refusal rate
Subscribe

Yes, with caveats. Ollama, LM Studio and llama.cpp serve an Anthropic-style API Claude Code can call, but Anthropic doesn't support non-Claude models.

[ fig. 01 — how-to ]48×5
[ fig. 01 — how-to ]16×5

Short answer

Claude Code can talk to a local model because Ollama, LM Studio and llama.cpp each serve an Anthropic Messages endpoint, and Claude Code lets you change its base URL. It works with two or three environment variables. It is not an Anthropic-supported setup: the Claude Code docs say Anthropic doesn't support routing Claude Code to non-Claude models through any gateway.

Anthropic support
None for non-Claude models
Protocol needed
Anthropic Messages (/v1/messages)
Ollama context advice
64,000+ tokens
LM Studio context advice
More than ~25k tokens

Key takeaways

  1. Ollama, LM Studio and llama.cpp document Claude Code setups. Anthropic's own docs say it doesn't support non-Claude models behind a gateway.
  2. The core setup is ANTHROPIC_BASE_URL plus ANTHROPIC_AUTH_TOKEN. The base URL alone leaves your saved claude.ai login active.
  3. Context is the first thing that breaks: Ollama defaults to 4k below 24 GiB VRAM and recommends at least 64,000 tokens for coding tools.
  4. Pick a model with tool calling. Qwen3-Coder, gpt-oss-20b and similar are used in vendor docs, but none of those docs publish a Claude Code quality comparison.
  5. If you only want a local coding agent, Aider, Cline, Continue and OpenCode are built around local models.

Yes, an Ollama Claude Code setup works. Ollama, LM Studio and llama.cpp each serve an Anthropic-style endpoint, and Claude Code lets you change its base URL, so a local model can sit behind it. Anthropic doesn’t support that, and the local model is the weak link. Here is what runs, what breaks and what developers report.

Claims below were checked against the linked docs on 2026-10-26. Local-model support in Claude Code changes fast, so re-check the version notes before you rely on a detail.

Does Claude Code support non-Anthropic or local models?

Not officially. Claude Code’s gateway documentation says any gateway that exposes a supported API format works, then adds: “Anthropic doesn’t endorse, maintain, or audit third-party gateway products, and doesn’t support routing Claude Code to non-Claude models through any gateway.” The mechanism exists, and the runtime vendors support their side of it. Anthropic does not.

What makes it possible is protocol, not intent. According to the gateway compatibility guide, Claude Code speaks three formats: Anthropic Messages (selected with ANTHROPIC_BASE_URL), Amazon Bedrock InvokeModel, and Google Cloud’s Agent Platform rawPredict. A server that implements Anthropic Messages at /v1/messages looks like the Claude API to Claude Code, which, per the same guide, “can’t tell which upstream you forward to.”

Three local runtimes now implement that endpoint:

