"I want Claude Code-style assistance, but the API costs add up." "I can't send our codebase to an external service." If either of those sounds familiar, the Gemma 4 × OpenCode combination is worth taking seriously.
Gemma 4 is Google's open model released in April 2026 — free for commercial use under the Apache 2.0 license. OpenCode is an open-source AI coding agent that runs in the terminal. Connect OpenCode to a local Ollama instance running Gemma 4 and you have a coding assistant that never leaves your machine, costs nothing to run, and works offline.
What You Should Know About Gemma 4
Gemma 4 is a family of open models developed by Google DeepMind, built on learnings from Gemini. Released April 2, 2026, four variants are available:
- E2B (edge, smallest)
- E4B (edge, mid-range)
- 26B MoE (Mixture-of-Experts)
- 31B Dense (highest accuracy)
For a personal machine, E4B is the practical choice. On Apple Silicon M3 or later, it runs comfortably. It handles code completion and small-to-medium implementation tasks at a usable level.
Compared to cloud models, accuracy is lower. But no internet dependency, no API fees, and no code leaving your machine are real advantages for privacy-sensitive projects or solo development where cost control matters.
What OpenCode Is
OpenCode is a terminal-based AI coding agent written in Go. It supports 75+ providers and can use local LLMs via Ollama. The workflow resembles Claude Code — autonomous file reading and writing, command execution, and multi-file edits. It's open source and free.
Setup Steps
Step 1: Install Ollama
# macOS
brew install ollama
# Linux
curl -fsSL https://ollama.com/install.sh | shStart the Ollama server:
ollama serveStep 2: Download Gemma 4
# E4B (recommended, ~5GB)
ollama pull gemma4:e4b
# 26B MoE (higher accuracy, ~18GB, 32GB RAM recommended)
ollama pull gemma4:26bFirst download takes several minutes to tens of minutes. Test it:
ollama run gemma4:e4b "Hello, can you write a simple Python hello world?"Step 3: Expand the Context Window
Ollama's default context window is 4,096 tokens — too short for an agent like OpenCode. Create a custom model file to expand it:
cat > Modelfile << 'EOF'
FROM gemma4:e4b
PARAMETER num_ctx 32768
EOF
ollama create gemma4-coder -f Modelfile
Step 4: Install OpenCode
npm install -g opencode-ai
# or via Homebrew (macOS)
brew install opencodeStep 5: Configure OpenCode
opencode config initEdit the generated config file (~/.config/opencode/config.json):
{
"provider": "ollama",
"model": "gemma4-coder",
"baseUrl": "http://localhost:11434"
}Step 6: Test It
cd your-project
opencodeTry: "Read the codebase and describe the main components." If it responds with an accurate description, the setup is working.
Honest Impressions After Using It
Setup takes under 10 minutes. Here's an honest take on the experience: compared to Claude Code running on Claude Sonnet, accuracy is noticeably lower. Complex refactors and changes across large codebases are difficult for it.
That said, it performed at a usable level for:
- Small-to-medium function implementations (50–200 lines)
- Debugging help based on error messages
- Scaffolding simple API endpoints
- Adding comments and generating documentation
For solo developers watching API costs, or teams that can't send internal code to external services, accepting the local environment's limitations is worth it.
Wrapping Up
Gemma 4 × OpenCode × Ollama gives you a zero-cost, fully local AI coding environment in about 10 minutes. There's a quality trade-off compared to cloud models — no pretending otherwise. But free, private, and offline in one package is genuinely difficult to find elsewhere.
Try it locally first and see for yourself which tasks fit comfortably within its capabilities.