Claude Code talks to a model over an Anthropic-style API. Ollama exposes an API of that shape, so you can point Claude Code at a model you run yourself, or at one of Ollama's cloud models. Ollama's integration page documents three ways to do it. This post walks through each, then covers the one setting that decides whether it works on a real repository: context length.
The one-liner: ollama launch claude

With Ollama installed, the shortest path is:
ollama launch claude
Per the docs, this starts Claude Code wired to Ollama and lets you pick a model from a selector. You need Claude Code installed first.
Manual setup against a local Ollama
If you want to see exactly what the launcher does, or run it from your own shell profile, set three environment variables and start Claude Code with a model name. First install Claude Code:
curl -fsSL https://claude.ai/install.sh | bash
Then point it at the local Ollama server:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5
The token value is a placeholder: the docs use the literal string ollama and an empty ANTHROPIC_API_KEY. The same thing works inline for a single run, here with a cloud-hosted model name from the docs:
ANTHROPIC_AUTH_TOKEN=ollama ANTHROPIC_BASE_URL=http://localhost:11434 ANTHROPIC_API_KEY="" claude --model kimi-k2.7-code:cloud
One gotcha the docs call out: Claude Code settings can override your shell variables. If the connection goes to the wrong place, fix the base URL or credentials in the settings and run /status to check what Claude Code is actually using.
Straight to Ollama's cloud, no local install
You can skip the local server entirely. Create an API key, export it as OLLAMA_API_KEY, and run:
ANTHROPIC_BASE_URL=https://ollama.com \
ANTHROPIC_AUTH_TOKEN="$OLLAMA_API_KEY" \
ANTHROPIC_API_KEY="" \
claude --model glm-5.3-flash
Pick a cloud model that supports tool calling; Ollama lists them at ollama.com/search?c=cloud. For local models, the tools filter at ollama.com/search?c=tools does the same job.
The 64k context rule

A coding agent sends a lot of text on every turn: instructions, tool definitions, file contents, command output. A small context window silently cuts that off, and the agent starts forgetting the start of the task. Ollama's docs say that for larger repositories you should set the context length to 64k or higher, and its context-length page says tasks that need large context, such as web search, agents and coding tools, should be set to at least 64000 tokens.
Defaults depend on where the model runs. According to the context-length page, cloud models default to their maximum context length. For local models the page lists defaults by available VRAM: 4k under 24 GiB, 32k from 24 to 48 GiB, and 256k at 48 GiB or more. Ollama's separate FAQ and Modelfile reference still quote different defaults (4096 and 2048 tokens), so do not rely on any of them. Set the value explicitly and check it.
The simplest way to set it for a server you start yourself:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
In the Ollama desktop app, use the context-length slider in settings instead. A bigger window needs more memory, so a model that fit before may no longer fit on your GPU.
Then prove the setting took effect, rather than trusting it:
ollama ps
The output has a CONTEXT column and a PROCESSOR column:
NAME ID SIZE PROCESSOR CONTEXT UNTIL
gemma4:latest c6eb396dbd59 9.6 GB 100% GPU 131072 2 minutes from now
Check both. CONTEXT should be at least 64000. PROCESSOR tells you whether the model sits fully on the GPU (100% GPU) or has spilled partly onto the CPU, which the docs advise avoiding. If raising the context pushes you into CPU offload, use a smaller model or a smaller window instead of accepting a slow agent.