RuntimeAnthropic endpointDocumented bySource date
OllamaMessages API with streaming, tool calling, vision, thinking blocksOllama docs, with a Claude Code pageDocs fetched 2026-10-26
LM StudioPOST /v1/messages, added in 0.4.1LM Studio docs and blogBlog dated 2026-01-30
llama.cpp (llama-server)/v1/messages and /v1/messages/count_tokensggml-org post on Hugging Face2026-01-19
[ fig. 01 — Request path for a local Claude Code setup. Ports are each runtime's documented default. ]
Claude Code sends Anthropic Messages requests to a base URL; Ollama, LM Studio and llama-server each answer at /v1/messages with a local model

Anything unofficial in this article is marked as such. Treat the whole local setup as unsupported by Anthropic and supported, to varying degrees, by the runtime.

How do you point Claude Code at Ollama, LM Studio or llama.cpp?

Set ANTHROPIC_BASE_URL to the local server and give Claude Code a placeholder credential. The Claude Code docs explain why you need the credential too: setting only the base URL “doesn’t replace the subscription”, so your saved claude.ai login stays the active credential. A token variable takes precedence over it.

Ollama. Per the Ollama Claude Code page, the manual setup is:

bash
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
claude --model qwen3.5

The same page documents ollama launch claude to start Claude Code against Ollama without exporting variables by hand, and says Claude settings can override your shell variables, so run /status to confirm the connection.

LM Studio. The LM Studio docs start the server on port 1234 (lms server start --port 1234) and set:

bash
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
export CLAUDE_CODE_ATTRIBUTION_HEADER=0
claude --model openai/gpt-oss-20b

If “Require Authentication” is on in LM Studio, put your LM Studio API token in ANTHROPIC_AUTH_TOKEN instead of the placeholder.

llama.cpp. The ggml-org post starts llama-server with a tool-capable GGUF and points Claude Code at http://127.0.0.1:8080. The post shows ANTHROPIC_BASE_URL alone, but a commenter there reports Claude Code still asked for a login until ANTHROPIC_AUTH_TOKEN and ANTHROPIC_MODEL were also set. A Hacker News commenter describes the same symptom with llama.cpp (comment, Jan 2026). That matches the Claude Code docs on credentials, so set the token. Another commenter reports that telemetry pings caused network failures in their setup and fixed it with CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 (comment); that is a single community report, so check the Claude Code docs for that variable before relying on it.

Two details apply to every runtime:

  • Don’t add /v1 to the base URL. Claude Code appends /v1/messages itself, and the compatibility guide lists that as the endpoint.
  • Verify before you trust it. Run /status and check that the Anthropic base URL line shows your local address and an Auth token line is present. The connect page describes both checks.

Do you need a translation proxy?

Only when your server does not speak one of Claude Code’s three formats. Ollama, LM Studio and llama.cpp now do, so for them no proxy is needed. A server that exposes only an OpenAI-style /v1/chat/completions endpoint has nothing Claude Code can call, and you would need a gateway in front that translates the two. Any such proxy is outside Anthropic’s support statement, and this article doesn’t cover specific proxy products because we haven’t verified them.

Which local models handle agentic tool calls?

One Hacker News commenter reports Qwen3-Coder 30B-A3B at Q8 with a 32k context, split across a 24 GB and a 16 GB GPU, running well behind Claude Code on Ollama (comment, Jan 2026); another found Devstral 24B and quantized Qwen3 30B-A3B fine for simple tasks but unreliable at tool use (comment, Dec 2025). So use a model that is explicitly trained or packaged for tool calling, and treat vendor claims as claims. Claude Code is a tool-calling loop: every file read, edit and shell command is a tool call, so a model that emits malformed calls fails visibly.

The runtime docs name a handful of models. None of them publish a Claude Code comparison, so this table records what each source actually says.

ModelNamed byWhat the source says
Qwen3-Coder (30B-A3B card: 30.5B total, 3.3B active, Apache-2.0)Ollama docs, llama.cpp postModel card: “excels in tool calling” and 256K native context. The card names Qwen Code and Cline, not Claude Code.
gpt-oss-20bLM Studio docsUsed as the Claude Code example model. No quality claim.
Qwen3-Next-80B-A3B-Instruct (GGUF Q4_K_M)llama.cpp postUsed as the example. The post says agentic work suits models like Nemotron, Qwen3 Coder, Kimi K2 or MiniMax M2.
Qwen3.5 (local); GLM and Kimi (cloud)Ollama Claude Code pageQwen3.5 is the manual-setup example. glm-5.3-flash and kimi-k2.7-code:cloud are cloud examples, so they aren’t local.

To compare tool-calling ability across models with numbers rather than model-card prose, the Berkeley Function Calling Leaderboard is the neutral reference. It measures function calling, including multi-turn use in V4. It doesn’t measure Claude Code sessions. For a coding-specific shortlist, see best local LLM for coding in 2026.

What breaks when the model is local?

A developer on an Apple M4 Max with 128 GB says local coding finally feels usable, but Claude Code’s large bootstrap context slows everything down, so they switched to a lighter agent (comment, Jul 2026). Another calls Claude Code on Ollama “doable, but not really viable” for larger tasks (comment, Jun 2026). Context length breaks first, then protocol gaps, then speed. Roughly in that order:

  1. Context window. Ollama’s context docs set defaults by VRAM: 4k under 24 GiB, 32k at 24 to 48 GiB, 256k at 48 GiB or more. They say agents and coding tools should run “at least 64000 tokens”, set with OLLAMA_CONTEXT_LENGTH=64000 ollama serve. The Ollama Claude Code page repeats the 64k advice. LM Studio is more modest, recommending more than about 25k. A 4k default under a tool-heavy agent loop will fail in confusing ways.
  2. Compaction doesn’t know your limit. For a model ID it doesn’t recognize, Claude Code assumes a 200k window (it warns “context assumed to be 200k tokens”). The gateway guide says to set CLAUDE_CODE_AUTO_COMPACT_WINDOW to the server’s limit, but values are clamped to at least 100,000 tokens. With a 64k local window you can’t match it, so /compact by hand becomes your recovery.
  3. Missing Anthropic features. Ollama’s compatibility page lists as unsupported: token counting, tool_choice, prompt caching via cache_control, the Batches API, citations and PDF blocks. Without a count endpoint, Claude Code falls back to a character-based estimate, so /context counts are approximate.
  4. Hosted features. The Ollama Claude Code page says hosted WebSearch and advanced tool controls are “not fully supported” with Ollama’s cloud endpoint. Claude Code’s own docs say Remote Control is disabled while ANTHROPIC_BASE_URL points at a non-Anthropic host.
  5. Prompt prefix and caching. LM Studio’s docs add CLAUDE_CODE_ATTRIBUTION_HEADER=0. Claude Code’s gateway guide explains the block it controls: from v2.1.181 it is stable within a conversation behind a custom base URL, and before that it changed every request and hurt prompt-cache reuse. On a current version you may not need the flag.
  6. Quality. There is no verified head-to-head number to quote here. Aider’s docs warn it “may not work well with less capable models”, and Anthropic states it doesn’t support non-Claude models. Test how your model handles tool calls on your own repository before relying on it. For a fuller comparison, see local LLM vs Claude for coding.
[ fig. 02 — Context numbers as stated in the Ollama, LM Studio and Claude Code docs, checked 2026-10-26. ]
Ollama defaults to 4k tokens under 24 GiB of VRAM but recommends at least 64k for coding tools, while Claude Code assumes a 200k window for unknown models

On speed: neither the runtime docs nor Claude Code’s docs publish tokens-per-second figures for this setup, so this article doesn’t either. Your hardware sets it. The runtime tradeoffs are covered in Ollama vs llama.cpp vs vLLM.

What do developers report in practice?

These are community reports from Hacker News, not our tests, and each is one person’s setup. Treat them as leads to check.

ReportSetup statedWhat they say
HN comment, Jan 2026Qwen3-Coder 30B-A3B at Q8, 32k context, split across a 24 GB and a 16 GB GPU (about 36 GB)Runs well behind Claude Code on Ollama
HN comment, Jan 2026llama.cpp, then ClineCould not get Claude Code working with llama.cpp; got better results in Cline with GLM-4.7-Flash than with Qwen3-Coder 30B
HN comment, Dec 2025Devstral 24B and Qwen3 30B-A3B, quantizedFine for simple tasks, but tool use often fails, especially on quantized versions, and bigger models are slower
HN comment, Jun 2026Ollama as the Claude Code backend“Doable, but not really viable”: slower, and larger tasks get notably worse with local models
HN comment, Jul 2026Apple M4 Max, 128 GBLocal coding finally feels usable, but Claude Code’s large bootstrap context slows everything down, so they use a lighter agent instead

The pattern across independent reports: hardware that fits a 30B-class coding model at 32k or more makes it work, tool-call reliability varies by model and quant, and Claude Code’s own prompt overhead is a cost on local hardware. Those reports back up the context and quality caveats above, but none of them is a benchmark.

What are the alternatives built for local models?

If the goal is a local coding agent rather than Claude Code specifically, tools designed around local models need less workaround. All four below have documented Ollama support.

ToolHow it connectsLocal-model notes from its docs
Aideraider --model ollama_chat/<model>Warns that Ollama’s 2k default context “silently” discards overflow; by default it sizes the window to each request plus 8k.
ClineOllama provider, base URL http://localhost:11434Recommends enabling “Use Compact Prompt” for local inference.
Continueprovider: ollama in model configCapabilities usually auto-detected; set capabilities to tool_use manually if tools don’t work.
OpenCode@ai-sdk/openai-compatible providerIf tool calls fail on Ollama, try raising num_ctx to 16k to 32k.

Notice what these have in common: each documents a context-window setting. That is the main failure mode for local agents regardless of the front end. For an editor-side setup, see self-hosted Copilot alternatives.

FAQ

Does Ollama officially support Claude Code?

Ollama documents it. Its docs include a Claude Code page, an Anthropic-compatible API and an ollama launch claude command. Anthropic does not support non-Claude models behind a gateway.

Why does Claude Code ask me to log in after I set ANTHROPIC_BASE_URL?

The base URL changes where requests go, not which credential is used. Set ANTHROPIC_AUTH_TOKEN (any placeholder works for Ollama or LM Studio without auth) so the token takes precedence over your saved login.

What context size should I use?

Ollama recommends at least 64,000 tokens for coding tools. LM Studio recommends more than about 25k. Both note that Claude Code consumes a lot of context.

Can I use llama.cpp instead of Ollama?

Yes. llama-server exposes /v1/messages and /v1/messages/count_tokens, and the ggml-org post shows Claude Code pointed at it. You need a GGUF model that supports tool calling.

Will a local model be as good as Claude inside Claude Code?

Don’t assume so. No source we checked publishes a like-for-like comparison, and Anthropic doesn’t support the setup. Test on your own repository before you depend on it.

Sources (10)
  1. Other LLM gateways, Claude Code docs
  2. Claude Code gateway compatibility guide, Claude Code docs
  3. Connect Claude Code to an LLM gateway, Claude Code docs
  4. Claude Code integration, Ollama docs
  5. Anthropic compatibility, Ollama docs
  6. Context length, Ollama docs
  7. Claude Code integration, LM Studio docs
  8. New in llama.cpp: Anthropic Messages API, Hugging Face blog (Jan 19, 2026)
  9. Community report: Qwen3-Coder 30B Q8 at 32k context on two GPUs behind Claude Code, Hacker News (Jan 2026)
  10. Community report: Claude Code on Ollama is doable but slower, Hacker News (Jun 2026)

Keep reading

[ fig. 02 — comparison ]18×8

Ollama vs llama.cpp vs vLLM: which should you use for local coding models?

Oct 29, 2026 · Comparison

Use Ollama if you are one developer who wants a local coding model running in a few commands. Use llama.cpp when you want direct control over GGUF files, quantization and server flags. Use vLLM when many people or agents share GPUs and you need batching. All three expose OpenAI-compatible endpoints, so your editor tooling rarely decides the choice; concurrency and hardware do.

Read
[ fig. 03 — comparison ]18×8

Is a local LLM for coding as good as Claude?

Oct 31, 2026 · Comparison

A local LLM is close to Claude on public coding benchmarks but not equal. Vendor-reported tables put the best open-weight models within a few points of the older Claude models they compare against, yet no independent run pits them against Claude Opus 5.5 on one harness. The biggest open models need datacenter hardware. A 27B model like Qwen3.8-27B fits one GPU, and developers report it works for small, well-scoped edits but not yet for long agent runs.

Read
[ fig. 04 — roundup ]18×8

What are the best self-hosted alternatives to GitHub Copilot?

Oct 31, 2026 · Roundup

For inline autocomplete on your own server, Tabby is the closest Copilot replacement, and llama.vscode is the lightest. For chat and agents against a local model, Cline and Aider are the main picks, and Continue is a risk because its repository is now read-only. All of them are open source, but only some are telemetry-free by default.

Read