Point Claude Code at a Local Model with Ollama: Subagents and Web Search Without Sending Your Code to the Cloud
By the end of this post Claude Code will be running against a model served by Ollama on your own machine, and you will know exactly which parts of a session leave the building. Cheapest place to start: a 16 GB laptop and a 9B model. Comfortable for real coding: 24 GB and a 26B model.
The source for this is Ollama’s post Subagents and web search in Claude Code (16 February 2026) and the Claude Code integration docs. Ollama’s post uses cloud-hosted models; everything below uses local ones, and we tested the setup on our own workstation on 2026-09-09.
What you need
- Ollama installed (
ollama --version). We used 0.30.10; the Anthropic-compatible endpoint answered atlocalhost:11434/v1/messages. - Claude Code installed:
curl -fsSL https://claude.ai/install.sh | bash(macOS/Linux) orirm https://claude.ai/install.ps1 | iex(Windows). We ran 2.1.266. - A model with the
toolscapability that fits your memory (table in Step 2). - No Anthropic account is required for the local path. No card, no key.
Step 1: Set three environment variables
These come straight from the integration docs:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model gemma4:26b
The shortcut ollama launch claude --model gemma4:26b writes the same configuration for you; ollama launch claude --restore puts it back. We prefer the variables because they live in one shell and leave your normal Claude Code login untouched.
Expected behaviour: Claude Code starts, and the first request appears in ollama ps. Two warnings are normal. Claude Code says the model is not in its catalog and assumes a 200k-token window; set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the context you actually gave Ollama. And it notes that claude.ai connectors are disabled while ANTHROPIC_API_KEY is set, which is exactly what you want here.
Step 2: Pick a model that fits, and give it enough context
The docs recommend a 64k-token context for larger codebases. Context costs memory: on our machine qwen3.6:35b took 23 GB at 32k context and 29 GB at its full 262k. Set the window explicitly instead of inheriting a default:
export OLLAMA_CONTEXT_LENGTH=65536 # or 32768 on a tight machine
ollama ps # CONTEXT column confirms it
Download sizes are from the Ollama library pages for qwen3.5, gemma4 and qwen3-coder. Resident memory is what we saw in ollama ps at 32k context.
| Machine | Model | Download | Resident at 32k | Verdict |
|---|---|---|---|---|
| 16 GB | qwen3.5:9b | 6.6 GB | not measured here | Fits with room for the editor |
| 16 GB | gemma4:12b | 7.6 GB | not measured here | Fits; keep context at 32k |
| 16 GB | qwen2.5-coder:7b | 4.7 GB | 6.6 GB | Fits, but see the test below |
| 24 GB | gemma4:26b | 19 GB | 17 GB | Fits at 32k; leaves about 6 GB |
| 24 GB | qwen3.5:27b | 17 GB | not measured here | Fits at 32k, tight at 64k |
| 24 GB | qwen3-coder:30b | 19 GB | not measured here | Fits at 32k only |
| 32 GB and up | qwen3.6:35b | 23 GB | 23 GB | Comfortable at 32k |
Step 3: Run the same smoke test we ran
Non-interactive mode makes the test repeatable. From an empty folder:
env ANTHROPIC_BASE_URL=http://localhost:11434 ANTHROPIC_AUTH_TOKEN=ollama ANTHROPIC_API_KEY= \
claude -p --model gemma4:26b "Reply with exactly the three words: local model ready"
Our results on the NVIDIA GB10 workstation (128 GB unified memory), 2026-09-09, wall-clock time including the model load:
| Model | Output | Wall time | Generation speed (/api/generate) |
|---|---|---|---|
qwen2.5-coder:7b | {"name": "local-model-ready", "arguments": {}} | 28 s | 34.1 tokens/s |
gemma4:26b | local model ready | 1 min 32 s | 51.2 tokens/s |
qwen3.6:35b | local model ready | 1 min 45 s | 51.4 tokens/s |
The 7B coder model is fast, but it answered Claude Code’s tool-heavy system prompt with a malformed tool call instead of text. That is the honest picture of the 16 GB tier: chat and single-file edits work, agentic sessions get confused. The 26B and 35B models behaved. The long wall times are almost entirely the first load from disk (116 s for gemma4:26b); the second run is seconds.
Step 4: Use subagents, and know what they cost
Subagents give side tasks their own context so the main session stays clean. Ollama’s post says models such as minimax-m2.5, glm-5 and kimi-k2.5 spawn them on their own; with a local model, ask explicitly: “Use subagents to check the tests and the docs in parallel while you refactor the parser.”
Each subagent is another request to the same Ollama server. On one GPU they share the same tokens per second, so three parallel subagents on a 26B model feel like one session at a third of the speed. Use them for isolation, not for speed, on local hardware.
What runs locally and what does not
This is the part to be precise about.
| Component | Where it runs | Notes |
|---|---|---|
| Your code, prompts, file edits, tool calls | Your machine | Sent only to localhost:11434 |
| The model | Your machine | Ollama, GPU or CPU |
| Subagents | Your machine | Extra requests to the same Ollama |
| Web search and web fetch | Ollama’s hosted service | POST https://ollama.com/api/web_search; needs a free account, ollama signin (docs) |
| Claude Code binary updates | Anthropic’s servers | Same as any install |
Web search is the one feature that leaves the building. Ollama’s post describes it as built into the Anthropic compatibility layer: when the model wants current information, Ollama runs the search and returns results into the local context. Only the query travels, not your repository. If your policy is strictly local, do not sign in, and the model simply has no search tool; or self-host a search engine such as SearXNG and expose it through an MCP server, which is what we do.
Where this fits, and the limits versus hosted models
Local Claude Code is right for code you cannot send anywhere, for offline work, and for the repetitive 80 percent: tests, docstrings, small refactors, explaining an unfamiliar file. Keep a metered hosted model for the hard 20 percent.
Honest limits. A 26B local model does not match a frontier model on multi-file architecture changes or long agent runs; expect more turns and more supervision. Generation at 51 tokens per second on a 26B model is slower than the hosted models, and a 24 GB machine runs one such model at a time. Vision and thinking work only if the model supports them (ollama show lists the capabilities). And Claude Code assumes a 200k window for unknown models, so tell it the truth with CLAUDE_CODE_MAX_CONTEXT_TOKENS.
Next steps
- Choose the machine for the tier you need: Edge AI hardware guide 2026.
- Compare the model families before you download 20 GB: Best local LLMs, Q2 2026 comparison.
- Work out when the box beats the subscription: Cloud vs local break-even.
Work with us
We run Claude Code against local models daily and keep a hosted key only for the hard cases. If you want that split designed for your team, with the models sized to the laptops you already own, get in touch or see how our consulting works.