Gemma 4 Coding
A capable coding model you can run on your own machine. It writes, explains and fixes code, calls tools for agent workflows, and keeps your source private. Here is how good it is, which size to pick and how to set it up.
Scores from Google's model card · commands and sizes checked October 7, 2026
How good is Gemma 4 at coding?
The three larger models are strong at writing code. The big jump over the previous generation is the headline: Gemma 3 27B scored 29.1% on the same test where the 31B scores 80.0%.
LiveCodeBench v6
| Model | LiveCodeBench | Codeforces | Tau2 |
|---|---|---|---|
| 31B | 80.0% | 2150 | 76.9% |
| 26B A4B | 77.1% | 1718 | 68.2% |
| 12B | 72.0% | 1659 | 69.0% |
| E4B | 52.0% | 940 | 42.2% |
| E2B | 44.0% | 633 | 24.5% |
| Gemma 3 27B | 29.1% | 110 | 16.2% |
From Google's Gemma 4 model card. LiveCodeBench tests writing code for new problems; Codeforces Elo rates competitive-programming skill; Tau2 measures multi-step tasks with tools, averaged over three runs. Scores assume thinking is on. Every other test is on the benchmarks page; the older generation is on the Gemma 3 page.
Which size for coding
Pick the largest model your memory allows. For real coding work, the 12B is the sensible minimum.
| Your machine | Model | Ollama tag | Download | Good for |
|---|---|---|---|---|
| 24 GB GPU or 32 GB Mac | 31B | gemma4:31b-it-qat | 19 GB | The best results on hard problems |
| 24 GB GPU or 32 GB Mac | 26B A4B | gemma4:26b-a4b-it-qat | 16 GB | Faster replies - the everyday pick |
| 16 GB laptop | 12B | gemma4:12b-it-qat | 7.2 GB | Functions, tests, explanations, reviews |
| 8 GB laptop | E4B | gemma4:e4b-it-qat | 6.1 GB | Short snippets and simple scripts |
| No suitable hardware | 31B, hosted | - | None | Pay per token through an API |
Download sizes from Ollama's tags page, October 2026. Long files and long sessions need memory beyond the download - plan with the VRAM guide. Compare sizes on the models page, read the 12B guide and specs, and prefer the QAT builds. Hosted prices are on the pricing page.
Set up a private coding assistant
Run the model with Ollama or LM Studio. Both give you a chat window and a local API your editor can use.
# 16 GB machine ollama pull gemma4:12b-it-qat # 24 GB GPU or 32 GB Mac ollama pull gemma4:26b-a4b-it-qat # Try it ollama run gemma4:12b-it-qat "Write a Python function that merges two sorted lists"
Get Ollama from ollama.com/download. Once a model is pulled, Ollama serves it at localhost:11434 for every app on your machine.
lms get google/gemma-4-12b # download lms load google/gemma-4-12b # load into memory lms server start # local API on port 1234
Or do it all in the app: download from lmstudio.ai, search for "Gemma", load a model and start the server from the Developer tab. No terminal needed.
Try it in Google AI Studio
Sign in at aistudio.google.com, choose Gemma 4 31B and paste your code. Free to try.
Or call it through an API
Google's API serves
gemma-4-31b-itandgemma-4-26b-a4b-it; other providers host them too. See the API page.Mind what you paste
Hosted options send your code to a provider. Use a local model for anything confidential.
Step-by-step help: install guide · how to download · download hub · Mac setup · runtime selector.
Connect your editor
Most AI coding extensions let you add a custom "OpenAI-compatible" model. Give them one of these addresses and the model name.
| Running with | Base URL | Model name | API key |
|---|---|---|---|
| Ollama | http://localhost:11434/v1 | gemma4:12b-it-qat | Any text, for example ollama |
| LM Studio | http://localhost:1234/v1 | google/gemma-4-12b | Any text |
Editor extensions
Look for "custom endpoint", "OpenAI-compatible" or "local model" in your extension's settings. The exact menu differs between tools.
Terminal agents
Claude Code can be pointed at a local Gemma 4 through Ollama. See Gemma 4 vs Claude Code for the setup and trade-offs.
A shared team server
Serve one model for everyone from a workstation or server. Start with self-hosting.
What to use it for
Eight jobs it handles well, each with a prompt you can adapt.
Write a function
Describe the inputs, outputs and edge cases.
Explain code
Paste something unfamiliar and ask what it does.
Write tests
Give it the function and your test framework.
Find a bug
Include the error message and what you expected.
Refactor
Ask for a specific improvement, not "make it better".
Review a change
Paste a diff and ask for problems first.
SQL and regex
Describe the data and the result you want.
Docs and commits
Turn code or a diff into plain words.
Prompts and settings that help
Turn thinking on for hard problems
Debugging, algorithms and multi-step changes benefit most. Turn it off for quick completions, where speed matters more.
Keep Google's sampling values
Temperature 1.0, top-p 0.95 and top-k 64 are the model card's settings for every size.
Raise the context length
The 12B and larger take 256K tokens, but local apps often start much lower. Increase it before pasting large files.
Give it the real code
Paste the function, the error and the versions you use. It cannot see your project unless a tool shows it.
State the constraints
Language version, libraries allowed, style rules and what must not change.
Ask for one change at a time
Small, checkable steps beat one giant request, especially on the 12B.
Its training data ends in January 2025, so it may not know newer library versions - paste the relevant docs when it matters. More in the prompting guide and on the capabilities page.
Agents and tool calling
Gemma 4 has built-in function calling, so it can ask your program to read a file, run tests or search docs, then act on the result. That is what turns a chat model into a coding agent.
tools = [{
"type": "function",
"function": {
"name": "run_tests",
"description": "Run the project's test suite and return the output",
"parameters": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"],
},
},
}]
reply = client.chat.completions.create(
model="gemma4:26b-a4b-it-qat", messages=messages, tools=tools,
)
call = reply.choices[0].message.tool_calls[0]
# Check the name and arguments before you run anything
if call.function.name == "run_tests":
...
The model never runs code
It only writes a request to call a tool. Your program decides whether to run it. Google's guide says to validate the function name and arguments first.
Use a larger size
Agent scores fall from 76.9% on the 31B to 42.2% on E4B. Use the 12B or above, and keep chains short.
Keep a human in the loop
Approve file writes and shell commands, work in a branch, and never give an agent credentials it does not need.
From Google's function-calling guide; the example uses the OpenAI-style format that Ollama and LM Studio accept. Re-pull models downloaded before the July 2026 refresh, which fixed tool calling. Responsible-use notes are under safety.
Script it: a local code reviewer
A dozen lines that review your staged changes before you commit, without sending code anywhere.
# pip install openai · ollama pull gemma4:12b-it-qat
import subprocess
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
diff = subprocess.run(["git", "diff", "--staged"],
capture_output=True, text=True).stdout
reply = client.chat.completions.create(
model="gemma4:12b-it-qat",
messages=[
{"role": "system", "content": "You are a careful code reviewer. "
"List bugs and risky changes first. Be specific and brief."},
{"role": "user", "content": "Review this diff:\n\n" + diff},
],
)
print(reply.choices[0].message.content)
Swap the base URL for http://localhost:1234/v1 to use LM Studio. More API detail is on the API page. To search a whole codebase by meaning, pair this with
EmbeddingGemma 2.
Where it falls short
Long autonomous tasks
Multi-step agent work is its weakest measured area, most of all on the small models.
Recent libraries
Knowledge stops at January 2025. It can suggest outdated APIs with confidence.
Whole-repository changes
It sees only what fits in context and what a tool feeds it.
It can be wrong
Run the code, read the diff and keep your tests. Treat output as a draft from a fast colleague.
The larger hosted models from several companies are still stronger on big, long-running coding jobs. A common pattern is Gemma 4 locally for everyday edits and private code, and a hosted model for the hardest work. More in limitations, the model comparison and Gemma 4 vs Qwen 3.5.
Is Gemma 4 good for coding?
The larger sizes are. The 31B solves 80.0% of LiveCodeBench v6 problems and the 12B 72.0%, according to Google's model card. The two edge models score much lower.
Which Gemma 4 model is best for coding?
The 31B for quality, the 26B A4B for speed, and the 12B if you have a 16 GB laptop.
Can I use it for free?
Yes. The models are open under Apache 2.0, so running one on your own machine costs nothing beyond the hardware. Commercial use is allowed.
Does my code stay private?
When the model runs on your machine, your code is not sent to a model provider. Hosted options do send it to a provider.
Which programming languages does it know?
Google does not publish a per-language list. Expect the best results in widely used languages such as Python, JavaScript and TypeScript, and test it on your own stack.
Can it read screenshots of code or errors?
Yes. Every size reads images, so you can paste a screenshot of an error or a UI. For text-heavy images use a higher image-detail setting - see features.
Can I code with it on a phone?
The E2B and E4B models run on phones and can write short snippets, but they are not strong coders. See the Android page and mobile downloads.
Where can I try it before installing?
In Google AI Studio, or see the playground and chat pages for other options.
Put a coding model on your own machine
Download a model, connect your editor and keep your source code private.