Yes, Claude Code can run against a local model through Ollama, and Ollama documents it on a page of its own. We have not run this setup ourselves. What follows is what Anthropic's and Ollama's pages say as of 10 November 2026, plus the things you have to check by hand. Whether the model you pick can handle your repository only your own run will tell you, and step 6 gives you the order of that run.
People ask for this for three reasons: the code cannot leave the machine, the network is unreliable or absent, or they want to try an agent without paying per token. Those are good reasons. They are also reasons to read the limits first.
What the docs say
| Question | What is written |
|---|---|
| Address and token | Local Ollama server: http://localhost:11434, ANTHROPIC_AUTH_TOKEN=ollama. The server does not validate the key |
| What is supported | Messages, streaming, system prompts, multi-turn conversations, tool calling and tool results, thinking, base64 images |
| What is not | tool_choice, metadata, token counting at /v1/messages/count_tokens, prompt caching with cache_control, the Batches API, citations, PDF blocks, images by URL |
| Context | Local models need a "64k+" window |
| Ollama's caveats | Hosted WebSearch and advanced tool controls are not fully supported, and the model must support tools |
| Anthropic's position | Anthropic does not support pointing Claude Code at non-Claude models through gateways |
The rows come from Ollama's Anthropic compatibility page, Ollama's Claude Code page and Claude Code's gateway documentation.
The last row changes what the whole exercise means. Ollama is not named in Anthropic's text, but any setup where something other than Claude answers behind ANTHROPIC_BASE_URL falls under it in spirit. That is our reading, not a quote. In practice, if a Claude Code update breaks something on your local model, do not wait for a fix from Anthropic. Anthropic's gateway documentation adds that Claude Code gains features with every release, and a gateway that does not forward them breaks the matching features.
Launch, step by step
Step 1. Install Claude Code
The install command from Anthropic's documentation for macOS, Linux and WSL:
curl -fsSL https://claude.ai/install.sh | bash
On Windows use irm https://claude.ai/install.ps1 | iex, and see how to install Claude Code on Windows if you hit trouble. Check with claude --version. The broader setup is in Claude Code in 2026: setup with Claudexia and pay-as-you-go.
Step 2. Install Ollama and pull a model
Get the installer from ollama.com, then pull the model Ollama's docs use in their example:
ollama pull qwen3.5
Without a tag you get latest, which matches 9b on the model's library page. The family carries the vision, tools and thinking labels, and the download sizes are:
| Tag | Download size |
|---|---|
qwen3.5:9b (also latest) | 6.6-7.6 GB |
qwen3.5:27b | 17-20 GB |
qwen3.5:35b | 22 GB |
qwen3.5:122b | 81 GB |
That is the weights. The context cache comes on top, and it is covered below.
Step 3. Raise the context
Ollama picks a context length from your VRAM:
| VRAM | Default context |
|---|---|
| under 24 GiB | 4k |
| 24-48 GiB | 32k |
| 48 GiB and more | 256k |
For Claude Code the docs ask for 64k or more. Start the server like this:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
In the Ollama app, the same setting is the context length slider. Check the result with ollama ps: the CONTEXT column should show your number, and the PROCESSOR column shows whether the model sits fully on the GPU or partly spilled to the CPU.
Step 4. Launch Claude Code on the model
Option one, a single command from Ollama's docs:
ollama launch claude --model qwen3.5
The docs do not explain what this command writes into Claude Code's configuration, so confirm the result in /status.
Option two, by hand. macOS and Linux:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5
Windows, PowerShell:
$env:ANTHROPIC_AUTH_TOKEN = "ollama"
$env:ANTHROPIC_API_KEY = ""
$env:ANTHROPIC_BASE_URL = "http://localhost:11434"
claude --model qwen3.5
Step 5. Check where requests actually go
Open /status. The Anthropic base URL line should show http://localhost:11434. If the line is missing, the variable never reached the session.
Two traps from the Claude Code docs. If the same variable is set both in your shell and in the env block of a settings file, the value from the file wins. A gateway you configured earlier in ~/.claude/settings.json will therefore override your export, and requests will go there: remove that env block while you experiment. The second trap is a login prompt. Claude Code asks you to sign in when the variables live only in a project's .claude/settings.json or .claude/settings.local.json, because those apply after the first-run wizard. Before that it reads a shell export, ~/.claude/settings.json and managed settings.
Step 6. Give it three tasks
Use your own repository. Task one: explain a module you did not write. Task two: fix a failing test. Task three: make one change across two files. Watch three numbers: did the test pass the first time, how many iterations it took, how long it ran. If the model loops on task two, stop there.
What may not work
Web search. Ollama says hosted WebSearch is not fully supported, so test web tools separately.
Cache and token counting. Ollama does not support cache_control or count_tokens. How Claude Code behaves without the second one, we did not check.
Background traffic. Claude Code contacts Anthropic for updates and telemetry. Setting CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 turns that off at the cost of auto-updates. The WebFetch safety check still calls api.anthropic.com, and the skipWebFetchPreflight: true setting disables it. We did not try a fully offline start, and the installation itself needs a network.
Context. The gap between the recommendation and the default is wide: 64k against 4k. If you skip step 3, your results describe the configuration, not the model.
Models. Ollama's docs show examples with qwen3.5, gemma4:cloud, glm-5.3-flash and kimi-k2.7-code:cloud. Other models are not mentioned in those texts, newer Qwen releases included.
How to tell the setup or the model cannot cope
Four signs, none of which needs a benchmark.
In ollama ps, the PROCESSOR column shows where the model was placed: on the GPU, in system memory, or split between them. Anything other than "100% GPU" can mean the model did not fit in VRAM, and then it runs noticeably slower from offloading. Check the other causes too: the GPU may be disabled on purpose (for example CUDA_VISIBLE_DEVICES=-1) or not detected by Ollama, which can happen on Linux after suspend and resume.
The CONTEXT column shows a number other than the one you set. Possible causes: the server started without the variable, or the Ollama app is already running with its own value.
The model has no tools label in the library. Ollama requires tool support, and according to its page, chat and file edits work with compatible models.
On task two, the agent goes in circles: it reads the same file, repeats the same edit, reruns the same test. That is your signal to change the model or the size.
How much memory you need
We worked this out for Qwen3.8 27B from the parameters on its model card, as an estimate and not a measurement. The Q4_K_M weights take about 16.5 GB, and the FP16 context cache is about 64 KiB per token, so about 8.6 GB for 131,072 tokens. At 64k the cache is around 4.3 GB, and with working buffers the total lands near 22-23 GB. That is tight on a 24 GB GPU or Mac, and on a Mac the system takes part of the memory too. We did not run Claude Code on this model.
If you have less, take the 9b from the table or something smaller. What that size delivers in agent work, we do not know. Step 6 answers that.
An honest verdict
Does it work? By Ollama's documentation, yes, and the page is official. Does Anthropic support it? No. Will it be good on your hardware? We do not know, and we will not guess from a parameter count.
Local makes sense in four cases: the code must not leave the machine, you need to work offline, the hardware already sits on your desk, or you want to poke at an agent without paying per token. You pay in electricity and time. If you need Claude-level results or predictability on every update, a local route promises neither.
Another agent is also a choice. Ollama's CLI page shows the same ollama launch pattern for other integrations, and our roundup of Claude Code alternatives in 2026 compares the tools side by side.
When local is not enough
If you hit the memory ceiling or the quality ceiling, cloud models cost less than you might expect. Below are prices from Claudexia's public catalog (Premium channel) on 10 November 2026, per 1M tokens, and the cost of a hypothetical task: 1M tokens in and 200k out, no cache. It is a comparison assumption, not a measurement.
| Model | In / out | Hypothetical task |
|---|---|---|
deepseek-v4.1-flash-1017-free | $0 / $0 | $0 |
glm-5.3-flash | $0.06 / $0.16 | $0.092 |
deepseek-v4.1-flash | $0.06 / $0.22 | $0.104 |
claude-haiku-5.5 | $0.10 / $0.36 | $0.172 |
claude-sonnet-5-5 | $0.52 / $1.98 | $0.916 |
You lose the privacy of a local run here: requests go to a third-party provider, so do not send anything you would not show a stranger. There is one free model, deepseek-v4.1-flash-1017-free, and it is not Claude. On 29 October there were three, and the list may change again, so do not build a workflow on it. For keys, prices and the risks of "free Claude API" proxies, read free Claude API: what exists in 2026. To keep a paid bill down, see how to cut your Claude Code bill threefold.
The ~/.claude/settings.json block for the free model looks like this. The address has no /v1, and every ANTHROPIC_DEFAULT_* line is needed, otherwise Claude Code asks for its own models:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.claudexia.tech",
"ANTHROPIC_AUTH_TOKEN": "sk_cdx_YOUR_KEY",
"ANTHROPIC_MODEL": "deepseek-v4.1-flash-1017-free",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-v4.1-flash-1017-free",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "deepseek-v4.1-flash-1017-free",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-v4.1-flash-1017-free",
"CLAUDE_CODE_SUBAGENT_MODEL": "deepseek-v4.1-flash-1017-free"
}
}
Variables are covered in the Claude Code guide, and you get a key after signing up. Once the block is saved it overrides your shell exports, by the same rule as in step 5, so remove it before you experiment with Ollama.
FAQ
Can I run Claude Code locally?
By Ollama's documentation, yes: Ollama accepts Anthropic Messages requests, and Claude Code points at http://localhost:11434. Anthropic does not support that mode, and we have not measured quality on your hardware.
How do I connect Claude Code to Ollama?
Run ollama launch claude --model qwen3.5, or set three variables: ANTHROPIC_AUTH_TOKEN=ollama, an empty ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL=http://localhost:11434, then run claude --model qwen3.5. Check the result in /status. The steps are above.
Does Claude Code work offline with a local model?
The model requests go to the local address. Installing Claude Code and Ollama needs a network, and Claude Code's background traffic to Anthropic can be switched off with CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1. We did not test a fully offline start.
Which local model should I pick for Claude Code?
Ollama's docs use qwen3.5 in their example. Two anchors: Ollama asks for a 64k context on local models, and the model must support tools (the qwen3.5 family carries the tools label in the library). We have not compared models on quality. Take the three tasks from step 6 and run the 9b and the 27b one after the other.
Does Anthropic support Claude Code with non-Claude models?
No. Its gateway documentation says Anthropic does not support pointing Claude Code at non-Claude models through gateways. The setup may work, but with no commitment from Anthropic.
Which is better, Ollama or a free cloud model?
It depends on the task. Ollama gives you privacy and no per-token bill, but runs into your memory and context. A free cloud model needs no hardware, yet your requests go to a third-party provider and the list of free models changes. Compare both on the same three tasks before you commit.