Blog
3 min read

Claude Code With Local Models (Ollama, LM Studio): How It Works and the Catch

You can point Claude Code at a local open-weight model through an Anthropic-compatible endpoint such as Ollama's. How the setup works with ANTHROPIC_BASE_URL, what hardware and context you need, why tool calling and quality suffer, what Anthropic does and doesn't support, and when it's worth it.

"Claude Code with local models" is one of the most-searched Claude Code topics. The idea: keep Claude Code's agent loop, tools and interface, but swap the Claude model for an open-weight model running on your own machine — free per token, private, offline.

It's possible. It comes with real trade-offs, and it's worth being clear about what you're getting.

How it works

Claude Code talks to models through the Anthropic Messages API. Any server that speaks the same API format can stand in. Since early 2026, Ollama (v0.14 and later) exposes an Anthropic-compatible endpoint, and proxies like LiteLLM can translate for other local servers such as LM Studio or vLLM.

You point Claude Code at it with environment variables:

export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama   # placeholder; Ollama ignores it
claude --model qwen3-coder           # or whichever model you pulled

Check Ollama's Anthropic compatibility docs for the current variable names and recommended models. Ollama recommends a context length of at least 32K tokens; for a coding agent, more is better.

What Anthropic supports — and doesn't

Anthropic's docs are explicit: gateways that expose a supported API format work, but Anthropic doesn't support routing Claude Code to non-Claude models through any gateway. In practice that means:

  • Features may break as Claude Code evolves (new tools, thinking formats, caching).
  • Bugs you hit with a local model are yours to debug.
  • Fast mode, some server-side tools and features that depend on Anthropic's API won't work.

The catch: quality and tool use

Claude Code is tuned around Claude models. An agent loop is demanding: it needs reliable tool calling, long context, and good judgement over dozens of steps. Smaller local models commonly:

  • Produce malformed tool calls or ignore tool results.
  • Lose track of the task in long sessions.
  • Write plausible code that doesn't run.

A 7B–14B model on a laptop is fine for small edits and experiments; for real agentic work you need a large coding model and serious hardware (lots of GPU memory or unified memory). Even then, expect a noticeable step down from frontier models. (Run an LLM Locally)

When it's worth it

  • Privacy-sensitive code that can't leave your machine, and you accept lower quality.
  • Offline work — flights, restricted networks.
  • Learning and experimenting with how agents behave across models.
  • Cheap bulk tasks like renaming, formatting or boilerplate.

When it isn't

  • You want Claude Code's results. Use Claude — Haiku 5.5 is very cheap if cost is the concern. (Opus vs Sonnet vs Haiku)
  • Production work where reliability matters.

Middle grounds

  • Open-source agents built for many models, like OpenCode, are designed to switch providers and local models. (Claude Code vs OpenCode)
  • OpenRouter gives you many hosted models through one API, which some agents support directly. (What Is OpenRouter?)
  • Ollama cloud models run larger models on Ollama's servers through the same local endpoint.

Watch your subscription settings

If ANTHROPIC_AUTH_TOKEN (or an API key) is set, Claude Code uses it instead of your claude.ai login. Unset these variables when you go back to Claude, or you'll wonder why your Max plan isn't being used. Run /status to see the active credential.

The summary

  • Point ANTHROPIC_BASE_URL at an Anthropic-compatible local endpoint like Ollama's.
  • It works, but it's unsupported by Anthropic and quality drops sharply with smaller models.
  • Use it for privacy, offline or experiments; use Claude for real agentic work.

EasySpawn runs Claude Code on a persistent server with your own Claude subscription or API key — no markup — so the agent always has a frontier model behind it. See how it works or join the waitlist.

Related: What Is Ollama? · Is Claude Code Free? · How Coding Agents Work · Claude Code Settings Explained

Keep reading