Claude Code + LM Studio: run Claude Code on a local model
13 min read
Run Claude Code on a local model with LM Studio 0.4.1 or later: the Anthropic-compatible endpoint, the environment variables, context length, models and limits.
Claude Code can run against a model served by LM Studio on your own machine. Since version 0.4.1, announced on 30 January 2026, LM Studio's local server exposes an Anthropic-compatible POST /v1/messages endpoint, so Claude Code talks to it directly. You set two environment variables and pass a model name. No proxy or translation layer is needed.
You need LM Studio 0.4.1 or later, a model trained for tool use, a context length well above LM Studio's stated floor of about 25K tokens, and 12 GB of memory or more, depending on the model. The guide covers the server, the context setting, the environment variables, how to check that requests stay local, what does not work on a non-Anthropic model, and how to roll the same setup out to a team with Aventail™ Connect.
What you need
Minimum | Comfortable | |
|---|---|---|
LM Studio | 0.4.1 for the Anthropic-compatible endpoint; 0.4.0 for API tokens | Latest release: 0.4.28 on 15 November 2026 |
Claude Code | Any current version | Latest release |
Context length | More than about 25K tokens, by LM Studio's guidance | 64K tokens or more |
Memory | 12 GB for openai/gpt-oss-20b | 16 to 20 GB for the 24B to 35B models, plus room for context |
Disk | 12 to 20 GB per model | Space for two or three models |
Platforms | Apple silicon Mac on macOS 14 or newer, Windows x64 or ARM, Linux x64 or ARM64 | 16 GB of RAM or more, as LM Studio recommends |
LM Studio is free for use at home and at work. It dropped the separate commercial licence on 8 July 2025.
Step 1: install LM Studio and download a model
Download the installer from lmstudio.ai/download. On a server or a VM without a desktop, install the headless daemon instead:
curl -fsSL https://lmstudio.ai/install.sh | bashlms daemon up
The lms command line tool ships with LM Studio. Run the app once before you use it.
Pick one model that fits your memory and is trained for tool use. Claude Code edits files and runs commands through tools. LM Studio says all models support some degree of tool use, but models with native support, marked with a hammer badge in the app, generally perform better. Every model below is marked "Trained for tool use" in the LM Studio catalogue on 15 November 2026.
Model | Download size | Context window | Minimum system memory | Capabilities |
|---|---|---|---|---|
openai/gpt-oss-20b | 12 GB | 131K | 12 GB | Tool use, reasoning |
qwen/qwen3-coder-30b | 15 GB | 256K | 15 GB | Tool use |
mistralai/devstral-small-2-2512 | 16.3 GB | 256K | 16 GB | Tool use, vision |
zai-org/glm-4.7-flash | 16 GB | 128K | 16 GB | Tool use, reasoning |
google/gemma-4-26b-a4b | 15.6 GB | 256K | 16 GB | Tool use, vision, reasoning |
qwen/qwen3.6-35b-a3b | 20.4 GB | Not stated on the catalogue page | 20 GB | Tool use, vision, reasoning |
qwen/qwen3-coder-next | 42 GB | 256K | 42 GB | Tool use |
The minimum memory figure is for loading the model. A larger context adds to it, so check the estimate in step 2 before you commit.
lms get openai/gpt-oss-20b
Step 2: set the context length
LM Studio warns that tools like Claude Code consume a lot of context. It says to use more than about 25K and to raise it for better results. Ollama's docs put the figure for coding agents at 64K, and so does Aventail™ Link for Claude Code. Use 64K if it fits.
Preview the memory a model needs at a given context before you load it:
lms load --estimate-only openai/gpt-oss-20b --context-length 64000
Load the model with that context:
lms load openai/gpt-oss-20b --context-length 64000
To make it stick, set the model's default load settings: open My Models, click the gear icon next to the model and set the context size. LM Studio says these defaults are used when the model is loaded anywhere in the app, including through lms load.
Check what is loaded:
lms ps
Step 3: start the local server
From the app, open the Developer tab and switch on Start server. From a terminal:
lms server start --port 1234
The server binds to 127.0.0.1 by default, so only this machine can reach it. Two server settings matter for Claude Code:
Just in Time Model Loading is on by default. A request for a model that is not loaded makes LM Studio load it. Load the model yourself first, as in step 2, so the context length is the one you chose.
Auto-Evict is on by default. At most one on-demand model stays in memory, so asking for a second model unloads the first.
If you serve on the local network, turn on Require Authentication and create an API token in Server Settings.
Step 4: install Claude Code
macOS, Linux and WSL:
curl -fsSL https://claude.ai/install.sh | bash
Windows PowerShell:
irm https://claude.ai/install.ps1 | iex
Step 5: point Claude Code at LM Studio
These are the lines from LM Studio's Claude Code page:
export ANTHROPIC_BASE_URL=http://localhost:1234export ANTHROPIC_AUTH_TOKEN=lmstudioexport CLAUDE_CODE_ATTRIBUTION_HEADER=0
Then start Claude Code with the LM Studio model identifier:
claude --model openai/gpt-oss-20b
Four things to know about these lines:
The base URL has no
/v1. Claude Code adds/v1/messagesitself.ANTHROPIC_AUTH_TOKENcan be any value while Require Authentication is off. When it is on, set it to your LM Studio API token. LM Studio accepts bothx-api-keyandAuthorization: Bearer.CLAUDE_CODE_ATTRIBUTION_HEADER=0stops Claude Code from adding an attribution block, which holds the client version and a fingerprint of the conversation, to the start of the system prompt. Anthropic's own endpoint strips that block. Any other server receives it as part of the prompt.--modeltakes the LM Studio identifier, aslms lsprints it. On this kind of connection Claude Code runs its background tasks on the main model unlessANTHROPIC_DEFAULT_HAIKU_MODELpins another one. Leave that variable unset. With Auto-Evict on, a second model would unload the first.
To make the setup permanent, put the variables in the env block of ~/.claude/settings.json:
{ "env": { "ANTHROPIC_BASE_URL": "http://localhost:1234", "ANTHROPIC_AUTH_TOKEN": "lmstudio", "CLAUDE_CODE_ATTRIBUTION_HEADER": "0", "ANTHROPIC_MODEL": "openai/gpt-oss-20b", "CLAUDE_CODE_MAX_CONTEXT_TOKENS": "64000", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1" }}
The last two lines matter on a local model:
CLAUDE_CODE_MAX_CONTEXT_TOKENStells Claude Code the real window. Claude Code does not recognise an ID such asopenai/gpt-oss-20b, so it assumes a window for it and prints a warning that names the size; Anthropic's example shows 1M tokens. With the wrong size it compacts too late and the local model runs out of context mid-task. Set the variable to the context length you loaded in step 2.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1turns off auto-updates, telemetry, error reporting, feedback and release-note checks.
For the VS Code extension, LM Studio's blog gives the same two variables in the claudeCode.environmentVariables setting:
"claudeCode.environmentVariables": [ { "name": "ANTHROPIC_BASE_URL", "value": "http://localhost:1234" }, { "name": "ANTHROPIC_AUTH_TOKEN", "value": "lmstudio" }]
Step 6: check it is running locally
Confirm the endpoint answers before you open a repository:
curl -sS -w '\n%{http_code}\n' -X POST "$ANTHROPIC_BASE_URL/v1/messages" \ -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \ -H "anthropic-version: 2023-06-01" \ -H "content-type: application/json" \ -d '{"model": "openai/gpt-oss-20b", "max_tokens": 1, "messages": [{"role": "user", "content": "."}]}'
A JSON response that starts with {"id":"msg_ means LM Studio is serving the model through the Anthropic-compatible API. Then:
Inside Claude Code, run
/statusand check that theAnthropic base URLline showshttp://localhost:1234.Run
lms psand confirm the model is loaded.lms log streamshows the prompts that reach the model.Unplug the network and ask Claude Code to explain a file. If it answers, the model is local.
LM Studio states that the app does not need the internet for chatting with models or for running the local server.
What works and what does not on a local model
LM Studio lists three things as supported on its Anthropic-compatible endpoint: the Messages API, streaming, and tool use. That covers chat, reading and editing files, running commands and the agent loop.
Does not work, or works differently:
Anthropic does not support it. Anthropic's documentation says it does not support routing Claude Code to non-Claude models through any gateway. It runs, but a Claude Code update can break it.
One Anthropic endpoint only. LM Studio documents
/v1/messages. It does not list the token-counting endpoint. Without it, Claude Code falls back to a character-based estimate, so/contextshows approximate counts.No documented prompt caching. LM Studio's Anthropic pages do not mention
cache_control. Plan for every turn to process the whole conversation.Claude.ai features are off. Connectors from claude.ai load only when a claude.ai subscription is the active login. Remote Control is disabled when the base URL points anywhere other than api.anthropic.com. Voice dictation needs a claude.ai account.
Two checks still call Anthropic. The WebFetch domain safety check calls api.anthropic.com unless you set
skipWebFetchPreflight: truein settings. The fast-mode availability check goes there too;CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFICsuppresses it.Request fields a local server may not expect. For a model ID it does not recognise, Claude Code sends everything current Claude models accept, including reasoning and context-management fields. If LM Studio rejects a request for that reason, Anthropic documents
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1, which strips the pre-release fields.Tool reliability depends on the model. LM Studio's troubleshooting note says some models work better than others for agentic tasks. Expect more retries and the odd malformed edit than with Claude.
Speed. Neither vendor publishes tokens per second for this pairing. The first request after a long idle period is the slowest: a model that LM Studio loaded on demand is unloaded after 60 idle minutes by default and has to load again. A model loaded with
lms loadstays in memory until you unload it.
Running the model on another machine
LM Studio's LM Link lets you run Claude Code on a laptop while the model runs on another device you own. The laptop still serves the API at localhost:1234, so the Claude Code settings above do not change. The request leaves the laptop, so it is no longer a single-machine setup. Aventail™'s equivalent, routing to a peer machine that runs Link, is in beta; see peer-to-peer AI routing.
The same setup for a team with Aventail™ Connect
The steps above suit one developer who manages their own machine. They give an IT or security lead no record of which machine sent which request where, and no rule that a developer cannot edit back in a shell profile.
Aventail™ Connect configures supported apps to send their model requests through Aventail™ Link, the inference engine and gateway that runs on each machine. Routing rules are set in Aventail™ Control and evaluated on the device. Claude Code, Claude Desktop, OpenCode and Codex are supported. In this setup Link serves the model itself, in place of LM Studio.
Sign in to Control at control.aventail.co.uk and choose Connect a device.
Install Link on each machine: desktop installers for macOS (Apple silicon), Windows x64 and Linux x64, or unattended:
curl -fsSL https://get.aventail.co.uk/install.sh | AVENTAIL_REGISTRATION_KEY='YOUR_REG_KEY' shServe a model. In Models, download a coding model and choose Start serving. Claude Code needs at least 64K context; Link warns below 128K.
Connect Claude Code. In Connected apps, choose Connect next to Claude. There is no configuration file, endpoint or key to enter. Open a fresh session and choose the model in Link.
Check where it ran. Send a harmless prompt, then open Requests in Control.
Write the routing rule. The first matching enabled rule wins. For a local-only team, permit only On device; if local serving is unavailable, the request fails with an error.
Disconnect restores the settings Link changed. The Free plan covers three connected devices, including business use. Starter is £50 a month excluding VAT and includes ten devices. Routing policies need Control for Enterprise.
Which path to take
Claude Code + LM Studio by hand | Claude Code with Aventail™ Connect | |
|---|---|---|
Who it suits | One developer on their own machine | A team whose code must stay on approved models |
Setup | LM Studio server plus environment variables | Connect button in Link, rules in Control |
Who picks the model | The developer, with | The developer in Link, within the routing rule |
Where requests go | Wherever the shell profile says | Where the routing rule says, evaluated on the device |
Record of requests | Local LM Studio logs on that machine | Requests view in Control |
If the local model is down | Developer changes the base URL | Fails with an error, or falls back to an approved provider |
Cost | Free | Free for three devices; £50 a month for ten |
Frequently asked questions
Can I use LM Studio with Claude Code?
Yes. LM Studio 0.4.1 and later expose an Anthropic-compatible /v1/messages endpoint. Set ANTHROPIC_BASE_URL=http://localhost:1234 and ANTHROPIC_AUTH_TOKEN=lmstudio, then run claude --model with an LM Studio model identifier.
Do I need a proxy such as LiteLLM between Claude Code and LM Studio?
No. Older guides used a proxy because LM Studio only spoke the OpenAI format. Since 0.4.1 Claude Code connects to LM Studio directly.
What context length does Claude Code need in LM Studio?
LM Studio says more than about 25K tokens. In practice set 64K if your memory allows, with lms load <model> --context-length 64000 or in the model's default load settings, and set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the same number.
Which LM Studio model is best for Claude Code?
On 16 GB, openai/gpt-oss-20b, which is the model LM Studio uses in its own examples. With more memory, qwen/qwen3-coder-30b or mistralai/devstral-small-2-2512. Test the model on a real edit before you settle.
Do I need an Anthropic account or API key?
LM Studio's setup uses a placeholder token and no Anthropic key. Model requests go to LM Studio. Claude Code will still ask you to trust the folder you open it in.
Does it work in VS Code?
Yes. Put the two variables in claudeCode.environmentVariables in VS Code's user settings, as shown in step 5.
Is LM Studio or Ollama better for Claude Code?
Both expose an Anthropic-compatible endpoint, and Ollama adds a one-command launcher. The differences are covered in LM Studio vs Ollama and in our guide to Claude Code + Ollama.
Related guides
Sources
LM Studio, Claude Code integration: https://lmstudio.ai/docs/integrations/claude-code
LM Studio, Anthropic compatibility endpoints: https://lmstudio.ai/docs/developer/anthropic-compat and https://lmstudio.ai/docs/developer/anthropic-compat/messages
LM Studio blog, Use your LM Studio models in Claude Code (30 January 2026): https://lmstudio.ai/blog/claudecode
LM Studio, API changelog: https://lmstudio.ai/docs/developer/api-changelog
LM Studio, Local server, server settings and authentication: https://lmstudio.ai/docs/developer/core/server, https://lmstudio.ai/docs/developer/core/server/settings and https://lmstudio.ai/docs/developer/core/authentication
LM Studio, Headless mode and JIT loading: https://lmstudio.ai/docs/developer/core/headless
LM Studio, Idle TTL and Auto-Evict: https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict
LM Studio, lms CLI, lms load, lms get, lms ps and lms server start: https://lmstudio.ai/docs/cli
LM Studio, Per-model defaults: https://lmstudio.ai/docs/app/advanced/per-model
LM Studio, Tool use: https://lmstudio.ai/docs/developer/openai-compat/tools
LM Studio, LM Link with integrations: https://lmstudio.ai/docs/integrations/lmlink
LM Studio, System requirements and offline operation: https://lmstudio.ai/docs/app/system-requirements and https://lmstudio.ai/docs/app/offline
LM Studio catalogue: gpt-oss, qwen3-coder, devstral-2, glm-4.7, gemma-4, qwen3.6, qwen3-coder-next at https://lmstudio.ai/models; download page (version 0.4.28): https://lmstudio.ai/download
LM Studio blog, LM Studio is free for use at work (8 July 2025): https://lmstudio.ai/blog/free-for-work
Anthropic, Claude Code environment variables: https://code.claude.com/docs/en/env-vars
Anthropic, Model configuration: https://code.claude.com/docs/en/model-config
Anthropic, LLM gateway: https://code.claude.com/docs/en/llm-gateway, https://code.claude.com/docs/en/llm-gateway-connect and https://code.claude.com/docs/en/llm-gateway-protocol
Anthropic, Feature availability: https://code.claude.com/docs/en/feature-availability
Ollama, Context length: https://docs.ollama.com/context-length
Aventail™, Connect overview: https://docs.aventail.co.uk/docs/connect/overview
Aventail™, Initial setup: https://docs.aventail.co.uk/docs/getting-started/initial-setup
Aventail™, Routing: https://docs.aventail.co.uk/docs/fleet/routing
Aventail™, Pricing: https://aventail.co.uk/#pricing
All sources were read on 15 November 2026.