Point Claude Code at a local model: ollama launch claude, the 64k context rule and a --yes CI run

Ollama documents running Claude Code against local or cloud open-weight models. The launch command, the manual env-var setup, the 64k context rule and a scripted --yes run, with the documented limits.

if.codesNov 22, 2026 · 4 min readAI-assisted

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

Setting up a local environment for AI-assisted coding.
Setting up a local environment for AI-assisted coding.

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 visualization of expanding the model's context window for larger projects.
A visualization of expanding the model's context window for larger projects.

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.

Want AI wired into the systems you already run?I build LLM integrations with costs and quality you can see. The estimate is free.

A scripted run for CI: --yes

Automating AI agent runs within a continuous integration pipeline.
Automating AI agent runs within a continuous integration pipeline.

For scripts, Docker and CI there is a non-interactive form of the launcher:

ollama launch claude --model gemma4:cloud --yes -- -p "how does this repository work?"

Three details from the docs matter here:

  • --yes skips the selectors and pulls the model if needed.
  • --yes requires --model, so a CI job always names its model explicitly.
  • Everything after -- goes straight to Claude Code. Here -p is Claude Code's print mode, which answers once and exits.

Treat the output of such a job as you would any model output from a less capable model: useful as a first pass, not as a gate you trust blindly. Keep the model name pinned in the script so results do not shift when a default changes.

What does not fully work

The docs are explicit about the limits on the direct-to-cloud path: hosted WebSearch and advanced tool controls are not fully supported. Basic chat and file edits work with compatible models. Claude Code still asks permission for most actions; for unattended use the docs point to permission rules, or to --dangerously-skip-permissions only inside an isolated environment. If you run this in CI, use a throwaway container, not a runner that holds your deploy credentials.

A short checklist

  1. Install Claude Code, then try ollama launch claude.
  2. Choose a model that supports tools.
  3. Set the context to 64000 or more, then confirm it in the CONTEXT column of ollama ps.
  4. Check PROCESSOR shows the model on the GPU.
  5. For CI, pin --model, use --yes, and run in an isolated container.
  6. If it behaves oddly, run /status and look for settings overriding your environment variables.

Sources

if.codesI build RAG, AI integrations and agent pipelines on Go and Python backends — and write about it here.
// keep reading

More posts on AI and backends.

// free quote

Read something you need? I’ll quote it for free.

RAG, AI integrations, agents or the backend underneath — tell me what you have and what should change. I read every request myself.

Free · no commitment

Tell me what you have. I’ll tell you what it takes.

1Describe the projectA few sentences is enough — about two minutes.
2I review itI read it myself and may ask a follow-up question.
3You get a free quoteScope, approach and estimate — yours to keep, no strings.
What kind of project is it?
Free and without obligation. Your details are used only to reply — see the privacy policy.