Set it up with Ollama
Ollama added Anthropic API compatibility (/v1/messages) in version 0.14 and the ollama launch command in 0.15. The one-line setup from Ollama's Claude Code page:
ollama launch claude --model qwen3-coder-nextOr set it up by hand:
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3-coder-nextThe token is required but ignored by the local server. Values in Claude Code's settings files override shell variables, so check what's in use with /status.
Or with LM Studio
LM Studio also exposes an Anthropic-compatible endpoint (docs):
lms server start --port 1234
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
export CLAUDE_CODE_ATTRIBUTION_HEADER=0
claude --model openai/gpt-oss-20bLM Studio's guide asks for more than about 25K tokens of context.
Context: the setting that breaks it
Claude Code sends long prompts: instructions, tool definitions and file contents. Ollama's docs say coding tools need at least 64K tokens, but Ollama's default depends on memory: 4K under 24 GiB and 32K up to 48 GiB. Raise it in the Ollama app's settings or with OLLAMA_CONTEXT_LENGTH=65536 ollama serve, then check the CONTEXT column in ollama ps.
Which Mac and model
| Model | Memory at 64K | Mac mini M6 16GB | Mac mini M6 32GB | Mac mini M5 Pro 48GB | Mac mini M5 Pro 64GB | Mac Studio M5 Max 128GB |
|---|---|---|---|---|---|---|
| Qwen3-Coder-Next 80B-A3B (Q4_K_M) | ~75 GB | too tight | too tight | too tight | too tight | ~142 tok/s |
| Devstral Small 2 24B (Q4_K_M) | ~29 GB | too tight | too tight | ~15.3 tok/s | ~15.3 tok/s | ~30.7 tok/s |
| GLM-4.7-Flash 30B-A3B (Q4_K_M) | ~34 GB | too tight | too tight | ~72.7 tok/s | ~72.7 tok/s | ~145 tok/s |
| Qwen3 Coder 30B-A3B (Q4_K_M) | ~34 GB | too tight | too tight | ~67.2 tok/s | ~67.2 tok/s | ~134 tok/s |
| gpt-oss 20B (MXFP4) | ~27 GB | too tight | ~31.9 tok/s | ~57.6 tok/s | 61.0 tok/s | ~115 tok/s |
Agents write a lot of tokens per task, so speed matters more than in chat. See the best local LLM for coding for how these models compare.
What doesn't work
| Limit | Source |
|---|---|
| Not supported by Ollama: tool_choice, token counting, prompt caching, batches, citations, PDFs | Ollama docs: Anthropic compatibility |
| Anthropic doesn't support routing Claude Code to non-Claude models | Claude Code docs: LLM gateway |
| ANTHROPIC_BASE_URL changes where requests go, not which model answers | Claude Code docs: model configuration |
FAQ
Can I use Claude Code with a local model?
How do I use Claude Code with Ollama?
Which Mac do I need for Claude Code with a local model?
Does Anthropic support local models in Claude Code?
See any model on the exact Mac you're considering.
- Ollama: Claude Code integration
- Ollama: Anthropic compatibility
- Ollama: context length
- Ollama v0.14.0 release notes
- Ollama v0.15.0 release notes
- LM Studio: Claude Code
- Claude Code docs: LLM gateway
- Claude Code docs: model configuration
Speeds come from published measurements (with source links) or labeled estimates. How we measure