One command, or three environment variables. Plus the 64k context setting Ollama's defaults don't give you, the VRAM that costs, and what Ollama's Anthropic API doesn't support.
Claude Code is Anthropic's terminal agent. It reads a codebase, edits files and runs commands. It normally talks to Anthropic's API, but since Ollama v0.14.0 added an Anthropic-compatible Messages API, you can point it at a model on your own machine instead. This is the setup, straight from Ollama's docs, with the one setting that trips most people up. If you're still choosing between agents, start with our Claude Code vs Codex vs OpenCode comparison.
Claude Code in your terminal, talking to a model on the box next to you. · Illustration generated with Higgsfield
Step 1: set the context length first
Do this before anything else. Ollama's Claude Code page says: "For larger repositories, set the context length to 64k or higher." Its context-length page lists the defaults by VRAM: under 24 GiB you get 4k, 24–48 GiB gets 32k, 48 GiB and up gets 256k. Claude Code's system prompt and tool definitions take a big bite of that before your code even arrives.
If you use the Ollama desktop app instead of ollama serve, the docs say to change the context slider in the app's settings. On Windows, Ollama reads your user and system environment variables, per the FAQ. Set them there and restart Ollama.
Step 2 (fast path): ollama launch claude
ollama launch claude
That's it. ollama launch arrived in Ollama v0.15.0. It lets you choose a model, configures Claude Code to use Ollama and starts the session. For scripts or CI, the docs show a non-interactive form. --yes skips the prompts and pulls the model if needed, but requires --model, and anything after -- goes straight to Claude Code:
# from Ollama's docs (25 Sep 2026); swap in a local model name to stay offline
ollama launch claude --model gemma4:cloud --yes -- -p "how does this repository work?"
Note that the docs' example uses a :cloud model, which runs on Ollama's servers, not your GPU. If staying local is the point, use a model you've pulled, like qwen3-coder:30b.
Step 2 (manual path): three environment variables
If you'd rather wire it yourself, for example to keep your existing Claude Code install, the docs give the install commands and three variables:
# 1. Install Claude Code (from Ollama's docs)
# macOS / Linux
curl -fsSL https://claude.ai/install.sh | bash
# Windows (PowerShell)
irm https://claude.ai/install.ps1 | iex
# 2. Point it at Ollama
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
# 3. Run it with a local model
claude --model qwen3-coder:30b
One gotcha the docs call out: Claude's own settings can override shell variables. If Claude Code still seems to hit Anthropic, check your Claude settings for a base URL or credentials and run /status inside Claude Code to see where it's connected.
Which local model, and will it fit?
Ollama's docs send you to its tools-capable models list. The model has to support tool calling, or Claude Code can't edit files or run commands. The two I'd shortlist for coding are Qwen3-Coder 30B (19 GB download, 256K max context) and gpt-oss 20B (14 GB, 128K), per the Ollama library. At the 64k context Claude Code wants, our VRAM engine gives:
`tool_choice`, which forces or disables specific tool use: listed as not supported on Ollama's Anthropic compatibility page.
Token counting (/v1/messages/count_tokens): not supported.
Hosted web search: not fully supported. Ollama offers its own web search you can wire in instead.
Images by URL: not supported. Base64 images work.
Extended thinking: basic support; budget_tokens is accepted but not enforced.
Most everyday Claude Code work (reading files, editing, running commands) doesn't depend on those. But if a plugin or workflow of yours relies on forced tool choice, expect it to behave differently. That's the honest trade: the workflow comes with you offline, not every API feature does.
Pros
+ One command (`ollama launch claude`) and you're running
+ Your code stays on your machine with a local model
+ Same Claude Code workflow and commands you already know
Cons
− Needs 64k context, which is 24GB-class VRAM for a 30B coder
− tool_choice, token counting and hosted web search not fully supported
− Claude Code itself is proprietary (Anthropic Commercial Terms)
Weighing the alternatives? The same setup for OpenCode (MIT, one config file) and Codex CLI (Apache-2.0, built around gpt-oss) takes about as long.
Quick answers
Do I need an Anthropic account to use Claude Code with Ollama?
Ollama's manual setup sets ANTHROPIC_API_KEY to an empty string and ANTHROPIC_AUTH_TOKEN to "ollama", so requests go to your local Ollama server, not Anthropic's API. Claude Code is still Anthropic's software, used under Anthropic's Commercial Terms.
Why does Claude Code lose track of my project with Ollama?
Context length. Ollama defaults to 4k tokens on GPUs under 24 GiB and 32k on 24–48 GiB, and its docs recommend 64k or more for Claude Code. Start Ollama with OLLAMA_CONTEXT_LENGTH=64000 and check the CONTEXT column in ollama ps.
Which Ollama version do I need?
Anthropic API compatibility arrived in Ollama v0.14.0 (January 2026), and ollama launch in v0.15.0. This guide is pinned to v0.34.4, the latest stable release on 25 Sep 2026.
What's the best local model for Claude Code?
It needs tool calling and a long context. Qwen3-Coder 30B is the common pick on a 24GB GPU (about 24.0 GiB at 64k on our engine, 21.0 GiB with an 8-bit KV cache). gpt-oss 20B fits 16GB cards (about 15.6 GiB, or 14.1 GiB with q8_0).
Can I use Ollama's cloud models with Claude Code instead?
Yes. Ollama's docs show setting ANTHROPIC_BASE_URL=https://ollama.com with your OLLAMA_API_KEY as the auth token, with no local install. That runs the model on Ollama's servers, so your code leaves your machine.