Guides
How to use a local model with Claude Code
You can run Claude Code on a local model by pointing it at Ollama or LM Studio, which speak Anthropic's API. Or you can keep Claude in charge and give it a local model as a tool over MCP, for summaries, JSON and batch tasks. The first keeps the model on your computer. The second keeps Claude's quality.
What changed. New guide. It covers both setups, what still goes online in each, and the memory and measured speed of each model on a Mac.
There are two ways to use a local model with Claude Code, and they work differently. You can replace Claude's model with a local one, or add a local model as a tool. Most guides cover only the first. This one covers both, says what still goes online in each, and shows which Macs can run which models.
The two setups at a glance
| Replace Claude with a local model | Add a local model as a tool | |
|---|---|---|
| Who plans, edits code and runs commands | The local model | Claude (or your agent's usual model) |
| What the local model does | Everything | The tasks Claude sends it: summaries, classification, structured JSON, batches, file search |
| Tools you need | Ollama or LM Studio, with an Anthropic-compatible endpoint | An MCP server, such as Loci for Mac |
| Claude subscription or API key | Not needed for the model | Needed, as before |
| Quality on hard coding tasks | Limited by the local model | Claude's, for the parts Claude does |
| Memory you need | A lot: the model plus a long context | Less: a small model handles short tasks |
| Works offline | Yes, once the model is downloaded | No, Claude still runs in the cloud |
Pick "replace" when nothing may leave the machine, or you want to stop paying for a cloud model and accept a weaker one. Pick "add" when you want to keep Claude's quality and move repetitive, high-volume work onto your own computer.
Option 1: Run Claude Code on a local model
Claude Code talks to Anthropic's Messages API. It reads the address from the ANTHROPIC_BASE_URL environment variable, so any local server that speaks the same API can stand in for Claude. Ollama and LM Studio both do.
With Ollama
Ollama's own Claude Code guide gives a one-line start:
ollama launch claude
To set it up by hand, start Ollama, then set these in the shell you run Claude Code from, and name a model you have pulled:
export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
claude --model qwen3.5
Ollama's server listens on port 11434. Its guide asks for a model that supports tool calls and a context window of 64K tokens or more.
With LM Studio
LM Studio added an Anthropic-compatible endpoint in version 0.4.1, described in its Claude Code post. Start its server, then point Claude Code at it:
lms server start --port 1234
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
claude --model openai/gpt-oss-20b
LM Studio recommends a context of at least 25K tokens. The model name must match the one the server lists.
What every Option 1 guide agrees on
- Context is the hard part. Claude Code sends long instructions and tool definitions with every request, so short context windows fail. Set the context to the size the server's guide asks for before you judge a model.
- The model must handle tool calls. Claude Code works by calling tools. A model without reliable tool use will chat well but fail at editing files.
- It is slower. Each step of an agent task is a full round trip through the model, and prompt processing on a long context takes time on a laptop.
- It is weaker than Claude on hard tasks. A model that fits a laptop is far smaller. Expect it to handle routine edits and lose the thread on large refactors.
What still goes online. The model runs on your computer, but Claude Code itself can still make nonessential network calls, such as update checks and usage reporting. Anthropic documents settings to turn these off, including CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC. Tools that fetch web pages or search the web go online by design.
Option 2: Keep Claude, add a local model for routine tasks
Here Claude still plans the work, writes the code and decides what to run. A local model is one more tool it can call over MCP (the Model Context Protocol). Claude sends a task, the local model answers on your computer, and only the answer comes back.
This suits work that is repetitive, high-volume or private: summarizing a folder of logs, classifying 200 support tickets, pulling fields out of documents into JSON, or searching files Claude has not read. Claude does not have to read every file to get the answer, and it decides when a task is worth sending.
With Loci on a Mac. Loci for coding agents is a free Mac app that does this for Claude Code, Codex, Cursor, Gemini CLI and other MCP clients. You paste one prompt into your agent. It installs Loci with your approval, connects over MCP and checks which models are ready. The agent then gets tools to check models and speeds, generate an answer or validated JSON, run one instruction over up to 200 items, and download models. Newer versions add tools to summarize or extract from local files, search folders, and transcribe audio. The agents page lists every tool, worked examples with their scores, and the setup for each agent.
Two limits. The local model's inputs and answers become part of your agent's conversation, so they follow your agent service's data policy. And Loci is not a replacement backend for Claude Code: it offers MCP and an OpenAI-compatible chat endpoint, not Anthropic's Messages API. For Option 1, use Ollama or LM Studio.
Without Loci. Ollama and LM Studio both run a local server, and community MCP servers can connect an agent to it. That takes more setup, and you choose and size the model yourself.
Which Mac can run which model?
Memory decides what fits. These are the models in Loci's Mac catalog, with the download size and the least installed memory each one needs:
| Model | Download | Mac memory |
|---|---|---|
| LFM2.5 1.2B | 0.7 GB | 3 GB or more |
| Qwen3.5 2B | 1.3 GB | 4 GB or more |
| Bonsai 2 4B | 1.2 GB | 6 GB or more |
| Qwen3.5 4B | 2.7 GB | 6 GB or more |
| Gemma 4 E2B | 3.1 GB | 6 GB or more |
| Gemma 4 E4B | 5.0 GB | 12 GB or more |
| Qwen3.5 9B | 5.7 GB | 16 GB or more |
| Gemma 4 12B | 7.1 GB | 16 GB or more |
| Ternary Bonsai 2 27B | 7.2 GB | 24 GB or more |
| Qwen3.8 27B Max Quality | 29 GB | 64 GB or more |
Memory is the least installed RAM the Loci Mac catalog lists for each model, not a promise of fit. Catalog checked October 30, 2026.
These figures are for a normal chat. Option 1 needs more, because a 25K-64K context takes extra memory on top of the model. On a 16 GB Mac, leave a wide margin, or use Option 2, where a small model handles short tasks. Every size, by memory tier, is in the best local LLMs guide, and the local LLM on Mac page covers Mac setup.
How fast is a local model on a Mac?
Median speeds for the models Loci's Mac users run most, measured in real chats:
| Mac | Model | Median speed | Measured on |
|---|---|---|---|
| M5 Max Mac with 128 GB | Gemma 4 12B | 38 tok/s | 2 Macs |
| M5 Pro Mac with 48 GB | Gemma 4 26B A4B | 45 tok/s | 2 Macs |
| M2 Pro Mac with 32 GB | Gemma 4 12B | 18 tok/s | 2 Macs |
| M5 Pro Mac with 24 GB | Gemma 4 12B | 31 tok/s | 6 Macs |
| M4 Pro Mac with 24 GB | Gemma 4 12B | 25 tok/s | 2 Macs |
| M5 Mac with 24 GB | Gemma 4 12B | 15 tok/s | 2 Macs |
| M4 Mac with 16 GB | Qwen3.5 2B | 39 tok/s | 2 Macs |
| M5 Mac with 16 GB | Gemma 4 E4B | 33 tok/s | 2 Macs |
| M2 Mac with 8 GB | Qwen3.5 2B | 44 tok/s | 2 Macs |
| M1 Mac with 8 GB | Qwen3.5 2B | 27 tok/s | 2 Macs |
| M3 Mac with 8 GB | Qwen3.5 2B | 23 tok/s | 2 Macs |
Measured in Loci from October 10, 2026 to November 9, 2026; each row is the median across the Macs counted, with Loci's default settings. About 5 tokens per second keeps up with reading. An agent needs more, because it reads long prompts and makes many calls. The measured Mac speeds pages show every model measured on each Mac.
Codex, Cursor and other agents
The same two choices apply. Codex can run on a local model through Ollama or LM Studio; check its documentation for the current option. Cursor's agent is built around cloud models, so the simpler path is to add a local model as a tool. Any agent that supports MCP can use Option 2. To choose the local model app itself, compare Loci and Ollama or Loci and LM Studio.
FAQ
Can Claude Code run on a local model?
Yes. Set ANTHROPIC_BASE_URL to a local server that speaks Anthropic's Messages API, such as Ollama (port 11434) or LM Studio 0.4.1 or later (port 1234), and pass the local model's name. Use a model with reliable tool calls and a large context window.
Is Claude Code free with a local model?
The model is free to run, and Ollama's local runtime and LM Studio are free. You pay in hardware and speed: a model that fits a laptop is slower and weaker than Claude.
Which local model is best for Claude Code?
Choose one that supports tool calls and fits your memory with room for a long context. Ollama's guide uses Qwen3.5 as its example, and LM Studio's uses gpt-oss-20b. Try your own tasks before you commit.
How much memory do I need to run Claude Code locally?
More than for a chat, because the context is long. 16 GB runs small models with care. 32 GB or more gives room for mid-size models and a 64K context.
Can I keep Claude and still use a local model?
Yes. Connect a local model over MCP and Claude can send it tasks such as summaries, classification and JSON extraction. Loci does this on a Mac with one prompt.
Does a local model reduce my Claude usage?
It can. Work the local model does is not generated by Claude, and with file tools the full files stay out of Claude's context. The request and the answer still pass through Claude's conversation.
Does anything leave my computer with a local model?
With Option 1, the model runs locally, but Claude Code can still send nonessential traffic unless you turn it off. With Option 2, Claude runs in the cloud, so your conversation, including the local model's answers, goes to Anthropic as usual.
Get Loci
Private AI that keeps working.
Download Loci once, then chat without an account, chat upload, or signal.