---
title: "Use Ollama with OpenCode: Local Model Setup Guide"
description: "Connect OpenCode to Ollama for local coding-agent inference. Includes config examples, model picks, performance notes, and fixes for common local model problems."
updatedDate: 2026-10-28
date: 2026-04-27
location: San Francisco, CA – Apr 27th, 2026
image: /images/ollama-opencode-setup-hero.jpg
keywords: "ollama opencode, opencode ollama, opencode local model, opencode local llm, use ollama with opencode"
faq:
  - question: "Can OpenCode use Ollama?"
    answer: "Yes. OpenCode can use Ollama through its OpenAI-compatible local endpoint at http://localhost:11434/v1. Add Ollama as a provider, use a placeholder key if required, and copy the exact model name from ollama list."
  - question: "What local model should I use with OpenCode?"
    answer: "For a 24GB GPU or 32GB+ unified-memory workstation, compare Qwen3.8 27B, Muse Glimmer 30B, and Qwen3 Coder 30B. For smaller machines, test Gemma 4 E4B or Qwen3 8B. Leave memory for context and runtime overhead."
  - question: "Is OpenCode with Ollama good enough for real coding?"
    answer: "Test local inference on your own code explanations, edits, and tool sequences. Keep a cloud fallback for tasks the local model cannot finish correctly or quickly enough."
---
Model picks checked on **October 14, 2026** against the [Ollama library](https://ollama.com/search?c=coding). 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:

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

On Linux:

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

Then pull a model:

```bash
ollama pull gemma4:e4b
```

Check that it is available:

```bash
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:

```text
http://localhost:11434/v1
```

Add an Ollama provider in your OpenCode config:

```jsonc
{
  "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:

```json
{
  "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](https://ollama.com/library/qwen3.8) 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

```bash
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.

## Related setup

If the connection fails or the model describes edits without changing files, follow the [OpenCode and Ollama troubleshooting checks](/blog/opencode-ollama-troubleshooting/) before changing your model.

If your real target is Gemma 4 specifically, read [Gemma 4 Ollama setup](/blog/gemma-4-ollama-setup-guide/). If you are using OpenClaw instead of OpenCode, use [Gemma 4 with OpenClaw](/blog/gemma-4-ollama-openclaw-setup/).

<a href="https://app.haimaker.ai/sign-up?utm_source=openclaw_blog&utm_medium=cta&utm_campaign=ollama_opencode" class="cta-button">ADD A CLOUD FALLBACK WITH HAIMAKER</a>
