Step-by-Step Guide

Connect Claude Code
to a Local Qwen Coder Model

Run a powerful coding LLM on your own machine — then use it from Claude Code (Amp CLI)

Qwen3-Coder (current) / Qwen 2.5 Coder (fallback) Ollama / LM Studio Claude Code / Amp 100 % Local
Updated July 27, 2026 — setup method rewritten (click to expand what changed)
  • Model: Recommend 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.
  • API protocol (important fix): Both Ollama and LM Studio now expose a native Anthropic-compatible /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.
  • Base URL fix: 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.
  • Auth + tier mapping: Use 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.
  • Beta-header fix: Set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 to strip Anthropic-specific beta headers that local servers reject.
  • settings.json: Replaced the obsolete apiProvider: "custom-openai" / customApiBaseUrl schema with the current {"env": {...}} block.
  • Not changed: Prerequisites (Node.js 18+, GPU/RAM guidance), Ollama/LM Studio install steps, performance tuning, and troubleshooting structure. Hardware numbers are vendor guidance, not independently benchmarked here.

Use ← → arrow keys or swipe to navigate  •  13 slides

1 Prerequisites

Before you start, make sure you have:

  • 16 GB+ RAM (the 14B model needs ~10 GB VRAM or ~12 GB system RAM (varies by model size/quant; vendor guidance) with CPU offload)
  • NVIDIA GPU with ≥ 12 GB VRAM recommended (RTX 3060 12 GB+, RTX 4060 Ti 16 GB, etc.) — CPU-only works but is slower
  • ~15 GB free disk space for model weights
  • Node.js 18+nodejs.org (or use Claude Code's native installer; Node is only needed for the npm install path)
  • Claude Code (or Amp CLI) installed — Claude Code docs
💡 Don't have a beefy GPU? Use the Q4_K_M quantised variant — it runs well on 8 GB VRAM.

2 Choose a Local Model Server

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:

🦙 Ollama

CLI-first, lightweight, auto-downloads models. Great for devs.

⬇ Download Ollama

🖥️ LM Studio

GUI app, model browser, easy quantisation picks. Great for beginners.

⬇ Download LM Studio

This guide covers both paths. Pick one and follow the matching steps.

3a Path A — Install & Run with Ollama

  1. Download & install from ollama.com/download
  2. Open a terminal and pull the model. Qwen3-Coder is the current recommendation (30B-class MoE, ~3B active params, strong on agentic coding):
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
  1. Verify it works — run a quick chat (use whichever tag you pulled):
ollama run qwen3-coder "Write hello world in Python"
  1. Start the Ollama server (it usually auto-starts, but to be sure):
ollama serve
✅ Ollama's API is live at http://localhost:11434 — it now exposes a native Anthropic-compatible /v1/messages endpoint (added Jan 2026), so Claude Code talks to it directly.

3b Path B — Install & Run with LM Studio

  1. Download & install from lmstudio.ai
  2. Open LM Studio → click Search → type qwen3-coder (or Qwen2.5-Coder-14B-Instruct for the lighter fallback)
  3. Pick a quantisation (recommended: Q4_K_M for balanced speed/quality)
  4. Click Download, wait for it to finish
  5. Go to the Local Server tab (left sidebar, server icon)
  6. Select the downloaded Qwen model from the dropdown
  7. Click Start Server
✅ LM Studio's API is live at 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.

4 Verify the Local API Works

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.

? If you get a JSON response with a "content" array (Anthropic shape) - you're good! A "choices" array means you hit the OpenAI endpoint by mistake.

5 Configure Claude Code to Use Your Local Model

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.

?? The auth token can be any non-empty string - local servers don't validate it, but Claude Code requires it. Some builds accept ANTHROPIC_API_KEY as an alias; ANTHROPIC_AUTH_TOKEN is the documented name for custom endpoints.

6 Make the Configuration Persistent

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.

?? Avoid the old "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.

?? Full Claude Code settings reference

7 Launch Claude Code

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...
    
✅ If you see responses — congratulations, you're running a fully local coding LLM through Claude Code!

8 Performance Tuning Tips

  • GPU layers: In Ollama, set OLLAMA_NUM_GPU=999 to offload all layers to GPU
  • Context window: Default is small. Raise it for code tasks (Qwen3-Coder supports a long context):
    ollama run qwen3-coder --num-ctx 32768
    Or in LM Studio: Settings → Context Length → 8192
  • Quantisation trade-offs (vendor guidance; not independently benchmarked here):
    • Q4_K_M — best balance (speed + quality)
    • Q5_K_M — slightly better quality, needs more VRAM
    • fp16 — full precision, needs ~28 GB VRAM
  • Batch size: If using CPU, increase batch size for faster prompt processing

📖 Ollama Modelfile options  |  Qwen Coder GitHub

9 Troubleshooting

ProblemSolution
Connection refusedMake sure ollama serve or LM Studio server is running
Model not foundCheck model name matches exactly — run ollama list
Very slow responsesEnsure GPU offload is enabled; reduce context length
Out of memoryUse a smaller quant (Q4_K_M) or reduce num_ctx
404 / not foundYou appended /v1 to ANTHROPIC_BASE_URL. Use the server root (e.g. http://localhost:11434); Claude Code adds /v1/messages itself.
Auth / API key errorSet ANTHROPIC_AUTH_TOKEN (or ANTHROPIC_API_KEY) to any non-empty string
⚠️ Qwen3-Coder / Qwen 2.5 Coder are strong at code, but local models may not support all Claude-specific features (agentic tool use, long agentic loops, artifacts). Tool-call reliability varies by server and quant.

10 Quick Reference Card

ItemValue
Ollama API URLhttp://localhost:11434/v1
LM Studio API URLhttp://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)
Ollama Model Page ↗ Qwen GitHub ↗ Claude Code Docs ↗ LM Studio ↗ HuggingFace Model ↗

🎉 You're All Set!

Recap — the 4 key steps:

  1. Install Ollama or LM Studio
  2. Download Qwen3-Coder (or Qwen 2.5 Coder 14B)
  3. Start the local API server
  4. Configure Claude Code via env vars (root URL + auth token)

Now you have a fully local, private, zero-cost coding AI running through the Claude Code interface.

Qwen GitHub ↗ Ollama ↗ LM Studio ↗