Claude Code (local backend) with a local model: setup for Ollama or LM Studio

Claude Code is Anthropic's proprietary terminal coding agent; pointed at a local server's Anthropic-compatible API, it runs against open-weight models. Ollama and LM Studio both document this setup, and it suits people already using Claude Code who have the memory for a 64k+ context.

At a glance

Type
cli
Licence
Proprietary
Latest release
2.1.303 (2026-10-18)
Status
Maintained
Local backends
ollama, lmstudio, anthropic-compatible
Needs native tool calling
Yes
MCP support
Yes
Recommended minimum context
64,000 tokens
Start-up prompt
~33,000 tokens (single third-party measurement)
GitHub stars
Not verified

How to set it up with a local model

Pick your backend. Each command has its own Copy button. Where a step uses an example model, swap in the one you run; the table below lists the ones that fit your machine.

  1. Install it (macOS / Linux):

    curl -fsSL https://claude.ai/install.sh | bash
  2. Start Ollama with a 64k context window (or set the context slider in the Ollama app's settings).

    OLLAMA_CONTEXT_LENGTH=64000 ollama serve
  3. In a second terminal, pull a tool-capable coding model (replace qwen3-coder:30b with any model you prefer).

    ollama pull qwen3-coder:30b
  4. Quickest path: let Ollama configure and launch Claude Code.

    ollama launch claude
  5. Or point Claude Code at Ollama's Anthropic-compatible API yourself.

    export ANTHROPIC_AUTH_TOKEN=ollama
    export ANTHROPIC_API_KEY=""
    export ANTHROPIC_BASE_URL=http://localhost:11434
  6. Tell Claude Code the real context window, since it assumes 200K for model IDs it doesn't recognize.

    export CLAUDE_CODE_MAX_CONTEXT_TOKENS=64000
  7. Run Claude Code with your local model.

    claude --model qwen3-coder:30b
Other ways to install

Windows (PowerShell)

irm https://claude.ai/install.ps1 | iex

Check that it works

Inside Claude Code, run /status to check which base URL and credentials are active.

/status

Which local models fit, by machine

Checked by this site's engine at the context Claude Code needs, with 32 GB of system RAM for MoE offload. A Mac counts three quarters of unified memory as usable.

MachineModelQuantContextFitOllama
12 GB GPUQwen 3.5 9BQ4_K_M64,000Comfortable (8.4 GB of 12 GB)qwen3.5:9b
Qwen 3.6 35B-A3BQ4_K_M64,000With CPU offload (MoE) (23.3 GB of 12 GB)qwen3.6:35b-a3b
16 GB GPUQwen 3.5 9BQ4_K_M64,000Comfortable (8.4 GB of 16 GB)qwen3.5:9b
Qwen 3.6 35B-A3BQ4_K_M64,000With CPU offload (MoE) (23.3 GB of 16 GB)qwen3.6:35b-a3b
24 GB GPUQwen3.8 27BQ4_K_M64,000Tight (21.9 GB of 24 GB)qwen3.8:27b
Qwen 3.6 27BQ4_K_M64,000Tight (21.9 GB of 24 GB)qwen3.6:27b
Qwen 3.6 35B-A3BQ4_K_M65,536Tight (23.3 GB of 24 GB)qwen3.6:35b-a3b
32 GB GPUQwen3.8 27BQ4_K_M64,000Comfortable (21.9 GB of 32 GB)qwen3.8:27b
Qwen 3.6 27BQ4_K_M64,000Comfortable (21.9 GB of 32 GB)qwen3.6:27b
Qwen 3.6 35B-A3BQ4_K_M65,536Comfortable (23.3 GB of 32 GB)qwen3.6:35b-a3b
Qwen3-Coder 30B-A3B (MoE)Q4_K_M65,536Comfortable (25.7 GB of 32 GB)qwen3-coder:30b
Devstral Small 2 24BQ4_K_M64,000Comfortable (25.8 GB of 32 GB)devstral-small-2:24b
Mac, 64 GBQwen 3.6 35B-A3BQ8_0131,072Comfortable (40.7 GB of 48 GB)—

Your exact machine: filter the matrix or check any model in the analyzer.

Common problems with local models

  • Ollama recommends a 64k+ context window for Claude Code; LM Studio says more than ~25k. Claude Code's system prompt alone is large, so stay at 64k where you can.
  • Ollama's Anthropic-compatible API does not support tool_choice or prompt caching (cache_control).
  • Claude settings files can override shell variables; if the connection goes elsewhere, update the base URL or credentials there and re-check with /status.
  • If LM Studio's Require Authentication is on, set ANTHROPIC_AUTH_TOKEN to your LM Studio API token instead of lmstudio.

Other coding agents

How they rank for local models: the best agent harness for local LLMs.

Sources (7), checked 2026-10-20