GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
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-05-06
Production-Grade Gemma 4 + Ollama + Android Studio — Task Routing, Fine-Tuning, Team Deployment, and CI Integration
A deep-dive into running Gemma 4 locally for Android development at production scale. Covers model-routing proxies, LoRA fine-tuning for project-specific patterns, Docker Compose team setup, and GitHub Actions AI code review integration.
Gemini Basics2026-05-05
Gemma 4 × OpenCode: Build a Free Local AI Coding Environment in 10 Minutes
Combine Google's open Gemma 4 model with the OpenCode terminal agent and you get a fully local, zero-cost AI coding environment ready in 10 minutes. Here's the setup and an honest take on the experience.
Dev Tools2026-06-24
Folding a Local Gemma 4 into Daily Work — Practical Notes on the Ollama API and Response Speed
Taking a local Gemma 4 you can now run interactively and folding it into real work: how to hit Ollama's local API from a script, tricks to improve perceived response speed, and a two-tier fallback that automatically routes to the cloud Gemini API — code included.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →