- Book: Observability for LLM Applications
- Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go
- My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools
- Me: xgabriel.com | GitHub
Since Ollama v0.14.0, announced on January 16, 2026, a local Ollama server answers the same Anthropic Messages API that Claude Code talks to. Change a base URL and a few variables, and the whole agent loop (read a file, edit it, run the tests, read the failure) runs on a model sitting on your own disk. No Anthropic key, no per-token bill.
It also means a model that was never tuned for Claude Code's tool set is now driving it. Before you trust it with real work, find out three things: does it call tools properly, does Claude Code know how big its context really is, and is it fast enough to wait for. You can check all three in one sitting, inside a git worktree you throw away afterwards.
Step 1: pull a coding model and give it room
Pick a model with tool support. qwen3-coder is the one Ollama uses in its own Anthropic-compatibility examples. Its 30b tag is a 19GB download with a 256K context window and the tools badge on its library page.
ollama pull qwen3-coder:30b
The download is the easy part. The trap is the context window. Ollama doesn't run a model at its full window by default; it picks one from your VRAM, and the context-length docs put that at 4k below 24 GiB, 32k from 24 to 48 GiB, and 256k at 48 GiB or more. On a 48 GiB card the default already clears 64k, but the bottom two tiers leave little room for an agent that sends its system prompt, tool definitions and the conversation so far on every turn. The same docs say coding tools and agents "should be set to at least 64000 tokens."
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
If you run the Ollama desktop app, use the context-length slider in its settings instead. Then load the model once and run ollama ps. The CONTEXT column shows the window Ollama actually allocated, and PROCESSOR shows whether the model fits on the GPU or spills onto the CPU. Ollama's docs advise avoiding the CPU spill for speed, so if you see it, drop the context or pick a smaller tag.

The agent loop stays the same. Only the thing answering it moves onto your machine.
Step 2: point Claude Code at Ollama
The short route is Ollama's own launcher. Per the Claude Code integration page, ollama launch claude sets Claude Code up for Ollama and starts it, --model picks the model, and --yes skips the selectors (it needs --model).
ollama launch claude --model qwen3-coder:30b --yes
The integration page doesn't say whether the launcher corrects Claude Code's assumed context window, so launcher users should still run the check in Step 3. The long route is a handful of environment variables, and it shows you every setting the launcher doesn't. Put them in a small wrapper script so they never leak into your normal shell:
#!/bin/sh
# ~/bin/claude-local: Claude Code on a local Ollama model
M=qwen3-coder:30b
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_DEFAULT_OPUS_MODEL="$M"
export ANTHROPIC_DEFAULT_SONNET_MODEL="$M"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="$M"
export CLAUDE_CODE_SUBAGENT_MODEL="$M"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=64000
exec claude --model "$M" "$@"
Run chmod +x ~/bin/claude-local and make sure ~/bin is on your PATH. Line by line:
- The first three lines come straight from Ollama's manual setup.
ANTHROPIC_AUTH_TOKEN=ollamais "required but ignored", per the compatibility page.ANTHROPIC_API_KEYis set to empty on purpose: Claude Code's env var reference says a set key is used instead of your Pro or Max subscription, so you don't want a stray real key in this shell. - The tier variables map the
opus,sonnetandhaikualiases to the local model. Claude Code uses thehaikumodel for background functionality, and Ollama only serves the models you pulled. Leave a tier unmapped and anything that asks for it asks Ollama for a Claude model it doesn't have. -
CLAUDE_CODE_SUBAGENT_MODELis the default model for subagents and agent-team teammates that aren't assigned one another way (model config docs). -
CLAUDE_CODE_MAX_CONTEXT_TOKENSfixes a mismatch between the two tools. When Claude Code doesn't recognize a model ID, it assumes a 200K window and auto-compacts there. Ollama gave you 64000. Without this line Claude Code keeps filling a conversation about three times bigger than the window behind it. The docs say an unrecognized ID that doesn't start withclaude-takes the variable directly, andqwen3-coder:30bqualifies.
Know what you give up. Ollama's compatibility layer doesn't support token counting, prompt caching (cache_control), tool_choice, batches, citations or PDF document blocks, and accepts but doesn't enforce thinking's budget_tokens (compatibility page). Claude Code's own Remote Control is disabled when ANTHROPIC_BASE_URL points anywhere other than api.anthropic.com.
Step 3: run a small task in a throwaway worktree
A git worktree is a second working folder on its own branch, sharing the repo's history. Whatever the local model does there stays off your main checkout:
cd ~/code/app
git worktree add -b try/local-model ../app-local
cd ../app-local
claude-local
Give it a task with a clear right answer and a test to prove it. Something like: "Add a test for slugify in src/slug.js covering empty strings and accents, then run the test suite and fix anything that fails." That one task makes the model read a file, write a new one, run a shell command and react to the result, which is most of what Claude Code asks of a model.
First thing in the session, run /status. Ollama's integration page points out that Claude settings files can override shell variables, and /status is how you confirm the base URL and model are the ones you set. Then run /context, which shows what's filling the window. It should reflect the 64000 you set rather than the 200K Claude Code assumes for unknown models. The startup warning that the model isn't recognized and its context is assumed to be 200k should also be gone.
Keep the permission prompts on. Ollama's docs mention --dangerously-skip-permissions for unattended setups, and only in an isolated environment. A worktree doesn't count. It only separates files inside git, and the model's shell commands still run as you, with access to your home directory and the network.
Step 4: check tool calls, context and speed
Tool calls. In the session, watch what happens when the model needs a file. A model that handles tools well calls Claude Code's read and edit tools. A weaker one tends to describe the edit in prose, paste a whole file into chat, or call a tool with malformed arguments. You can test the raw capability outside Claude Code too, with one request against Ollama's Messages endpoint:
curl -s http://localhost:11434/v1/messages \
-H "content-type: application/json" \
-H "x-api-key: ollama" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "qwen3-coder:30b",
"max_tokens": 512,
"tools": [{
"name": "read_file",
"description": "Read a file from the repository",
"input_schema": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"]
}
}],
"messages": [{"role": "user",
"content": "What scripts does package.json define?"}]
}' | jq '.content[] | select(.type == "tool_use")'
If jq prints a tool_use block named read_file with "path": "package.json" in its input, the model and the endpoint agree on the format. If it prints nothing, the model answered in text instead, and Claude Code will have the same problem at a larger scale.
Context. Let the task run long enough to read a few files, then run /context again and compare it with ollama ps. If Claude Code's numbers climb toward 64k and it compacts, the window line did its job.
Speed. Ollama's generate API returns token counts and durations in nanoseconds, which is all you need for tokens per second:
curl -s http://localhost:11434/api/generate -d '{
"model": "qwen3-coder:30b",
"prompt": "Write a JavaScript slugify function.",
"stream": false
}' | jq '{
prefill_tok_s:
(.prompt_eval_count / (.prompt_eval_duration / 1e9)),
gen_tok_s: (.eval_count / (.eval_duration / 1e9))
}'
Watch both numbers. gen_tok_s is how fast it writes. prefill_tok_s is how fast it reads a prompt, and an agent sends long ones, as Step 1 showed. Your hardware decides both, so I won't quote numbers here. Measure them on your machine and decide whether you can wait for them.
When you're done, run the tests yourself and review what changed, from inside ../app-local:
git status --short
git diff --stat
git diff main...try/local-model --stat
The first two show what the model changed but didn't commit, which is the usual state after a one-task trial. The third shows anything it did commit; swap main for your default branch if it has another name. Then clean up:
cd ~/code/app
git worktree remove ../app-local
git branch -D try/local-model
git worktree remove refuses to delete a folder with modified or untracked files unless you pass --force. If it refuses, look at what's left before you force it. -D deletes the branch even though it was never merged, which is what you want for a throwaway.
Make it one more agent in Hermes
I build Hermes IDE, so weigh this part with that in mind. Hermes runs each coding agent in its own real terminal, and its ⌘N task launcher (Ctrl+Shift+N on Windows and Linux) starts every task on its own hermes/ branch in its own worktree. That's Step 3 done for you on every task. The agent picker lists the built-in agents plus Custom agent, and the site says Hermes runs "any command you add as a Custom agent."

The ⌘N agent picker: Claude Code (2.1.299) and Codex (0.145.0) installed, the other supported agents marked Not installed, and Custom agent.
So claude-local from Step 2 can be that command. Add it as a custom agent and it sits in the same picker as the subscription-backed Claude Code. The launcher also picks the account, model, effort and approval mode per task, and has a Save as preset… button, so a "local, try it first" combination can live next to your paid one. Before anything starts, the launcher shows the exact command Hermes will run.

The ⌘N New task sheet: the task, the agent, project, worktree, approval, model and effort chips, and the "Hermes will run" preview of the command.
That preview is where you catch the mistake that matters here: a task you meant for the local model launching plain claude on your subscription. Read it before you press Enter.
I haven't checked which of Hermes's Claude-specific extras follow Claude Code into a custom agent, so treat those as something to try rather than something promised. The branch and worktree come from the launcher, not the agent, and the Review Desk (⌘G) lists the task's staged, unstaged and untracked files with an inline diff, so you can read what the local model changed before you land it. Hermes is free, source-available under BSL 1.1, and runs on macOS, Windows and Linux; download it or read the code on GitHub.
If this was useful
Swap the model under an agent and the prompt and tools stay identical while the behavior changes, so you can't see the difference from outside. Step 4 is a small version of the habit that catches it: measure tool-call success, context use and latency. Observability for LLM Applications is the long version, covering tracing, evals, cost and quality regressions for LLM features once they're in front of real users.

Top comments (1)
The context-window mismatch is the part I wish I'd read first. I pointed a local model at a coding agent and couldn't figure out why it started dropping files mid-task — the client was still assuming a 200k window while the server had allocated something much smaller. Setting both sides to the same length, then checking with /context and ollama ps, would have saved me a lot of confusion. I'm also going to steal the curl tool-use check before spending a whole session finding out the model just narrates the edit instead of calling tools.