Claude in a hard hat points at a blueprint while the Atomic Agent mascot builds a toy house at a home desk next to a glowing desktop computer
Guide

How to Use Claude Code with a Local LLM (and When to Keep Claude in the Loop)

Published
Reading time
10 min read
Tag

Point Claude Code at a local LLM with Ollama, llama.cpp, LM Studio or vLLM: exact env vars, the limits you will hit, and a hybrid setup that keeps a cloud model.

You can run Claude Code against a local LLM by pointing ANTHROPIC_BASE_URL at a local server that speaks the Anthropic Messages API. Ollama, llama.cpp, LM Studio and vLLM all do this natively today, so for most setups no proxy is needed. The catch is the model: Claude Code was built around Claude, and a model that fits on one consumer GPU is weaker, slower and shorter on context.

This guide covers the exact setup for each server, checked against each project’s documentation on November 13, 2026, then the limits you will hit and a hybrid pattern that keeps a strong cloud model in the loop.

How does Claude Code connect to a local model?

Claude Code sends every model request to the address in ANTHROPIC_BASE_URL, using the Anthropic Messages format. Any server that answers at /v1/messages in that format can stand in for Anthropic’s API.

The Claude Code gateway docs list the variables:

VariableWhat it does
ANTHROPIC_BASE_URLWhere requests go. Use the server root (http://localhost:11434), because Claude Code appends /v1/messages itself
ANTHROPIC_AUTH_TOKENCredential sent as Authorization: Bearer. Local servers accept a placeholder
ANTHROPIC_API_KEYCredential sent as x-api-key. Set it to an empty string if you use the token instead
ANTHROPIC_DEFAULT_OPUS_MODEL, _SONNET_MODEL, _HAIKU_MODELWhat the opus, sonnet and haiku aliases resolve to, so every tier can map to your local model
--model flag or ANTHROPIC_MODELThe model for this session

Two details matter for local use. First, the gateway overview says that setting only the base URL does not replace your claude.ai login: “a saved claude.ai login remains the active credential, so its usage limits and billing apply.” Set a credential variable as well. Second, you can put these values in the env block of ~/.claude/settings.json instead of your shell, and a settings-file value wins over a shell export. Run /status inside Claude Code to see which base URL and credential it is actually using.

Which local servers work with Claude Code?

Four popular local servers speak the Anthropic Messages API natively. Two proxies cover everything else.

ServerAnthropic endpointDefault addressNotes from its docs
OllamaNative, plus ollama launch claudehttp://localhost:11434”Choose a model and set a 64k+ context window”
llama.cpp llama-serverNative since January 2026http://127.0.0.1:8080Tool use, streaming and count_tokens
LM StudioNative since 0.4.1http://localhost:1234Use “more than ~25k context length”
vLLMNativehttp://localhost:8000Start with tool calling enabled
LiteLLMProxyyour proxyMaps Claude Code’s tiers to other providers
claude-code-routerProxyhttp://127.0.0.1:3456 (UI on 3458)Rule-based routing and fallback models

Ollama

The shortest path. With Ollama installed, its Claude Code guide gives one command:

Terminal window
ollama launch claude

The manual setup from the same page:

Terminal window
export ANTHROPIC_AUTH_TOKEN=ollama
export ANTHROPIC_API_KEY=""
export ANTHROPIC_BASE_URL=http://localhost:11434
claude --model qwen3.5

Swap qwen3.5 for any local model you have pulled that supports tools. Ollama’s compatibility page says it covers “a subset of the Anthropic Messages API”: tool calling, streaming, thinking and base64 images work, while count_tokens, prompt caching (cache_control), PDFs and tool_choice do not.

llama.cpp (llama-server)

llama.cpp added the Anthropic Messages API to llama-server in January 2026, with Claude Code compatibility as an explicit goal. The announcement shows this pair:

Terminal window
llama-server -hf unsloth/Qwen3-Next-80B-A3B-Instruct-GGUF:Q4_K_M
ANTHROPIC_BASE_URL=http://127.0.0.1:8080 claude

Replace the model with one that fits your hardware, and set the context size with -c (for example -c 65536), because by default llama-server loads the model’s full trained context, which may not fit in memory. If you start llama-server with --api-key, set the same value in ANTHROPIC_AUTH_TOKEN.

LM Studio

LM Studio’s integration page starts the server and sets three variables:

Terminal window
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-20b

If Require Authentication is on in LM Studio, put your LM Studio API token in ANTHROPIC_AUTH_TOKEN.

vLLM

vLLM’s Claude Code page is the best template for mapping every Claude tier to one local model:

Terminal window
vllm serve openai/gpt-oss-120b --served-model-name my-model \
--enable-auto-tool-choice --tool-call-parser openai
ANTHROPIC_BASE_URL=http://localhost:8000 \
ANTHROPIC_API_KEY=dummy \
ANTHROPIC_AUTH_TOKEN=dummy \
ANTHROPIC_DEFAULT_OPUS_MODEL=my-model \
ANTHROPIC_DEFAULT_SONNET_MODEL=my-model \
ANTHROPIC_DEFAULT_HAIKU_MODEL=my-model \
claude

The same page explains why CLAUDE_CODE_ATTRIBUTION_HEADER=0 keeps showing up: Claude Code adds a per-request hash to the system prompt, which can defeat prefix caching and slow a local server down a lot. vLLM handles this itself after version 0.17.1. On other servers, setting the variable is cheap insurance.

When you need a proxy

Use LiteLLM or claude-code-router when your server only speaks the OpenAI format, or when you want routing rules, such as sending one model name to a small local model and another to a bigger one, with fallbacks. Both add a moving part that has to keep up with Claude Code’s request format, so skip them when one of the native servers above already covers your case.

What are the limits of running Claude Code on a local LLM?

Expect a working setup, with a weaker model inside it. A local model on consumer hardware falls behind Claude on long agentic coding, context size, tool-calling reliability and speed, and Claude Code does nothing to hide those gaps.

The fixed prompt is large. Claude Code sends a long system prompt and dozens of tool schemas with every request. MCP servers and memory files add more. Anthropic does not publish the size. In a field test against llama-server on a 6 GB laptop, KUN measured the first request at about 15,800 prompt tokens, which took 48.8 seconds to process and used half of a 32K window. Automatic compaction then failed in 2 of 3 runs. Run /context in a session to see your own breakdown. On a model with a 32K window, little is left for your code.

Compaction is tuned for big windows. Claude Code’s docs note that CLAUDE_CODE_AUTO_COMPACT_WINDOW is clamped to at least 100,000 tokens. On a local model with a 64K window, plan to run /compact yourself before the context fills up.

Tool calls fail more often. Every edit, read and shell command is a structured tool call. Smaller and heavily quantized models get the format or the arguments wrong more often over a long session, and Ollama does not support tool_choice, so a client cannot force a specific tool.

It is slow. In our own agent runs (Atomic Agent, not Claude Code) of a 27B model at 4-bit on a 32 GB Mac, two multi-step tasks took 202 and 421 seconds, so a long Claude Code session on that hardware will be slow.

Some features switch off. While a credential variable or a non-Anthropic base URL is set, Remote Control and voice dictation are unavailable, the fast mode and WebFetch domain checks still call api.anthropic.com, and /feedback saves a local file instead of sending it.

None of this makes the setup useless. Bounded jobs (rename across a module, write tests for a known function, explain a file, run and fix a script) suit a local model well. Open-ended work across a large codebase is where it falls apart.

Which local model should you use with Claude Code?

Pick a model that supports tool calling and still leaves room for a 64K context after it loads. On a single GPU with about 24 GB of memory, a 27B-class model at 4-bit is the practical starting point in our own agent tests.

The numbers behind that guidance are in our Qwen 3.8 27B local agent guide. Per the official model card, it is a dense 27B model with a 262,144-token context and an Apache 2.0 license. The 4-bit file is about 17 GB, which leaves headroom on a 24 GB card for the KV cache that Claude Code’s long prompt needs. On Apple Silicon, the same sizes apply to unified memory, and 32 GB gives you slack.

Smaller models in the 4B to 8B range run on 8 to 16 GB, but between the fixed prompt and the shorter context they spend most of their window on Claude Code itself. Thinking modes cost time on every tool call, so if your model has a switch for thinking, try it off for routine edits.

How do you keep Claude in the loop with local models?

Split the work by role. A strong cloud model plans the job and reviews the result, while a local model does the bulk of the reading and writing. The reverse also works: a local model plans, and cloud models write the large outputs.

The split works because the two halves of a coding task need different things. Planning and review depend on judgment, which is where a frontier model earns its price. Execution is mostly mechanical once the brief is clear, which is where a local model is often good enough. Review rounds can still use a lot of cloud tokens, so cap the spend. Done by hand, this means running Claude Code for the plan, then pasting briefs into a second agent on a local model and checking its output yourself.

Claude Code can give plan mode and subagents their own model (the opusplan alias, a subagent’s model field), but every request goes to one base URL, so mixing a cloud Claude with a local model still needs a router that sends each model name to the right backend.

Fusion: the hybrid pattern built into Atomic Agent

Atomic Agent is an open-source, local-first agent (desktop app and terminal), and its Fusion run mode is a ready-made version of this split. An orchestrator model plans, writes a brief for each part and reviews the results. The orchestrator splits the job into up to 16 parts per fan-out and decides how many run at once: cloud workers run several in parallel, local workers share the machine’s request slots. Each worker runs one part in a throwaway session and writes files straight to disk.

During a Fusion turn the orchestrator cannot change your files or run shell commands in your project. It checks the workers’ output with verify.syntax and verify.run, which runs tests or opens the page in a throwaway copy of the folder, and sends weak parts out again with a more specific brief. The Fusion docs cover the settings, and our guide to multi-agent orchestration for coding walks through the pattern with measured runs.

DirectionWho plansWho buildsFits
DefaultCloud modelLocal workersJobs that split into many small, self-contained parts
Swapped (/runmode swap)Local modelCloud workersCode-heavy jobs with a lot of output per part

In the terminal, /runmode fusion turns it on. In the desktop app, you pick Fusion in the composer, choose a provider for each role, and use the swap control to flip the direction.

On cost: local tokens count as $0, so only the cloud seat spends tokens, and turnBudgetUsd sets a money cap for one turn. That does not make a Fusion run cheaper than Claude Code by default. In one of our own long runs, the cloud planner’s review rounds pushed the bill above what a cloud-only run had spent by the time we stopped it, so set a budget cap. On privacy, the cloud seat sees your request and the files it works with, so your data does reach that provider. Parallel local workers share one GPU, so more workers on one card means each one runs slower.

What if Claude Code stops mid-task?

Carry the session into another agent instead of starting over. Atomic Agent’s handoff reads the session files Claude Code keeps on your computer and continues the task on a local or cloud model.

In the folder where Claude Code was working, run:

Terminal window
atag handoff --from claude-code

It saves the newest session as a new Atomic Agent chat with its history and sends a message asking the agent to pick up where Claude Code stopped. Tool calls that never got a result are marked so the agent checks them before relying on them. A long session usually will not fit a local model’s window, so handoff keeps the newest steps word for word and turns the older part into a short extract of picked lines, sized to your local model’s context (or 32,768 tokens if none is set). In the desktop app, the same thing is Continue from Claude Code / Codex… in the command palette. The handoff guide lists every flag.

FAQ

Running Claude Code against a local LLM, in short answers.

  • Can Claude Code run with a local LLM?

    Yes. Claude Code sends its requests to whatever address ANTHROPIC_BASE_URL names, and Ollama, llama.cpp's llama-server, LM Studio and vLLM all serve the Anthropic Messages API at /v1/messages. Anthropic itself says it does not support routing Claude Code to non-Claude models, so this works through the local servers' compatibility layers and you are on your own when something breaks.

  • What is the easiest way to run Claude Code on a local model?

    With Ollama installed, run ollama launch claude. For a manual setup, set ANTHROPIC_BASE_URL to http://localhost:11434, ANTHROPIC_AUTH_TOKEN to ollama, ANTHROPIC_API_KEY to an empty string, and start claude with --model and the name of a local model that supports tools. Ollama recommends a context window of 64K tokens or more.

  • Does using a local model with Claude Code use up my Claude subscription limits?

    No, as long as a credential variable is set. Claude Code's docs say that while ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY is active, requests carry that credential instead of your claude.ai login and the subscription's usage limits do not apply to them. Setting only ANTHROPIC_BASE_URL is not enough, because the saved login stays the active credential.

  • What is the best local LLM for Claude Code?

    A model that supports tool calling and fits in your GPU memory with a long context. In our own agent tests a 27B-class model at 4-bit is the practical starting point, which needs about 24 GB of GPU memory. Smaller models run, but Claude Code's long system prompt and tool list leave them little room for your code, and they make more tool-call mistakes on long tasks.

  • Is a local LLM as good as Claude inside Claude Code?

    No, not on long agentic coding. A model that fits on one consumer GPU is weaker at multi-step planning, slower, and works with a smaller context than Claude. It does well on bounded jobs with a clear spec, such as editing a known file, writing a test, or running a script. That gap is why hybrid setups that keep a strong cloud model for planning and review are popular.

  • What can I do when Claude Code hits its usage limit mid-task?

    You can carry the session into another agent and finish it on a local model. Atomic Agent's atag handoff --from claude-code reads the session files Claude Code keeps on disk, saves the session as a new chat with its history, and shortens that history to fit a local model's context window. The desktop app offers the same thing as Continue from Claude Code.

The bottom line

Pointing Claude Code at a local LLM takes three environment variables and one of four servers that already speak its API. Whether it is worth it depends on the job: a 27B-class model on a 24 GB GPU handles bounded edits and scripts, and struggles with long autonomous sessions on a big codebase.

If you want local models doing the bulk of the work without giving up a strong planner, use a setup that keeps the roles separate, such as Fusion, and cap the cloud spend. If your limit runs out halfway through a task, hand the session off and finish it locally. To try either, download Atomic Agent or start with the quickstart.


Commands and variables were checked against the Claude Code, Ollama, llama.cpp, LM Studio, vLLM, LiteLLM and claude-code-router documentation on November 13, 2026.


Get new posts
by email

One email when we post something new.

Share
Written by
Nadya Dudka Product, Atomic Agent
Andrew Dyuzhov SEO and growth

Run your local agent
in one click