Claude Code with a local LLM: Step-by-step guide with Ollama, llama.cpp, and LM Studio
Share
Updated: December 2026
Can Claude Code be used with a local LLM?
Yes: Ollama, llama.cpp, and LM Studio are compatible.
Since January 2026, Ollama, llama.cpp (llama-server), and LM Studio have supported Anthropic's Messages API, which is the one used by Claude Code. You simply need to point ANTHROPIC_BASE_URL to your local server, fill in the ANTHROPIC_AUTH_TOKEN, and then launch claude with a reliable model capable of tool calling and at least 64,000 context tokens, such as Qwen3.8-27B on a 32 GB graphics card.
Claude Code is Anthropic's programming agent: it reads your repository, executes commands, and modifies files. By default, it sends all this work to Claude models in the cloud. However, you can connect it to a model running on your own machine. Below are the exact commands, verified in official documentation in November 2026, the models that can handle the task, and what you sacrifice in exchange.
How does Claude Code work with a local model?
Claude Code sends every request to an address that speaks the Anthropic Messages API; if a local server supports this same protocol, you simply need to update that address. Claude Code remains the agent (it reads files, runs tests, and suggests modifications), while the local model becomes its "brain."
The Messages API is the request format for Claude models: a list of messages, tools (reading a file, running a command), and streaming responses. Ollama, llama.cpp, and LM Studio added this format to their servers in January 2026, alongside the OpenAI format they already supported.
Which local servers are compatible with Claude Code?
Three servers natively support the Anthropic Messages API: Ollama (from version 0.14.0), llama-server from llama.cpp, and LM Studio (from version 0.4.1). For servers that only support the OpenAI format, a gateway like LiteLLM can handle the translation.
| Server | Since | Address for Claude Code | Notes |
|---|---|---|---|
| Ollama | version 0.14.0, January 16, 2026 | http://localhost:11434 | The simplest option (command ollama launch claude). It does not support token counting or Anthropic-style request caching. |
| llama.cpp (llama-server) | January 2026 | http://127.0.0.1:8080 (port selected with --port) |
Includes token counting. Tools require Jinja conversation templates, which are enabled by default. |
| LM Studio | version 0.4.1, January 30, 2026 | http://localhost:1234 | Features a GUI; server started via lms server start. We recommend more than 25,000 context tokens. |
| LiteLLM (gateway) | per its documentation | the gateway address | Translates to an OpenAI-formatted server. Adds one more component to maintain. |
Versions and dates: official documentation and announcements from Ollama, llama.cpp, and LM Studio, reviewed on November 28, 2026.
How to connect Claude Code to Ollama?
Launch Ollama with a context of at least 64,000 tokens, then start Claude Code using three variables: the Ollama address, any token, and an empty API key. The Ollama documentation provides these commands:
ollama pull qwen3.8:27b OLLAMA_CONTEXT_LENGTH=65536 ollama serve export ANTHROPIC_BASE_URL=http://localhost:11434 export ANTHROPIC_AUTH_TOKEN=ollama export ANTHROPIC_API_KEY="" claude --model qwen3.8:27b
Even simpler: ollama launch claude launches Claude Code with pre-set configurations and lets you choose the model. On Windows, using PowerShell, the syntax is $env:ANTHROPIC_BASE_URL = "http://localhost:11434", and the context is configured within the Ollama application settings.
Why adjust the context? Without manual configuration, Ollama selects the limit based on your graphics card memory: 4,096 tokens for under 24 GB, and 32,768 tokens between 24 and 48 GB. This is insufficient for Claude Code, as its instructions and tool descriptions already occupy a significant portion of the window.
:cloud suffix do not run locally; they run on Ollama's servers. Ollama's documentation includes them in its examples for Claude Code. To keep your code on your own machine, only use downloaded models and disable cloud functions with OLLAMA_NO_CLOUD=1 (or disable_ollama_cloud in ~/.ollama/server.json).How to connect Claude Code to llama.cpp (llama-server)?
Launch llama-server with the model, a short name (alias), a large context window, and a fixed port, then provide this address to Claude Code. This is our preferred setup: we use Claude Code with a Qwen 3.8 27B served by llama.cpp.
llama-server -hf unsloth/Qwen3.8-27B-GGUF:UD-Q4_K_XL \ --alias qwen3.8-27b -c 131072 --port 8080 \ -ctk q8_0 -ctv q8_0 export ANTHROPIC_BASE_URL=http://127.0.0.1:8080 export ANTHROPIC_AUTH_TOKEN=local export ANTHROPIC_API_KEY="" claude --model qwen3.8-27b
What these options do, according to the llama-server documentation:
-
-hfdownloads the GGUF file (the compressed model format for llama.cpp) from Hugging Face. In this case, it is a 4-bit version released by Unsloth. -
--aliasassigns the name that Claude Code will use with the--modelcommand. -
-csets the context size. By default, llama-server uses the model's default size. -
-ctk q8_0 -ctv q8_0store the conversation memory (the KV cache) in 8-bit instead of 16-bit, which takes up about half the space. Unsloth uses this setting in its recipe for Claude Code. - The server only listens to the local machine (127.0.0.1) unless you change
--host. To share it over the network, add a key with--api-keyand enter the same one inANTHROPIC_AUTH_TOKEN.
And with LM Studio?
Start the LM Studio server on port 1234, then set the same variables; LM Studio adds CLAUDE_CODE_ATTRIBUTION_HEADER=0 to its recipe.
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 you have enabled authentication in LM Studio, the token is your LM Studio API token.
Which Claude Code settings should you know?
Add the variables to the env block in ~/.claude/settings.json to avoid re-typing them, and use the /status command to verify that Claude Code is communicating correctly with your server. The table below lists the useful variables for a local model.
| Variable | Role |
|---|---|
ANTHROPIC_BASE_URL |
Local server address. This redirects Claude Code away from the cloud. |
ANTHROPIC_AUTH_TOKEN |
Token sent in the "Authorization: Bearer" header. Any value works if the server does not require one. |
ANTHROPIC_MODEL |
The default model used instead of the --model flag. |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
Model for background tasks (session titles, minor tasks). Specify your local model here as well. |
CLAUDE_CODE_SUBAGENT_MODEL |
Model for sub-agents that do not have a specific model assigned. |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC |
Disables non-essential traffic, such as automatic updates, telemetry, and error reports. |
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS |
Removes experimental fields from requests. Try this if the server returns "Extra inputs are not permitted". |
API_TIMEOUT_MS |
Timeout for each request (10 minutes by default). Increase this if the machine takes time to process a long context. |
CLAUDE_CODE_ATTRIBUTION_HEADER | Set to 0: recommended by LM Studio and Unsloth (see below). |
Example file for llama-server:
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:8080",
"ANTHROPIC_AUTH_TOKEN": "local",
"ANTHROPIC_MODEL": "qwen3.8-27b",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "qwen3.8-27b",
"CLAUDE_CODE_SUBAGENT_MODEL": "qwen3.8-27b",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0"
}
}
Why CLAUDE_CODE_ATTRIBUTION_HEADER=0?
Claude Code includes a small block at the beginning of its instructions that changes with every request. A local server caches the start of conversations to avoid re-reading them every time, but it can only reuse this cache if the beginning remains identical. According to Unsloth documentation, this block prevents such reuse and can make local inference up to 90% slower. This variable is not mentioned in the Anthropic documentation we reviewed; we are citing it based on information from LM Studio and Unsloth. Unsloth notes that while recent versions of Claude Code read this setting from the terminal, the settings.json file remains the most reliable method.
Which local model should you choose for Claude Code?
You need a reliable model for tool calling with at least 64,000 context tokens: on a 32 GB card, Qwen3.8-27B is the most robust choice in November 2026; with more memory, Qwen3-Coder-Next or gpt-oss-120b. Claude Code executes dozens of tool calls per task: a model that fails on the format of a single call will block the entire workflow.
| Model | Size | Context | Memory in 4-bit, 131,072 tokens (estimate) | Publisher Insights |
|---|---|---|---|---|
| Qwen3.8-27B (Apache 2.0) | 27 billion, dense | 262,144 tokens | 25 GB | Several of its coding tests were passed with Claude Code (SWE-bench Pro: 61.7). |
| Qwen3.6-35B-A3B (Apache 2.0) | 35 billion, 3 active | 262,144 tokens | 24 GB | Faster than the 27B, slightly less capable: 49.5 on SWE-bench Pro. |
| GLM-4.7-Flash (MIT) | 30 billion, 3 active | 202,752 tokens (model configuration) | 26 GB | 59.2 on SWE-bench Verified. |
| Devstral Small 2 (Apache 2.0) | 24 billion, dense | 256,000 tokens | 35 GB (25 GB at 65,536 tokens) | 68.0 on SWE-bench Verified. Lists Claude Code among compatible tools. |
| Qwen3-Coder-Next (Apache 2.0) | 80 billion, 3 active | 262,144 tokens | 49 GB | 70.6 on SWE-bench Verified. Lists Claude Code among compatible tools. |
| gpt-oss-120b (Apache 2.0) | 117 billion, 5.1 active | 131,072 tokens (model configuration) | 72 GB | OpenAI reasoning model, text only. |
Sizes, licenses, and scores: publisher Hugging Face sheets, reviewed on November 28, 2026. Scores are provided by the publishers, with settings varying between sheets: they rank the models, they do not break ties. Memory: Radiance Systems estimates (4-bit weights, 16-bit KV cache, operating margin), not measurements.
The largest open models, such as GLM-5.3-Flash (320 billion parameters), require a multi-card server: approximately 190 GB in 4-bit according to our estimates. For detailed memory requirements for Qwen3.8-27B, see our article best PC for Qwen 3.8 27B.
What machine do you need for Claude Code locally?
A 32 GB card is sufficient for Qwen3.8-27B in 4-bit mode with a 131,072 token context; 96 GB allows for the 8-bit version with the full model context, or a model exceeding 100 billion parameters. Context is just as important as the model: Claude Code re-reads its instructions, open files, and command results at every turn.
| Memory | Capacity (estimate) | Our machine |
|---|---|---|
| 32 GB (RTX 5090) | Qwen3.8-27B in 4-bit with 131,072 tokens (25 GB), Qwen3.6-35B-A3B, GLM-4.7-Flash | CoreIA RTX 5090 |
| 96 GB (RTX PRO 6000, 1,792 GB/s) | Qwen3.8-27B in 8-bit with its 262,144 tokens (45 GB), Qwen3-Coder-Next in 8-bit (83 GB), gpt-oss-120b | CoreIA RTX PRO 6000 |
| 128 GB unified (GB10, 273 GB/s) | The same models, plus Qwen3.8-Flash-Next in 4-bit (106 GB). Better suited for MoE models (few active parameters) than dense models. | CoreIA GB10 |
Memory bandwidth determines write speed. The GB10 offers ample memory but features a bandwidth of 273 GB/s, which is roughly six times slower than an RTX PRO 6000. This makes it suitable for MoE models like Qwen3-Coder-Next (3 billion active parameters), but less ideal for a 27 billion dense model. We do not provide specific speed guarantees as performance depends on the model, context, and settings. To learn more, read our guide how much VRAM for a local LLM.
What local models do not replace
The quality of top-tier Claude models
On the public Terminal-Bench 4.1 ranking (terminal agent tasks, recorded on November 28, 2026), Claude Opus 5.5 in Claude Code solves 65.8% of tasks; the top open model on the leaderboard, Kimi K3.1 Pro, solves 59.7%, but it features 2,800 billion parameters. Qwen3.8-27B is not listed. Expect more errors and more revisions on long tasks.
Speed
A workstation writes slower than a cloud service and takes longer to process long contexts. For short, targeted tasks, the difference is manageable; for a major overhaul, it becomes noticeable.
All Claude Code features
According to Anthropic's documentation, Remote Control is disabled when ANTHROPIC_BASE_URL points to a location other than Anthropic, and voice dictation requires a connection to claude.ai. Ollama does not support request caching in the sense defined by Anthropic. The auto-compaction setting (CLAUDE_CODE_AUTO_COMPACT_WINDOW) does not go below 100,000 tokens: if you have a shorter context on the server side, run /compact manually.
Does your code actually stay on your machine?
Your code text stays on your local server and nowhere else, provided three conditions are met: you use a downloaded model (not a cloud model), Claude Code's ancillary traffic is disabled, and no tools are used that connect to the internet themselves.
-
The model. With a downloaded model, requests stop at your server. Ollama
:cloudmodels, however, are sent to remote servers. -
Ancillary traffic. Claude Code also sends version checks and telemetry.
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1disables these. Anthropic's documentation specifies that the security check for the web page reading tool still calls api.anthropic.com; this can be disabled separately (skipWebFetchPreflight). -
The tools. Web search, MCP servers, or a
git pushnaturally require an external connection. If your code must never leave your local environment, work on a machine with no internet access.
This is the primary reason for choosing this setup: handling source code under an NDA, processing client data during testing, or complying with internal policies that forbid cloud usage. For a solo developer without these constraints, a Claude subscription remains simpler and more capable.
Our machine for local coding
At Radiance Systems, a specialist integrator in local AI based in Auriol (Bouches-du-Rhône), we deliver the machine with the model server pre-installed, your chosen model downloaded and tested, and Claude Code or another agent configured for use. If multiple developers share the machine, we configure the network access and keys. Hardware and software, one single point of contact.
Qwen3.8-27B for a developer: CoreIA RTX 509032 GB, 10 to 15 people simultaneously for conversation use (estimate).live pricing excl. VAT
8-bit model, long context, small team: CoreIA RTX PRO 600096 GB, 8 to 15 people (estimate).live pricing excl. VAT
MoE models with over 100 billion parameters: CoreIA GB10128 GB unified, compact, 2 to 4 people (estimate).live pricing excl. VAT
Base configuration price excl. VAT, automatically updated. The full range is available on the page of our AI machinesThe GB10 is detailed in our article on the Local AI development on GB10.
A code agent that never leaves your premises
Tell us about your preferred programming language, your repository size, and the number of developers on your team. We provide the model and the hardware, delivered fully installed and tested. Get a free quote within 48 working days.
Frequently Asked Questions
Does Claude Code work with Ollama?
Yes. Since version 0.14.0 (January 2026), Ollama has supported the Anthropic Messages API. Set ANTHROPIC_BASE_URL=http://localhost:11434, ANTHROPIC_AUTH_TOKEN=ollama, and leave ANTHROPIC_API_KEY blank, then run claude --model with a downloaded model. The command ollama launch claude configures these settings for you.
Do you need a Claude subscription to use Claude Code with a local model?
No. When ANTHROPIC_AUTH_TOKEN is set, Claude Code sends this token instead of your claude.ai connection, routing requests to your local server. Certain features linked to the claude.ai account, such as remote control, will no longer be available.
What is the best local model for Claude Code?
On a 32 GB graphics card, Qwen3.8-27B (Apache 2.0, 262,144 context tokens) is the most reliable choice as of November 2026. For 96 GB or 128 GB, go with Qwen3-Coder-Next or gpt-oss-120b. Choose a model with reliable tool-calling capabilities and at least 64,000 context tokens.
How much memory is required for Claude Code locally?
Based on our estimates, approximately 25 GB is needed for Qwen3.8-27B in 4-bit mode with 131,072 context tokens, requiring a 32 GB card. Budget 45 GB for the 8-bit version with full context, and 72 GB for gpt-oss-120b.
Is Claude Code with a local model as effective as using Claude?
No. According to the Terminal-Bench 4.1 rankings from November 2026, the top Claude models still outperform all open-source models, and models capable of running on a local workstation are even more modest. Local deployment is justified by code privacy, not by quality.
Does my code go to Anthropic when using a local model?
Model requests are sent to your server. Disable non-essential Claude Code traffic using CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1, avoid Ollama cloud models, and bypass tools that connect to the internet. For maximum security, use a machine with no internet access.
Sources
- Anthropic : LLM gateways and Claude Code, connecting Claude Code to a gateway, environment variables
- Ollama : Claude Code with Ollama, Anthropic API compatibility, January 16, 2026 announcement, context length, FAQ (local mode only)
- llama.cpp : Anthropic Messages API in llama.cpp, llama-server documentation
- LM Studio : Claude Code with LM Studio, version 0.4.1 notes
- Unsloth, Claude Code with local models ; LiteLLM, Claude Code with other models
- Hugging Face Sheets: Qwen3.8-27B, Qwen3.6-35B-A3B, Qwen3-Coder-Next, Devstral Small 2, GLM-4.7-Flash, gpt-oss-120b
- Terminal-Bench 4.1 Ranking (Stanford and Laude Institute)
- NVIDIA: GB10 spec sheet (DGX Spark), RTX PRO 6000 spec sheet
Commands and variables sourced from official documentation as of November 28, 2026; these change rapidly, so please verify your software version. Memory: Radiance Systems estimates, not measured values. Scores: published by the manufacturers or the cited ranking, not our own tests. Simultaneous users: orders of magnitude from our comparisons.
Let’s talk about your local AI project
By phone or video call, we look at what you need together. You leave with a clear recommendation, with no commitment.
- The AI computer or server that fits your use and your team
- What we should develop for you, if needed: automations, applications, search in your documents
- Budget and lead times, with a quote within 24 hours
Calls in English, French or Dutch.
You are booked!











