Skip to content
local-ai
Intermediate

Using Claude Code with a local model via Ollama

Claude Code can run against a model served locally by Ollama instead of a hosted API. Here is how to point it at Ollama, which local models can keep up with agentic coding, and an honest account of what you give up.

By Leon Mallett

What you’ll learn

How to run Claude Code against a model served locally by Ollama rather than a hosted API, which local models are worth pointing it at, and what you lose by doing so. Setup methods here change quickly, so the commands below were checked in October 2026; confirm them against the current Ollama and Claude Code documentation before relying on them.

What this gets you, and what it does not

Running Claude Code against a local model keeps your code and prompts on your machine and removes the per-token cost. That is the appeal. Be clear-eyed about the trade, though: agentic coding leans hard on reliable tool use over many steps, and this is exactly where local models still trail the hosted frontier. On a scoped, well-defined task a good local model can do real work; on a long, open-ended one it is more likely to lose the thread than the hosted model Claude Code is built around. Treat this as a capable, private option for suitable tasks, not a free replacement for the hosted experience on hard work.

Point Claude Code at Ollama

Ollama now exposes an Anthropic-compatible API, so Claude Code can talk to it directly, with no translation proxy. First make sure Ollama is running and the model you want is pulled:

ollama pull qwen3-coder:30b

Then set these environment variables and launch Claude Code against the Ollama tag:

export ANTHROPIC_BASE_URL="http://localhost:11434"
export ANTHROPIC_AUTH_TOKEN="ollama"
claude --model qwen3-coder:30b

A few notes. The base URL has no /v1 on the end, because this is the Anthropic-compatible endpoint rather than the OpenAI-compatible one. The auth token is a placeholder: a local server does not check it, but Claude Code expects something to be set. If a fresh install does not seem to pick up settings from ~/.claude/settings.json, set the variables in your shell as above instead, which is the more reliable route today.

Pick a model that can keep up

The model matters more than the wiring. For agentic coding you want one trained for tool use with a long context window. Sensible choices from the catalogue are Qwen3-Coder 30B-A3B, whose mixture-of-experts design keeps it quick, and Devstral Small, which was built for agent-driven work. Both want around a 24GB card. Our choosing a local coding model guide covers the options by hardware tier.

Expect to feel the difference from the hosted model most on long tasks: a local agent loop generates a lot of tokens, so speed and context length bite, and tool-calling reliability is the first thing to wobble when a task runs long.

If it does not connect

  • Older Ollama. The Anthropic-compatible endpoint is a recent addition. If yours predates it, update Ollama, or put a translation proxy such as LiteLLM in between, which accepts Anthropic-format requests and forwards them to Ollama.
  • Wrong base URL. Check there is no trailing /v1, and that Ollama is actually running on port 11434 (ollama ps will show loaded models).
  • Settings not applied. Use shell environment variables rather than the settings file if the file is being ignored, as noted above.

OpenCode: the provider-agnostic alternative

If you would rather use a tool built to be model-agnostic from the start, OpenCode is an open-source coding agent that supports many providers, including a local Ollama endpoint, configured in its own settings rather than through Anthropic-style variables. The trade-offs with local models are the same; only the harness differs.

Next steps

Related tools

Last updated 2 October 2026.