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.
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.
- None for non-Claude models
- Anthropic Messages (/v1/messages)
- 64,000+ tokens
- More than ~25k tokens
Key takeaways
- 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.
- The core setup is ANTHROPIC_BASE_URL plus ANTHROPIC_AUTH_TOKEN. The base URL alone leaves your saved claude.ai login active.
- 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.
- 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.
- 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:
| Runtime | Anthropic endpoint | Documented by | Source date |
|---|---|---|---|
| Ollama | Messages API with streaming, tool calling, vision, thinking blocks | Ollama docs, with a Claude Code page | Docs fetched 2026-10-26 |
| LM Studio | POST /v1/messages, added in 0.4.1 | LM Studio docs and blog | Blog dated 2026-01-30 |
llama.cpp (llama-server) | /v1/messages and /v1/messages/count_tokens | ggml-org post on Hugging Face | 2026-01-19 |
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:
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
claude --model qwen3.5The 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:
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
export CLAUDE_CODE_ATTRIBUTION_HEADER=0
claude --model openai/gpt-oss-20bIf “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
/v1to the base URL. Claude Code appends/v1/messagesitself, and the compatibility guide lists that as the endpoint. - Verify before you trust it. Run
/statusand check that theAnthropic base URLline shows your local address and anAuth tokenline 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.
We build CandorNo GPU? Use a hosted model
Uncensored AI, right in your browser.
Candor runs open models with refusals removed, so it answers the questions other assistants deflect. New accounts get free credits, no card needed.
Try Candor freeWhich 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.
| Model | Named by | What the source says |
|---|---|---|
| Qwen3-Coder (30B-A3B card: 30.5B total, 3.3B active, Apache-2.0) | Ollama docs, llama.cpp post | Model card: “excels in tool calling” and 256K native context. The card names Qwen Code and Cline, not Claude Code. |
| gpt-oss-20b | LM Studio docs | Used as the Claude Code example model. No quality claim. |
| Qwen3-Next-80B-A3B-Instruct (GGUF Q4_K_M) | llama.cpp post | Used 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 page | Qwen3.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:
- 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. - 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_WINDOWto 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/compactby hand becomes your recovery. - Missing Anthropic features. Ollama’s compatibility page lists as unsupported: token counting,
tool_choice, prompt caching viacache_control, the Batches API, citations and PDF blocks. Without a count endpoint, Claude Code falls back to a character-based estimate, so/contextcounts are approximate. - 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_URLpoints at a non-Anthropic host. - 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. - 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.
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.
| Report | Setup stated | What they say |
|---|---|---|
| HN comment, Jan 2026 | Qwen3-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 2026 | llama.cpp, then Cline | Could 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 2025 | Devstral 24B and Qwen3 30B-A3B, quantized | Fine for simple tasks, but tool use often fails, especially on quantized versions, and bigger models are slower |
| HN comment, Jun 2026 | Ollama as the Claude Code backend | “Doable, but not really viable”: slower, and larger tasks get notably worse with local models |
| HN comment, Jul 2026 | Apple M4 Max, 128 GB | Local 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.
| Tool | How it connects | Local-model notes from its docs |
|---|---|---|
| Aider | aider --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. |
| Cline | Ollama provider, base URL http://localhost:11434 | Recommends enabling “Use Compact Prompt” for local inference. |
| Continue | provider: ollama in model config | Capabilities usually auto-detected; set capabilities to tool_use manually if tools don’t work. |
| OpenCode | @ai-sdk/openai-compatible provider | If 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.
We build CandorSkip the setup
Want an uncensored model without hosting one?
Candor (candorai.dev) is an uncensored AI chat app that runs in your browser: it answers the questions mainstream assistants dodge, on health, money, law and work, without the lecture. New accounts get free credits, no card needed.
Facts from candorai.dev, checked Nov 10, 2026. Candor never changes how we rank or review models. Disclosure.
Sources (10)
- Other LLM gateways, Claude Code docs
- Claude Code gateway compatibility guide, Claude Code docs
- Connect Claude Code to an LLM gateway, Claude Code docs
- Claude Code integration, Ollama docs
- Anthropic compatibility, Ollama docs
- Context length, Ollama docs
- Claude Code integration, LM Studio docs
- New in llama.cpp: Anthropic Messages API, Hugging Face blog (Jan 19, 2026)
- Community report: Qwen3-Coder 30B Q8 at 32k context on two GPUs behind Claude Code, Hacker News (Jan 2026)
- Community report: Claude Code on Ollama is doable but slower, Hacker News (Jun 2026)
Written by Refusal Rate editors from papers, model cards, official docs and pricing pages. Anything we ran ourselves is labeled as our own test, with the hardware and settings. Our method.