◉GEMINI LABJP
●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 6 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…
Articles/Advanced
⬡ Advanced/2026-05-05Intermediate

Gemma 4 × OpenCode Advanced Guide: Building a Production-Ready Local AI Dev Environment

Move beyond 'it works' with Gemma 4 and OpenCode. A deep guide to model selection, context management, prompt design, and hybrid cloud-local workflows for real-world development.

Gemma 412OpenCode3Ollama8local LLM6AI development6prompt engineering5hybrid workflow

Getting Gemma 4 × OpenCode "working" is the easy part. Getting it to a point where it's actually useful in a real development workflow takes more deliberate setup.

Context window limits, prompt design for smaller models, and the judgment of which tasks belong on local versus cloud LLMs — these aren't things you figure out automatically. Without working through them, it's easy to conclude "local LLMs aren't worth it" before you've given them a fair test.

Choosing the Right Gemma 4 Variant

Four model sizes exist. Picking the right one matters.

E2B (up to ~4GB RAM)

The smallest variant. Designed for mobile and IoT integration. Not practical for coding tasks — limited instruction-following and code quality.

E4B (up to ~8GB RAM)

The mid-range edge model. Runs comfortably on Apple Silicon M1+ Macs and Windows machines with 16GB RAM.

Small-to-medium function implementations, code review comments, and documentation generation all fall within usable accuracy. Works well as a "sub-engine" for development tasks where API cost is the constraint.

26B MoE (up to ~20GB unified/VRAM)

Uses Mixture-of-Experts architecture — surprisingly high accuracy relative to its parameter count. Requires Apple Silicon M2 Ultra or higher, or a GPU with 24GB+ VRAM.

Multi-file refactoring and architecture review tasks become more viable here.

31B Dense (~35GB RAM)

Highest accuracy. Not realistic for personal machines. Intended for server deployment.

Recommended path for individuals: Start with E4B, validate the speed-quality balance for your use case, then step up to 26B MoE if needed.

Practical Context Window Management

The most common failure point with local LLM coding agents is running out of context. Ollama's default 4,096-token window fills up quickly with real codebases.

# For E4B (16GB RAM)
cat > Modelfile-e4b << 'EOF'
FROM gemma4:e4b
PARAMETER num_ctx 32768
PARAMETER num_gpu 99
EOF
ollama create gemma4-e4b-coder -f Modelfile-e4b
 
# For 26B MoE (32GB+ RAM)
cat > Modelfile-26b << 'EOF'
FROM gemma4:26b
PARAMETER num_ctx 65536
PARAMETER num_gpu 99
EOF
ollama create gemma4-26b-coder -f Modelfile-26b

num_gpu 99 pushes as many layers as possible to GPU memory. On Apple Silicon, this means nearly all layers stay on the neural engine.

Directory Strategy to Conserve Context

For large projects, starting OpenCode from a specific subdirectory — rather than the project root — keeps context focused and effective.

# Start in the module you're actually working on
cd src/modules/payment
opencode
 
# Or specify what to exclude from context
cat > .opencodeignore << 'EOF'
node_modules/
.next/
dist/
*.test.ts
*.spec.ts
*.log
EOF

Excluding test files and build artifacts alone frees up substantial context for actual source code.

Prompt Design for Local LLMs

Prompts that work well with Claude or Gemini 1.5 Pro often don't translate cleanly to local models. Smaller models respond better to different patterns.

Principle 1: Make tasks as atomic as possible

❌ "Refactor this entire module to improve type safety and add comprehensive tests."

✅ "Change the return type of the fetchUser function from User | null 
   to Result<User, ApiError>. Modify only this file."

Local models lose coherence on large, multi-goal tasks. One clear task per prompt produces substantially more reliable output.

Principle 2: Specify the output format explicitly

Add JSDoc comments to the following function.
Output format: only the complete code with JSDoc added. No explanatory text.

[code]

"No explanatory text" suppresses the tendency smaller models have to pad responses with verbose introductions.

Principle 3: Reference specific files

Refer to @src/types/user.ts and @src/api/fetchUser.ts.
Fix the type error in the fetchUser return value.

"Look at the whole codebase" produces worse results than explicit file references. The model processes what you point at, rather than trying to figure out what's relevant.

Hybrid Cloud-Local Workflow

In practice, the most balanced approach is distributing tasks between local and cloud models based on complexity and sensitivity.

Give to Local (Gemma 4)

  • Comment and documentation generation
  • Small function implementations (under 50 lines)
  • Variable and function rename suggestions
  • Simple bug fixes where the error message is clear
  • Boilerplate and scaffolding generation

Give to Cloud (Claude / Gemini)

  • Implementations requiring design judgment
  • Multi-file refactoring
  • Security-sensitive code review
  • Complex algorithm implementation
  • Any code that can safely leave your machine

Writing this decision framework into a CODING_POLICY.md at your project root keeps the logic consistent — and communicable if you work with others.

Managing Multiple Profiles in OpenCode

// ~/.config/opencode/config.json
{
  "profiles": {
    "local-fast": {
      "provider": "ollama",
      "model": "gemma4-e4b-coder",
      "baseUrl": "http://localhost:11434"
    },
    "local-quality": {
      "provider": "ollama",
      "model": "gemma4-26b-coder",
      "baseUrl": "http://localhost:11434"
    },
    "cloud": {
      "provider": "anthropic",
      "model": "claude-sonnet-4-6"
    }
  },
  "defaultProfile": "local-fast"
}

Switch profiles with:

opencode --profile cloud

The Right Mental Model for Local LLMs

The key to using Gemma 4 × OpenCode productively is not treating it as a drop-in Claude Code replacement. It's a zero-cost sub-engine that handles specific, well-defined tasks — while your cloud model handles the rest.

With model selection, context configuration, and prompt design aligned, the local environment performs well above the "toy project" level. Start with E4B, find where it fits in your workflow, and expand from there.

Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

⬡ Advanced2026-10-14
Fine on Desktop, Blank on Safari: Four Things to Gather Before You Ask an AI to Diagnose It
After a shuffle, my lazy-loaded images never loaded again, but only in Safari on iPhone. Here is what to collect by hand before asking Gemini or any other model to diagnose a bug that does not reproduce on desktop, plus a request template you can paste.
⬡ Advanced2026-10-10
Keeping Money and Health Questions Out of Your History: Gemini Temporary Chat and the Settings to Check
Before you ask Gemini about household spending or a health worry, here is the order I use to check Temporary Chat and the Activity setting, so you can decide what gets kept and what doesn't.
⬡ Advanced2026-09-24
I Stopped Asking Gemini 'Is This Right?' and Started Hiding My Answer Instead
Ask Gemini to confirm a label you already chose and it tends to agree. Here is why I compared three ways of asking, chose blind re-classification, how my answer still leaked in, and the routing code that sends only disagreements to a human.