Gemma 4 / Coding

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

users.py Gemma 4 · local 1# sort users by signup date, newest first 2def sort_users(users): 3return sorted( 4users, 5key=lambda u: u.signup_date, 6reverse=True, 7) $ pytest -q 3 passed in 0.04s
A comment in, working code out - generated on your own machine.
Benchmarks

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

Fresh coding problems, percent solved
Gemma 4 31B80.0%
Gemma 4 26B A4B77.1%
Gemma 4 12B72.0%
Gemma 4 E4B52.0%
Gemma 4 E2B44.0%
Gemma 3 27B29.1%
ModelLiveCodeBenchCodeforcesTau2
31B80.0%215076.9%
26B A4B77.1%171868.2%
12B72.0%165969.0%
E4B52.0%94042.2%
E2B44.0%63324.5%
Gemma 3 27B29.1%11016.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.

Choose

Which size for coding

Pick the largest model your memory allows. For real coding work, the 12B is the sensible minimum.

Your machineModelOllama tagDownloadGood for
24 GB GPU or 32 GB Mac31Bgemma4:31b-it-qat19 GBThe best results on hard problems
24 GB GPU or 32 GB Mac26B A4Bgemma4:26b-a4b-it-qat16 GBFaster replies - the everyday pick
16 GB laptop12Bgemma4:12b-it-qat7.2 GBFunctions, tests, explanations, reviews
8 GB laptopE4Bgemma4:e4b-it-qat6.1 GBShort snippets and simple scripts
No suitable hardware31B, hosted-NonePay 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.

Setup

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.

  1. Try it in Google AI Studio

    Sign in at aistudio.google.com, choose Gemma 4 31B and paste your code. Free to try.

  2. Or call it through an API

    Google's API serves gemma-4-31b-it and gemma-4-26b-a4b-it; other providers host them too. See the API page.

  3. 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.

Editor

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 withBase URLModel nameAPI key
Ollamahttp://localhost:11434/v1gemma4:12b-it-qatAny text, for example ollama
LM Studiohttp://localhost:1234/v1google/gemma-4-12bAny 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.

Everyday use

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.

"Write a TypeScript function that groups orders by customer ID. Handle an empty list."
📖

Explain code

Paste something unfamiliar and ask what it does.

"Explain this function step by step, then list anything that looks risky."
🧪

Write tests

Give it the function and your test framework.

"Write pytest tests for this function, including edge cases and bad input."
🐞

Find a bug

Include the error message and what you expected.

"This raises KeyError on some inputs. Find the cause and show the fix."
♻️

Refactor

Ask for a specific improvement, not "make it better".

"Refactor this into smaller functions without changing behaviour."
🔍

Review a change

Paste a diff and ask for problems first.

"Review this diff. List bugs and security issues before style points."
🗄️

SQL and regex

Describe the data and the result you want.

"Write a PostgreSQL query for the top 10 customers by revenue in 2026."
📝

Docs and commits

Turn code or a diff into plain words.

"Write a docstring for this function and a one-line commit message."
Technique

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

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.

1 · WriteGemma drafts the change 2 · Runyour tests or linter 3 · Readthe error comes back 4 · FixGemma corrects it Repeat until the tests pass - with you approving each step
The loop behind every 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.

Automate

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.

Honest limits

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.

FAQ

Coding questions

More answers on the full FAQ page.

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.

Top '