Model picks checked on October 14, 2026 against the Ollama library. Use local model tags when the work must stay on your machine.

OpenCode with Ollama is the setup people want when they are tired of sending every coding prompt to a cloud API. It works. It is also slower and more fragile than the demos make it look.

The right expectation is simple: local OpenCode is excellent for small, private, repetitive work. It is not the model you should trust with a messy multi-file migration unless you enjoy babysitting.

Install Ollama

On macOS:

brew install --cask ollama-app
open -a Ollama

On Linux:

curl -fsSL https://ollama.com/install.sh | sh

Then pull a model:

ollama pull gemma4:e4b

Check that it is available:

ollama list

Use the exact model name from that output in your OpenCode config.

Configure OpenCode

OpenCode can talk to OpenAI-compatible providers. Ollama exposes a compatible endpoint at:

http://localhost:11434/v1

Add an Ollama provider in your OpenCode config:

{
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "gemma4:e4b": {}
      }
    }
  }
}

If OpenCode asks for auth, use a placeholder key:

{
  "ollama": {
    "type": "api",
    "key": "ollama"
  }
}

Restart OpenCode and switch to the Ollama model from the model picker.

Models to try first

Gemma 4 E4B or Qwen3 8B

Start with a smaller build on a laptop. Use gemma4:e4b or qwen3:8b, keep context short, and check actual memory use during a tool loop. The generic gemma4 tag can resolve to a larger build than you intended.

Qwen3.8 27B

A newer coding and tools candidate for a workstation. Ollama’s listing shows an approximately 18GB download before context and runtime overhead. Compare it with qwen3-coder:30b rather than assuming release order determines quality.

Muse Glimmer 30B

Another local agent candidate with tools support. Its approximately 18GB download also needs working-memory headroom. Pull muse-glimmer:30b, then use that exact name in the OpenCode provider block. Test recovery from a failed tool call before leaving a session unattended.

Performance expectations

Recent local-model threads all say the quiet part out loud: prompts can work, code can be good, and the whole thing can still feel slow once tool calls start stacking up.

That is normal. A coding agent is not a single chat request. It reads files, plans, edits, checks output, and loops. Local inference makes every loop more visible.

To make it tolerable:

  • Keep context small
  • Use smaller models for simple edits
  • Keep the model warm
  • Close memory-heavy apps
  • Use a cloud fallback for long refactors

Keep Ollama warm

export OLLAMA_KEEP_ALIVE="-1"

Restart Ollama after setting it. This avoids repeated cold starts during a coding session.

When to use a cloud fallback

Use local OpenCode for:

  • Reading unfamiliar code
  • Drafting small changes
  • Generating tests
  • Explaining errors
  • Working with private files

Use a cloud model for:

  • Multi-file refactors
  • Hard debugging
  • Architecture changes
  • Anything you do not want to review line by line

The best setup is not local-only. It is local-first.

If the connection fails or the model describes edits without changing files, follow the OpenCode and Ollama troubleshooting checks before changing your model.

If your real target is Gemma 4 specifically, read Gemma 4 Ollama setup. If you are using OpenClaw instead of OpenCode, use Gemma 4 with OpenClaw.

ADD A CLOUD FALLBACK WITH HAIMAKER