View all articles
Claude CodeOllamaLocal AIDeveloper Tools

Point Claude Code at a Local Model with Ollama: Subagents and Web Search Without Sending Your Code to the Cloud

JG
Jacobo Gonzalez Jaspe
|

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 at localhost:11434/v1/messages.
  • Claude Code installed: curl -fsSL https://claude.ai/install.sh | bash (macOS/Linux) or irm https://claude.ai/install.ps1 | iex (Windows). We ran 2.1.266.
  • A model with the tools capability 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.

MachineModelDownloadResident at 32kVerdict
16 GBqwen3.5:9b6.6 GBnot measured hereFits with room for the editor
16 GBgemma4:12b7.6 GBnot measured hereFits; keep context at 32k
16 GBqwen2.5-coder:7b4.7 GB6.6 GBFits, but see the test below
24 GBgemma4:26b19 GB17 GBFits at 32k; leaves about 6 GB
24 GBqwen3.5:27b17 GBnot measured hereFits at 32k, tight at 64k
24 GBqwen3-coder:30b19 GBnot measured hereFits at 32k only
32 GB and upqwen3.6:35b23 GB23 GBComfortable 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:

ModelOutputWall timeGeneration speed (/api/generate)
qwen2.5-coder:7b{"name": "local-model-ready", "arguments": {}}28 s34.1 tokens/s
gemma4:26blocal model ready1 min 32 s51.2 tokens/s
qwen3.6:35blocal model ready1 min 45 s51.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.

ComponentWhere it runsNotes
Your code, prompts, file edits, tool callsYour machineSent only to localhost:11434
The modelYour machineOllama, GPU or CPU
SubagentsYour machineExtra requests to the same Ollama
Web search and web fetchOllama’s hosted servicePOST https://ollama.com/api/web_search; needs a free account, ollama signin (docs)
Claude Code binary updatesAnthropic’s serversSame 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

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.

Share: LinkedIn X
Newsletter

Access exclusive resources

Subscribe to unlock 230+ workflows, 43 agents, and 26 professional templates. Weekly insights, no spam.

Bonus: Free EU AI Act checklist when you subscribe
Once a week No spam Unsubscribe anytime
EU AI Act is now in effect — Is your organization compliant?

Tell us what you want to run

Tell us what you want to run and on what budget. We will tell you which hardware you need, which model fits, and what to expect from it — before you spend anything.

Self-service Local-first Open-source toolkits

136 pages of free resources · 26 compliance templates · 22 certified devices