Get updates
Setup

Best agent harness for local LLMs and Ollama

Four open-source harnesses document a local-model path today: OpenCode, Codex CLI, Aider and goose. Which one fits depends on the job, and the setting most likely to break any of them is the model's context length, not the harness.

Checked against official docs on Oct 18, 202614 sourcesNo affiliate links

The short answer

OpenCode

Full coding agent, least glue

OpenCode's docs ship an Ollama provider block, and Ollama documents a one-command launcher, ollama launch opencode. MIT licensed.

Codex CLI

You already use Codex

Codex has reserved built-in ollama and lmstudio providers and an --oss flag. Apache-2.0.

Aider

Small, git-safe edits

Point it at ollama_chat/<model>. Every edit becomes a commit you can /undo. Apache-2.0.

goose

Desktop app or repeatable non-coding tasks

Ollama is a built-in provider and installed models appear in the picker automatically. Apache-2.0.

First fix the context window

Most "the local agent ignores my tools" reports come down to context length. Ollama picks a default from your GPU memory: 4k tokens under 24 GiB of VRAM, 32k from 24 to 48 GiB, 256k at 48 GiB or more. It recommends at least 64,000 tokens for agents and coding tools, and its OpenCode and Codex pages both ask for 64k or more. OpenCode's own tip says that if tool calls aren't working, raise num_ctx, starting around 16k to 32k. Source.

Serve with a larger context, then check it
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
# in another terminal: the CONTEXT column shows what was allocated
ollama ps

A larger context needs more memory. If ollama ps shows the model partly on CPU, it will be slow; Ollama advises avoiding CPU offload for best performance.

How each harness connects

HarnessHow it talks to OllamaWhere the setting livesOllama shortcutLicense
OpenCodeOpenAI-compatible provider at http://localhost:11434/v1opencode.jsonollama launch opencodeMIT
Codex CLIBuilt-in ollama / lmstudio provider, picked with --oss~/.codex/config.toml (oss_provider)ollama launch codexApache-2.0
AiderOLLAMA_API_BASE + --model ollama_chat/<model>env var or .aider.conf.ymlnone documentedApache-2.0
gooseBuilt-in Ollama provider (OLLAMA_HOST)goose configure or the desktop appOllama documents a goose pageApache-2.0
Claude CodeOllama's Anthropic-compatible API (unsupported by Anthropic)env / launcherollama launch claudeNo license file (GitHub)

Licenses from the GitHub API on Oct 18, 2026. "No license file" means GitHub detects none in anthropics/claude-code.

Rig 1: OpenCode + Ollama

This is OpenCode 1's documented Ollama block, plus a permission rule so edits and shell commands ask first. Replace <model> with a model you've pulled.

opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": { "baseURL": "http://localhost:11434/v1" },
      "models": { "<model>": { "name": "<model> (local)" } }
    }
  },
  "permission": { "edit": "ask", "bash": "ask" }
}

Rig 2: Codex CLI + Ollama or LM Studio

~/.codex/config.toml
# default local provider used when you run with --oss
oss_provider = "ollama"   # or "lmstudio"
Run it
codex --oss
# or let Ollama set up a dedicated Codex profile for the session
ollama launch codex

If oss_provider is unset, Codex prompts you to choose. The IDs openai, ollama and lmstudio are reserved, so don't define a custom provider with those names. Config reference.

Rig 3: Aider + Ollama

Aider with a local model
python -m pip install aider-install && aider-install
export OLLAMA_API_BASE=http://127.0.0.1:11434
ollama pull <model>
OLLAMA_CONTEXT_LENGTH=8192 ollama serve   # Aider's doc example; raise it for bigger repos
aider --model ollama_chat/<model>

Aider recommends the ollama_chat/ prefix over ollama/. Its doc example uses an 8k window; Ollama's own guidance for coding tools is 64k, so start higher if your hardware allows. Aider's repo was last pushed on May 22, 2026, per the GitHub API, which is slower than the other three.

Rig 4: goose + Ollama

goose CLI
goose configure        # Configure Providers -> Ollama
export OLLAMA_HOST=http://localhost:11434
goose session

In goose Desktop, locally installed Ollama models show up in the model dropdown automatically. goose also reads AGENTS.md by default, so the same instructions file works here and in OpenCode and Codex.

Keeping private files local

A local model only keeps data local if nothing else in the rig phones out. Check three things before pointing a harness at private documents:

  • Every model slot is local. Harnesses can use more than one model for different tasks; set all of them to your local provider.
  • Web tools are off or ask first. In OpenCode, "webfetch": "deny" under permission blocks fetches.
  • MCP servers are local. A remote MCP server sends your requests to its host.

See the private-docs recipe for a full read-only rig.

FAQ

What is the best agent harness for Ollama?

For a full coding agent, OpenCode: it has a documented Ollama provider and Ollama ships ollama launch opencode. If you already use Codex, its built-in Ollama provider and --oss flag are the shortest path. For small git-tracked edits, Aider.

How much context does a local coding agent need?

Ollama recommends at least 64,000 tokens for agents and coding tools. Its default is only 4k on GPUs with under 24 GiB of VRAM, which is too small for most agent loops.

Can Claude Code use a local model?

Ollama documents it via its Anthropic-compatible API, but Anthropic's docs say it doesn't support routing Claude Code to non-Claude models. It may work; it isn't supported by the vendor.

Which local model should I pick?

We don't rank local models. No benchmark we trust compares them inside these harnesses yet, so we won't invent a pick. Choose a tool-capable model that fits in GPU memory with a 64k window.

Sources

  1. Ollama docs: context length · checked Oct 18, 2026
  2. Ollama docs: OpenCode · checked Oct 18, 2026
  3. Ollama docs: Codex CLI · checked Oct 18, 2026
  4. Ollama docs: Claude Code · checked Oct 18, 2026
  5. Ollama docs: goose · checked Oct 18, 2026
  6. OpenCode 1 docs: providers · checked Oct 18, 2026
  7. OpenCode 1 docs: permissions · checked Oct 18, 2026
  8. OpenCode 2 docs: migrate from V1 · checked Oct 18, 2026
  9. Codex docs: config reference · checked Oct 18, 2026
  10. Aider docs: Ollama · checked Oct 18, 2026
  11. goose docs: providers · checked Oct 18, 2026
  12. goose docs: .goosehints and AGENTS.md · checked Oct 18, 2026
  13. Claude Code docs: LLM gateway · checked Oct 18, 2026
  14. GitHub repo metadata (license, last push), via the GitHub API · checked Oct 18, 2026

Spotted something out of date? Email sternberg@mail.grokbot.com.

Related