Web Asset House Guides
Local AI

Use Claude Code with Local Models: Ollama's Anthropic-Compatible API Explained

By Web Asset House Studio ·

Note: Some future links on this site may be affiliate links. We never claim hands-on testing; guides are researched from the public sources listed in each article.

How we wrote this: A summary of Ollama's official Anthropic compatibility reference, Claude Code integration page and API introduction (linked below), checked October 29, 2026. We describe what the docs say; the supported feature list changes between versions, so check the reference for yours.

Claude Code is a coding agent that reads a codebase, edits files and runs commands. Normally it talks to Anthropic's API. Ollama implements a subset of the Anthropic Messages API, so Claude Code and the official Anthropic SDKs can be pointed at models running on your own machine instead.

The quick route: ollama launch

Ollama's Claude Code page gives a one-line start:

ollama launch claude

launch configures and starts the app against your Ollama models. Our Ollama commands cheat sheet lists the other apps it supports. For scripts or CI, the docs show a non-interactive form:

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

--yes skips the selectors, pulls the model if needed and requires --model; everything after -- is passed to Claude Code. That example uses a cloud model; substitute a local one if you want everything on your machine.

The manual route: three environment variables

If you install Claude Code yourself, the docs say to set:

export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434

then run Claude Code with a model you've pulled, for example claude --model qwen3.5. The token value is a placeholder: per the reference, the local server doesn't validate API keys. The Anthropic client appends /v1/messages to the base URL, which is why the base URL has no path.

Pick a model with enough context

The Claude Code page says to choose a model with enough context for your repository, and for local models to set a 64k or larger context window. Our context length guide shows how to check and raise the setting. A larger context uses more memory, which the calculator below helps estimate.

Agent features such as file edits and running commands depend on tool calling, so pick a model that supports tools; see Ollama tool calling basics.

Using the Anthropic SDKs directly

The same endpoint works from code. The docs' Python example creates anthropic.Anthropic(base_url='http://localhost:11434', api_key='ollama') and calls client.messages.create(...) with a local model such as qwen3-coder. JavaScript and curl versions follow the same pattern, and the reference has examples for streaming and tool calling.

Tools that expect Claude model names. Some tools assume default Anthropic model names. The docs suggest copying a local model under that name:

ollama cp qwen3-coder claude-3-5-sonnet

Requests for that name then go to your local model.

What's supported, and what isn't

The reference lists support for messages, streaming, system prompts, multi-turn conversations, vision (images), tools and extended thinking, with some limits:

Not currently supported

Partly supported

The docs also note that token counts are approximations based on the underlying model's tokenizer.

Local versus cloud

Ollama's API introduction lists two base URLs for Anthropic clients: http://localhost:11434 for your local server and https://ollama.com for direct cloud access, which needs an API key sent as a bearer token. Cloud model names carry a :cloud suffix when used through a signed-in local server.

If the point is keeping code on your machine, stick to local models, and consider local-only mode, which turns off Ollama's cloud models and web search entirely. Claude Code has its own settings and permission rules; the Ollama page notes that Claude settings can override shell variables, so check them if requests don't go where you expect.

Quick checklist

Sources

← All Local AI guides · All guides