Claude Code is Anthropic’s coding agent for the terminal, and it normally talks to Anthropic’s models. Since Ollama added an Anthropic-compatible API, it can also run against a model on your own machine: ollama launch claude sets it up in one command. It is one of the rising “ollama” searches this month, and there are limits you should know before relying on it.
This guide covers the two ways to set it up, the context-length and model settings that make or break it, what the compatibility layer does not support, and what still leaves your machine. BFWR has not benchmarked this setup; everything below comes from Ollama’s and Anthropic’s documentation.
Quick answer
- Fastest setup:
ollama launch claude, then pick a model. - Manual setup: point Claude Code at Ollama with
ANTHROPIC_BASE_URL=http://localhost:11434,ANTHROPIC_AUTH_TOKEN=ollamaand an emptyANTHROPIC_API_KEY, then runclaude --model <model>. - Context: Ollama says to set a 64K or larger context window for local models. Its default on most graphics cards is 4K.
- Models: use one with tool support, such as Qwen3.8, Qwen3-Coder, gpt-oss or Gemma 4.
- Limits: prompt caching, token counting and forced tool choice from Anthropic’s API are not supported by Ollama.
Setup 1: ollama launch claude
Ollama’s integration page for Claude Code starts with a single command:
ollama launch claude
It starts Claude Code connected to Ollama and lets you pick a model. For scripts and CI, Ollama documents a non-interactive form: the --yes flag “skips selectors, pulls the model when needed”, and requires --model. Arguments after -- pass straight through to Claude Code:
ollama launch claude --model qwen3.8:27b --yes -- -p "how does this repository work?"
You need both Ollama and Claude Code installed. Claude Code’s installer is curl -fsSL https://claude.ai/install.sh | bash on macOS and Linux, and irm https://claude.ai/install.ps1 | iex in PowerShell on Windows.
Setup 2: environment variables
If you prefer to see what is going on, set the variables yourself. These are Ollama’s documented values:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.8:27b
The token is a placeholder: Ollama’s compatibility page labels it “required but ignored”, and notes that “The local server does not validate API keys.” Claude Code’s own reference describes ANTHROPIC_BASE_URL as the way to “Override the API endpoint to route requests through a proxy or gateway”, and ANTHROPIC_AUTH_TOKEN as a “Custom value for the Authorization header”.
Ollama adds one warning that catches people out: “Claude settings can override shell variables.” If you have a base URL or key in ~/.claude/settings.json, change it there, then run /status inside Claude Code to confirm where it is connected.
Background tasks need a model too
Claude Code does not use only the model you pick. Its reference says the ANTHROPIC_DEFAULT_HAIKU_MODEL variable sets the “Model ID that the haiku alias resolves to, also used for background functionality”. There are matching variables for the sonnet and opus aliases, and CLAUDE_CODE_SUBAGENT_MODEL for subagents. When you set things up by hand, point these at a local model too; otherwise background work or a subagent may request a Claude model name that your Ollama server does not have:
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3.8:27b
export CLAUDE_CODE_SUBAGENT_MODEL=qwen3.8:27b
For tools that insist on Anthropic model names, Ollama’s documentation offers a second route: copy a local model under a Claude name with ollama cp, for example ollama cp qwen3-coder claude-3-5-sonnet.
The context length setting
Ollama’s integration page says it plainly: for local models, “Choose a model and set a 64k+ context window.” Its context-length documentation repeats the point for agents in general: “Tasks which require large context like web search, agents, and coding tools should be set to at least 64000 tokens.”
Ollama’s own default is much smaller: 4K of context on graphics cards with less than 24GB of memory, 32K from 24 to 48GB, and 256K above that. An agent’s instructions and tool definitions take up a large share of a 4K window before any of your code is added, so raise it before you start:
OLLAMA_CONTEXT_LENGTH=65536 ollama serve
A 64K context costs memory. Our OpenCode local setup guide has a table of eight coding-capable models at 32K and 64K, computed with our VRAM calculator: Gemma 4 12B needs about 10.3GB at 64K and Qwen3.8 27B about 22.5GB, both at 4-bit. The same numbers apply here, because the limit is the model and its context, not the agent in front of it. They apply to personal agents too; see our OpenClaw guide.
Which model to use
Claude Code reads files, edits them and runs commands through tool calls, so the model must support tools. On Ollama’s library pages, look for the tools label; Qwen3.8, Qwen3-Coder, gpt-oss and Gemma 4 all carry it. Ollama’s own manual-setup example uses qwen3.5.
Be realistic about quality. Claude Code was designed around Anthropic’s models, and a 27B local model is much smaller, so results depend heavily on which model you choose. Our list of the best local LLMs for coding compares the candidates on licence, memory and published benchmark scores.
What the compatibility layer does not support
Ollama supports “a subset of the Anthropic Messages API”. Messages, streaming, system prompts, images, tool calls and thinking all work. Its documentation lists these as not currently supported:
- the token-counting endpoint,
/v1/messages/count_tokens tool_choice, for forcing or disabling specific tools- prompt caching with
cache_controlblocks - the Batches API, citations and PDF document blocks
Two more are partial: images only as base64, not URLs, and extended thinking with “budget_tokens accepted but not enforced”. Token counts are approximations from the model’s own tokenizer. For Ollama’s cloud models, the integration page adds that “Hosted WebSearch and advanced tool controls are not fully supported.”
Claude Code’s side has one consequence of its own. Its reference notes that when ANTHROPIC_BASE_URL points at a non-Anthropic host, “MCP tool search is disabled by default”, and that Remote Control is disabled.
What still leaves your machine
With a local model, your prompts and code go to Ollama on localhost, not to Anthropic. Claude Code itself still has its own network activity, which you can reduce:
DISABLE_TELEMETRY=1opts out of telemetry. Anthropic’s reference says “Telemetry events don’t include user data like code, file paths, or Bash commands”, and that the setting also disables feature-flag fetching.DISABLE_ERROR_REPORTING=1opts out of error reporting.- Ollama’s cloud models (names ending in
:cloud) run on Ollama’s servers, not yours. Check the model name if staying local is the point.
Also note the licence. Claude Code is not open source: its repository states “© Anthropic PBC. All rights reserved. Use is subject to Anthropic’s Commercial Terms of Service.” If you want an open-source agent for local models, OpenCode is MIT-licensed.
Permissions
Ollama’s page notes that “Claude Code prompts for permission on most actions.” That is a safer default than OpenCode’s, which lets the agent edit files and run commands without asking unless you configure it otherwise. Keep it that way with a local model, and avoid --dangerously-skip-permissions outside an isolated environment. A smaller model misreads instructions more often, and the prompt is your chance to catch it.
If Ollama runs on another machine on your network, change ANTHROPIC_BASE_URL to that machine’s address, and read our guide to running Ollama as a server first. Ollama’s documentation describes no built-in authentication for its API, so it should not be reachable from the open internet.
FAQ
Is Claude Code free with Ollama?
The Claude Code tool costs nothing to install. Running it against a local model through Ollama has no per-token cost; you pay in hardware and electricity. Ollama’s cloud models need an Ollama account and key.
Do I need an Anthropic account?
Ollama’s documented setup sets the token to a placeholder and the API key to empty, and sends requests to your local server. Its instructions do not include signing in to Anthropic.
Why does Claude Code fail to call tools or forget the task?
Usually the context window. Raise Ollama’s context to 64K or more, and use a model with tool support.
Claude Code or OpenCode for local models?
Both work through Ollama. Claude Code asks permission by default and is proprietary. OpenCode is open source and provider-neutral, with permissive defaults you should tighten. DeepSeek Harness also accepts a local OpenAI-compatible server. Our Ollama vs Claude comparison covers the wider local-versus-API trade-off.
Related guides and tools
- LiteLLM and its alternatives, if you want one endpoint in front of several backends
- LLM context windows and what they cost in VRAM
- VRAM calculator and Ollama models and VRAM
- LM Studio Bionic
- Cline with a local model
- Pi coding agent with a local model
Sources
- Ollama docs: Claude Code integration
- Ollama docs: Anthropic compatibility and context length
- Claude Code docs: environment variables and model configuration
- anthropics/claude-code on GitHub (licence notice; v2.1.302, 16 October 2026)
Updated 18 October 2026. Ollama and Claude Code documentation were read on that date; both change often.
Work out what your hardware can actually run
Free calculators and directories, sized from real model weights — before you download gigabytes or order a card:

