Run a powerful coding LLM on your own machine — then use it from Claude Code (Amp CLI)
qwen3-coder (Qwen3-Coder 30B-class MoE, ~3B active params) as the current local coding model; Qwen 2.5 Coder 14B remains a valid lighter fallback./v1/messages endpoint (Ollama since Jan 2026, LM Studio since 0.4.1). Claude Code talks to it directly — no custom-openai provider or translation proxy is needed anymore.ANTHROPIC_BASE_URL must be the bare host:port (e.g. http://localhost:11434), not .../v1. Claude Code appends the path itself. The previous guide's http://localhost:11434 (root; + /v1/messages) was wrong.ANTHROPIC_AUTH_TOKEN (not just ANTHROPIC_API_KEY) and map Claude Code's internal sonnet/haiku/opus tiers to your local model with ANTHROPIC_DEFAULT_SONNET_MODEL / ANTHROPIC_DEFAULT_HAIKU_MODEL / ANTHROPIC_DEFAULT_OPUS_MODEL. Without these, Claude Code requests claude-sonnet-... and the local server rejects it.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 to strip Anthropic-specific beta headers that local servers reject.apiProvider: "custom-openai" / customApiBaseUrl schema with the current {"env": {...}} block.Use ← → arrow keys or swipe to navigate • 13 slides
Before you start, make sure you have:
You need software that hosts Qwen locally and exposes an Anthropic-compatible /v1/messages API (the native protocol Claude Code speaks). Both options below now support it natively — no translation proxy needed:
GUI app, model browser, easy quantisation picks. Great for beginners.
This guide covers both paths. Pick one and follow the matching steps.
ollama pull qwen3-coder
Prefer the lighter, older Qwen 2.5 Coder 14B (smaller VRAM footprint)?
ollama pull qwen2.5-coder:14b
This downloads the Q4_K_M quantised weights (~9 GB). For the full-precision variant:
ollama pull qwen2.5-coder:14b-instruct-fp16
ollama run qwen3-coder "Write hello world in Python"
ollama serve
http://localhost:11434 — it now exposes a native Anthropic-compatible /v1/messages endpoint (added Jan 2026), so Claude Code talks to it directly.qwen3-coder (or Qwen2.5-Coder-14B-Instruct for the lighter fallback)http://localhost:1234 — since v0.4.1 it exposes a native Anthropic-compatible /v1/messages endpoint, so Claude Code connects with no proxy. Set context size to ≥ 25K tokens (LM Studio's recommendation) for best results.Claude Code talks to local servers using the Anthropic Messages API (/v1/messages), not the OpenAI chat endpoint. Confirm your server exposes it:
For Ollama (port 11434):
curl http://localhost:11434/v1/messages \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "qwen3-coder",
"max_tokens": 256,
"messages": [{"role":"user","content":"Say hello"}]
}'
For LM Studio (port 1234):
curl http://localhost:1234/v1/messages \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "qwen3-coder",
"max_tokens": 256,
"messages": [{"role":"user","content":"Say hello"}]
}'
On Windows PowerShell, use Invoke-RestMethod or install curl via curl.se.
"content" array (Anthropic shape) - you're good! A "choices" array means you hit the OpenAI endpoint by mistake.Point Claude Code at your local server's root URL (do not append /v1 - Claude Code adds the path itself). Set these before launching:
Linux / macOS (bash/zsh) - Ollama:
# For Ollama
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_MODEL=qwen3-coder
export ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3-coder
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3-coder
export ANTHROPIC_DEFAULT_OPUS_MODEL=qwen3-coder
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
claude
Linux / macOS - LM Studio:
# For LM Studio
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lm-studio
export ANTHROPIC_MODEL=qwen3-coder
export ANTHROPIC_DEFAULT_SONNET_MODEL=qwen3-coder
export ANTHROPIC_DEFAULT_HAIKU_MODEL=qwen3-coder
export ANTHROPIC_DEFAULT_OPUS_MODEL=qwen3-coder
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
claude
Windows PowerShell - Ollama:
$env:ANTHROPIC_BASE_URL = "http://localhost:11434" $env:ANTHROPIC_AUTH_TOKEN = "ollama" $env:ANTHROPIC_MODEL = "qwen3-coder" $env:ANTHROPIC_DEFAULT_SONNET_MODEL = "qwen3-coder" $env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "qwen3-coder" $env:ANTHROPIC_DEFAULT_OPUS_MODEL = "qwen3-coder" $env:CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS = "1" claude
Qwen 2.5 fallback: set ANTHROPIC_MODEL=qwen2.5-coder:14b (Ollama) or qwen2.5-coder-14b-instruct (LM Studio).
Why the tier vars? Claude Code internally requests claude-sonnet-... / claude-haiku-... / claude-opus-.... Mapping all three to your local tag prevents "model not found" rejections. CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 strips Anthropic beta headers local servers do not understand.
ANTHROPIC_API_KEY as an alias; ANTHROPIC_AUTH_TOKEN is the documented name for custom endpoints.Environment variables reset when you close the terminal. Persist them so you don't re-export every session:
Linux / macOS - add to ~/.bashrc or ~/.zshrc:
export ANTHROPIC_BASE_URL=http://localhost:11434 export ANTHROPIC_AUTH_TOKEN=ollama export ANTHROPIC_MODEL=qwen3-coder
Windows PowerShell - set user-level variables (survives new shells):
[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL","http://localhost:11434","User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN","ollama","User")
[Environment]::SetEnvironmentVariable("ANTHROPIC_MODEL","qwen3-coder","User")
To switch back to Anthropic's cloud, just unset the variables (Remove-Item Env:ANTHROPIC_BASE_URL on PowerShell, or unset ANTHROPIC_BASE_URL on bash) and relaunch claude.
"apiProvider": "custom-openai" settings.json schema - it targeted the OpenAI chat endpoint and is not the native path for current Claude Code. Use environment variables with the Anthropic-compatible endpoint instead.With your local server running and config in place, just start Claude Code normally:
claude
You should see it connect. Try a prompt:
You: Explain what a decorator is in Python, with an example. Qwen3-Coder: A decorator is a function that takes another function as an argument and extends its behavior without modifying it...
OLLAMA_NUM_GPU=999 to offload all layers to GPUollama run qwen3-coder --num-ctx 32768Or in LM Studio: Settings → Context Length → 8192
Q4_K_M — best balance (speed + quality)Q5_K_M — slightly better quality, needs more VRAMfp16 — full precision, needs ~28 GB VRAM| Problem | Solution |
Connection refused | Make sure ollama serve or LM Studio server is running |
Model not found | Check model name matches exactly — run ollama list |
| Very slow responses | Ensure GPU offload is enabled; reduce context length |
| Out of memory | Use a smaller quant (Q4_K_M) or reduce num_ctx |
404 / not found | You appended /v1 to ANTHROPIC_BASE_URL. Use the server root (e.g. http://localhost:11434); Claude Code adds /v1/messages itself. |
| Auth / API key error | Set ANTHROPIC_AUTH_TOKEN (or ANTHROPIC_API_KEY) to any non-empty string |
| Item | Value |
| Ollama API URL | http://localhost:11434/v1 |
| LM Studio API URL | http://localhost:1234 (root; + /v1/messages) |
| Model name (Ollama) | qwen3-coder (fallback: qwen2.5-coder:14b) |
| Model name (LM Studio) | qwen2.5-coder-14b-instruct |
| RAM needed | ~10 GB VRAM or ~12 GB system RAM |
| Disk space | ~9 GB (Q4_K_M) |
Recap — the 4 key steps:
Now you have a fully local, private, zero-cost coding AI running through the Claude Code interface.