An Ollama coding agent runs the model on your own computer. Ollama has a one-line launcher for Claude Code (ollama launch claude), Codex CLI (ollama launch codex) and OpenCode (ollama launch opencode), and each agent can also be pointed at http://localhost:11434 by hand. The two things that trip people up are about the model, not the agent: small models lose track of multi-step work, and Ollama’s default context is often too short.
Use Ollama with your agent
| Agent | Supported? | How | Note |
|---|---|---|---|
| Claude Code | Works, not supported by Anthropic | ollama launch claude, or ANTHROPIC_BASE_URL=http://localhost:11434 |
Ollama documents this. Anthropic doesn’t support routing Claude Code to non-Claude models, so expect rough edges |
| Codex CLI | Yes | ollama launch codex, or codex --oss |
Ollama recommends at least 64k context for Codex |
| OpenCode | Yes | ollama launch opencode, or a provider block in opencode.json |
OpenCode needs 64k context or more |
| Contenox | Yes | Backends → Providers → Ollama / Ollama Cloud | Pulled models appear in the Model chip |
Before you start
- Ollama installed and running. It usually runs in the background after install; otherwise start it with
ollama serve. - A model that supports tool calls, pulled with
ollama pull. Filter the library to models with tools. - Context of at least 64k tokens. See the context fix below; do it before the first session.
ollama pull qwen3
ollama ps
After the first request, ollama ps shows the loaded model. CONTEXT is the context length Ollama allocated, and PROCESSOR shows whether the model runs fully on the GPU. Those two columns explain most slow or confused agent sessions.
Claude Code
ollama launch claude
Or set it up yourself. In PowerShell on Windows:
$env:ANTHROPIC_AUTH_TOKEN = "ollama"
$env:ANTHROPIC_API_KEY = ""
$env:ANTHROPIC_BASE_URL = "http://localhost:11434"
claude --model qwen3
On macOS or Linux:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3
Claude Code is built and supported for Claude models. Anthropic says it doesn’t support routing it to other models through any gateway, so a feature that works with Claude may fail here.
Codex CLI
ollama launch codex
Or start Codex in local mode with a model:
codex --oss -m qwen3
--oss uses Ollama or LM Studio. To always pick Ollama, set oss_provider = "ollama" in ~/.codex/config.toml; otherwise Codex asks.
OpenCode
ollama launch opencode
Or add Ollama as a provider in opencode.json in your project, or in ~/.config/opencode/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": {
"qwen3": { "name": "Qwen3" }
}
}
}
}
Then pick the model with /models. ollama launch opencode doesn’t overwrite an existing opencode.json, and models you define only there don’t show up in Ollama’s launch picker.
Contenox
- Open Backends → Providers and, under Local, choose Ollama / Ollama Cloud.
- Leave Base URL at
http://127.0.0.1:11434, or enter the address of an Ollama server on another machine. - Select Connect and wait for Connected.
Your pulled models appear in the Model chip of a session, next to any cloud providers you connected. With a local server, model requests stay on your machine. Download Contenox.
Where this provider comes from: Contenox began as an Ollama client. The first version was about 70 lines of Go: read
OLLAMA_URL, fall back tohttp://localhost:11434, POST{"model": "llama3.2", "prompt": "Why is the sky blue?", "stream": false}to/api/generate, print the reply. Everything else grew from that one visible problem, and the provider above still talks to the same endpoint family. The story is in From a Simple Ollama Client to 26k LOC.
Which Ollama models work for a coding agent?
Pick a model tagged for tools — without it the agent can’t read files or run commands (Ollama’s library, filtered to tools). These picks were checked against Ollama’s library in November 2026:
| Your GPU / unified memory | Pick | Notes |
|---|---|---|
| 8 GB | qwen3.5:9b, short tasks only |
For real agent work at this size, use Ollama Cloud (below). |
| 12 GB | qwen3.5:9b |
Runs a full 64k context on the GPU. |
| 16 GB | qwen3.5:9b-q8_0 |
Or qwen3-coder:30b partly on the CPU. |
| 24 GB | qwen3.8:27b |
The sweet spot for local agent work. |
| 48 GB+ | qwen3.8:27b-q8_0, or qwen3-coder-next at 64 GB+ |
8-bit weights and a longer context. |
| Too big to fit | an Ollama Cloud model | glm-5.3:cloud, kimi-k2.7-code:cloud. |
On an Apple Silicon Mac, read “memory” as the unified memory left after the system and your apps. Best Ollama models for coding works out the pick, the context memory and the benchmarks for each size.
A few rules behind the table:
- Favor a mixture-of-experts model where one fits. A 30B-A3B model activates about 3B of its 30B parameters per token, so it runs near a 3B’s speed while needing memory for the full 30B.
- Keep the whole model on the GPU. If
ollama psshows a CPU share, the model plus its context didn’t fit and is running at system-RAM speed, ten to twenty times slower than VRAM. Use a smaller model or a shorter context. - Size the context for agent work, not chat. An agent resends its tools, files and command output every turn; aim for at least 64k tokens (see the context fix below).
- Try it on a real task first, such as explaining one module or fixing one failing test.
Too big to fit? Ollama now runs the largest open models on its own servers — see Ollama Cloud below. What the hardware does to token speed and context is in Run models locally.
Why does the agent ignore my request or forget the tools?
Usually the context is too short. An agent sends instructions, tool definitions, file contents and command output every turn. If that doesn’t fit, part of the prompt is cut, and that can be your request or the tool list.
Ollama’s default depends on your GPU memory. Its docs recommend at least 64000 tokens for agents and coding tools. Use the context slider in the Ollama app’s settings, or set OLLAMA_CONTEXT_LENGTH before Ollama starts.
On Windows, quit Ollama from the system tray, then in PowerShell:
setx OLLAMA_CONTEXT_LENGTH 64000
Start Ollama again from the Start menu. On macOS or Linux, for a single run:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
Check CONTEXT in ollama ps. A longer context needs more memory, so watch PROCESSOR too. In Contenox, the Token Limit chip sets how much history a session keeps; keep it no higher than your machine can hold.
Common errors
- Connection refused or Unreachable: Ollama isn’t running, or the address is wrong. Start it and check the address. In Contenox, then select Check again.
- No models found: Ollama is running but has no models. Run
ollama pullwith a model name. - The model answers in text instead of using tools: it doesn’t support tool calls, or its context is too short. Switch to a model tagged for tools and raise the context.
- Ollama runs on another machine and can’t be reached: Ollama listens only on
127.0.0.1by default. On that machine, setOLLAMA_HOSTto0.0.0.0:11434and restart Ollama; the Ollama FAQ has the steps per OS. Anyone on your network can then use it, so keep it on a trusted network.
Can I use Ollama Cloud instead?
Yes, if your computer can’t run the models you want. Ollama Cloud runs them on Ollama’s servers, so your code leaves your machine. Create a key at ollama.com/settings/keys.
- Claude Code: set
ANTHROPIC_BASE_URLtohttps://ollama.com, your key inANTHROPIC_AUTH_TOKEN,ANTHROPIC_API_KEYempty, and startclaude --modelwith a cloud model. - Codex CLI: use a cloud tag, for example
codex --oss -m gpt-oss:120b-cloud. - OpenCode:
/connect, choose Ollama Cloud and paste the key. OpenCode’s docs say to runollama pull gpt-oss:20b-cloudlocally first, then pick the model with/models. - Contenox: in the same Ollama / Ollama Cloud provider, set Base URL to
https://ollama.com/api, open Advanced and paste the key into API Key (optional), or enterOLLAMA_API_KEYas the Environment variable name, then Connect. Use Add another connection to keep your local server too.
Ollama Cloud has its own plans and usage limits; see Ollama’s pricing page.
Related
- Best Ollama models for coding: which models hold up in agent work
- Best Ollama harness: which agent to pair with Ollama
- How to run local LLMs for coding: hardware, model sizes and setup in more depth
- Run models locally: Ollama or vLLM, and what local models can’t do yet
- vLLM: serve models for a team
- How to choose a model for coding