Yes, Claude Code can work with a local model through Ollama, and Ollama devoted a separate documentation page to it. The setup was not tested on real hardware, so what follows is only what Anthropic's and Ollama's texts say as of 10 November 2026, plus what you will have to check yourself. Whether the model you pick can handle your repository only your own run will show. Step 6 describes the order of that run.
People come to a local setup for three reasons: the code must not leave the machine, the network is missing or flaky, or they want to try an agent without paying per token. The reasons are sound. That is why the limits are worth reading before you install anything.
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 table rests on three texts: Claude Code's gateway documentation and two Ollama pages, one on Anthropic API compatibility and one on Claude Code.
The last row matters most. Anthropic does not name Ollama, but the statement covers in spirit any setup where something other than Claude answers behind ANTHROPIC_BASE_URL. That is a reading of the text, not a quote. The consequence is simple: if a Claude Code update breaks something on your local model, waiting for a fix from Anthropic is pointless. The same gateway documentation carries a second warning. New Claude Code features arrive with every release, and a gateway that does not forward them breaks the matching functions.
Launch in steps
Step 1. Install Claude Code
Installation per Anthropic's documentation for macOS, Linux and WSL (more in the Claude Code setup guide):
curl -fsSL https://claude.ai/install.sh | bash
On Windows irm https://claude.ai/install.ps1 | iex does the job, and if it fails, the article on installing Claude Code on Windows will help. To check: claude --version.
Step 2. Install Ollama and pull a model
The Ollama installer is on ollama.com. Then pull the model the documentation uses for its example:
ollama pull qwen3.5
Without a tag you download latest, which on the model's library page matches 9b. The family carries the vision, tools and thinking labels. 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 alone. The context cache comes on top, and it is covered below.
Step 3. Raise the context
Ollama chooses the 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 documentation advises 64k or more. Start the server like this:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
In the Ollama app this is the context length slider in settings. Check the result with ollama ps: the CONTEXT column shows the actual number, and PROCESSOR tells you whether the model sits fully on the GPU or part of it moved to the CPU.
Step 4. Launch Claude Code on the model
Method one, a single command from Ollama's docs:
ollama launch claude --model qwen3.5
Which Claude Code settings the command changes, the documentation does not reveal, so verify the result with /status.
Method two, manual. 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. Find out where requests really go
Open /status: the Anthropic base URL line should read http://localhost:11434. No such line? Then the variable did not reach the session.
Claude Code's docs warn about two pitfalls. First, when a variable is set both in your shell and in the env block of a settings file, the file wins. A gateway configured earlier in ~/.claude/settings.json will override your export and requests will go to it, so remove that env block while you experiment. Second, sign-in. If the variables live only in a project's .claude/settings.json or .claude/settings.local.json, Claude Code will still ask you to log in, because those files are applied after the first-run wizard. Before that point it reads a shell export, ~/.claude/settings.json and managed settings.
Step 6. Give it three tasks
You need three trials on your own repository. One: ask it to explain a module you did not write. Two: fix a failing test. Three: make one change across two files at once. Record three numbers: did the test pass on the first try, how many iterations it took, how much time went. If the model spins in circles on the second trial, there is no point continuing.
What may not work
Web search. Ollama says hosted WebSearch is not fully supported, so test web tools separately.
Prompt cache and token counter. Ollama has neither cache_control nor count_tokens. What Claude Code does without the counter was not checked.
Background calls to Anthropic (updates, telemetry) are switched off by CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1, and the price is auto-updates. The WebFetch safety check still knocks on api.anthropic.com, and the skipWebFetchPreflight: true setting turns it off. A start with no network at all was not tried, and the installation itself is impossible without the internet.
Context. The recommendation and the default differ severalfold: 64k against 4k. Skip step 3 and the results of your run describe the configuration, not the model.
Models. Ollama's docs use qwen3.5, gemma4:cloud, glm-5.3-flash and kimi-k2.7-code:cloud in their examples. Other models, Qwen3.8 included, are absent from those texts.
How to tell the setup or the model cannot cope
Four signs, and none needs a benchmark.
PROCESSORinollama psshows where the model sits: in VRAM, in system memory or split between them. Any value other than "100% GPU" may mean the model did not fit in VRAM entirely, and then offloading slows it down noticeably, as the Qwen article says. Check the other causes too: the GPU may have been disabled on purpose (say,CUDA_VISIBLE_DEVICES=-1) or not detected by Ollama, which happens on Linux after waking from sleep.- The
CONTEXTcolumn does not match the number you set. Likely causes: the server started without the variable, or the Ollama app is running alongside with a value of its own. - The model has no tools badge in the library. Ollama makes tool support a condition, and its page ties chat and file edits to compatible models.
- On the second trial from step 6 the agent walks in circles: it reads the same file, repeats the same edit, reruns the same test. That is the signal to change the model or its size.
How much memory you need
The formula and numbers for Qwen3.8 27B are worked out in the article Running Qwen 3.8 27B locally. The Q4_K_M weights take about 16.5 GB, and the FP16 context cache costs about 64 KiB per token, which is about 8.6 GB for 131,072 tokens. At 64k the cache is around 4.3 GB, and with working buffers the total reaches 22-23 GB. That is tight on a 24 GB GPU or Mac, all the more so because on a Mac the system takes part of the memory. The calculation uses numbers from the model card and stays an estimate, not a measurement. Claude Code was not run on this model.
With less memory, take the 9b from the table in step 2, or something smaller. What that size delivers in agent work is unknown, and step 6 answers it.
The verdict without gloss
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? Unknown, and guessing from a parameter count is a bad idea.
A local route makes sense under one of four conditions: the code must not leave the machine, you need to work offline, suitable hardware is already on your desk, or you are curious to try an agent without paying per token. You pay in a different currency: electricity and time. If you need Claude-level results or predictability after every update, the local setup promises neither.
You can also switch the agent itself. The same Qwen 3.8 article gives the command ollama launch opencode --model qwen3.8, Ollama's CLI page shows the same ollama launch pattern for other integrations, and OpenCode installation is covered in OpenCode: install and models. Other tools are compared in the roundup of Claude Code alternatives.
When local is not enough
If memory or quality runs short, cloud models remain, and they cost less than you might think. The table below uses prices from codexkey's public catalog (Premium channel) on 10 November 2026, per 1M tokens. The last column is a hypothetical task: 1M tokens in and 200k out, no cache. The assumption is for comparison and is 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 |
The privacy of a local run is lost 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 a workflow cannot be built on it. How to connect a free or cheap model to Claude Code is shown in the article Claude Code for free: what works in 2026, keys, prices and the risks of "free Claude API" proxies are in free Claude API: what exists in 2026, and ways to shrink a paid bill are in how to cut your Claude Code bill threefold.
Here is the ~/.claude/settings.json block for the free model. The address has no /v1, and every ANTHROPIC_DEFAULT_* line is required, otherwise Claude Code asks for its own models:
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.codexkey.online",
"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"
}
}
The variables are described in the Claude Code guide, and a key appears after signing up. A saved block overrides your shell exports by the same rule as in step 5, so remove it for your Ollama experiments.
FAQ
Can I really run Claude Code on my own machine?
By Ollama's documentation, yes: the server accepts the Anthropic Messages format, and Claude Code can be pointed at http://localhost:11434. Anthropic does not support that mode, and quality on your hardware was not measured.
How do I point Claude Code at Ollama?
Either with the command ollama launch claude --model qwen3.5 or with three variables: ANTHROPIC_AUTH_TOKEN=ollama, an empty ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL=http://localhost:11434. After them run claude --model qwen3.5 and check the result in /status. The details are in the steps above.
Does Claude Code work offline with a local model?
The requests to the model go to the local address. Installing Claude Code and Ollama needs a network, though, and Claude Code's background traffic to Anthropic is silenced by CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1. A fully offline start was not tested.
Which local model should I take for Claude Code?
Ollama's documentation shows an example with qwen3.5. There are two anchor conditions: the context of 64k that Ollama expects from local models, and the ability to call tools (the qwen3.5 family carries the tools label in the library). Models were not compared on quality, so take the three tasks from step 6 and run the 9b and the 27b one after the other.
Does Anthropic acknowledge Claude Code with non-Claude models?
No. The gateway documentation says so outright: Anthropic does not support pointing Claude Code at non-Claude models through gateways. The setup may come to life, but Anthropic promises nothing.
Ollama or a free cloud model: which to choose?
It comes down to the task. Ollama gives you privacy and no per-token bill, but it is limited by 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. Running Claude Code on such models is covered in the article on free Claude Code. Before choosing, run both on the same three tasks.