---
title: "Claude Code + LM Studio: run Claude Code on a local model — Aventail™ Guides"
url: https://aventail.co.uk/guides/claude-code-lm-studio
description: "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."
lang: en-GB
---

Skip to content

Aventail™ co-founder speaks to BBC Radio Wales on AI safety and AI agents. Read the story: https://aventail.co.uk/newsroom/bbc-radio-wales-joseph-ward-ai-agents-safety

All guides (https://aventail.co.uk/guides)

# Claude Code + LM Studio: run Claude Code on a local model

23 November 2026 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 | bash`
`lms 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:1234`
`export ANTHROPIC_AUTH_TOKEN=lmstudio`
`export 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/messages` itself.
- `**ANTHROPIC_AUTH_TOKEN**` **can be any value** while Require Authentication is off. When it is on, set it to your LM Studio API token. LM Studio accepts both `x-api-key` and `Authorization: Bearer`.
- `**CLAUDE_CODE_ATTRIBUTION_HEADER=0**` stops 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.
- `**--model**` **takes the LM Studio identifier**, as `lms ls` prints it. On this kind of connection Claude Code runs its background tasks on the main model unless `ANTHROPIC_DEFAULT_HAIKU_MODEL` pins 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_TOKENS` tells Claude Code the real window. Claude Code does not recognise an ID such as `openai/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=1` turns 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:

1. Inside Claude Code, run `/status` and check that the `Anthropic base URL` line shows `http://localhost:1234`.
2. Run `lms ps` and confirm the model is loaded. `lms log stream` shows the prompts that reach the model.
3. 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 `/context` shows 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: true` in settings. The fast-mode availability check goes there too; `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` suppresses 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 load` stays 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 (https://aventail.co.uk/guides/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.

1. **Sign in to Control** at control.aventail.co.uk and choose Connect a device.
2. **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' sh`
3. **Serve a model.** In Models, download a coding model and choose Start serving. Claude Code needs at least 64K context; Link warns below 128K.
4. **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.
5. **Check where it ran.** Send a harmless prompt, then open Requests in Control.
6. **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 `--model` | 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 (https://aventail.co.uk/guides/claude-code-ollama).

## Related guides

- AI coding on your own models: https://aventail.co.uk/guides/ai-coding-on-your-own-models
- Claude Code + Ollama: https://aventail.co.uk/guides/claude-code-ollama
- OpenCode + LM Studio: https://aventail.co.uk/guides/opencode-lm-studio
- Claude Code with: https://aventail.co.uk/guides/claude-code-with-aventail-connect
  Aventail: https://aventail.co.uk/guides/claude-code-with-aventail-connect
  ™: https://aventail.co.uk/guides/claude-code-with-aventail-connect Connect: https://aventail.co.uk/guides/claude-code-with-aventail-connect
- LM Studio vs: https://aventail.co.uk/guides/lm-studio-vs-aventail
  Aventail: https://aventail.co.uk/guides/lm-studio-vs-aventail
  ™: https://aventail.co.uk/guides/lm-studio-vs-aventail
- Claude Code security for enterprises: https://aventail.co.uk/guides/claude-code-security-enterprise

## Sources

1. LM Studio, Claude Code integration: https://lmstudio.ai/docs/integrations/claude-code
2. LM Studio, Anthropic compatibility endpoints: https://lmstudio.ai/docs/developer/anthropic-compat and https://lmstudio.ai/docs/developer/anthropic-compat/messages
3. LM Studio blog, Use your LM Studio models in Claude Code (30 January 2026): https://lmstudio.ai/blog/claudecode
4. LM Studio, API changelog: https://lmstudio.ai/docs/developer/api-changelog
5. 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
6. LM Studio, Headless mode and JIT loading: https://lmstudio.ai/docs/developer/core/headless
7. LM Studio, Idle TTL and Auto-Evict: https://lmstudio.ai/docs/developer/core/ttl-and-auto-evict
8. LM Studio, lms CLI, lms load, lms get, lms ps and lms server start: https://lmstudio.ai/docs/cli
9. LM Studio, Per-model defaults: https://lmstudio.ai/docs/app/advanced/per-model
10. LM Studio, Tool use: https://lmstudio.ai/docs/developer/openai-compat/tools
11. LM Studio, LM Link with integrations: https://lmstudio.ai/docs/integrations/lmlink
12. LM Studio, System requirements and offline operation: https://lmstudio.ai/docs/app/system-requirements and https://lmstudio.ai/docs/app/offline
13. 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
14. LM Studio blog, LM Studio is free for use at work (8 July 2025): https://lmstudio.ai/blog/free-for-work
15. Anthropic, Claude Code environment variables: https://code.claude.com/docs/en/env-vars
16. Anthropic, Model configuration: https://code.claude.com/docs/en/model-config
17. 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
18. Anthropic, Feature availability: https://code.claude.com/docs/en/feature-availability
19. Ollama, Context length: https://docs.ollama.com/context-length
20. Aventail ™, Connect overview: https://docs.aventail.co.uk/docs/connect/overview
21. Aventail ™, Initial setup: https://docs.aventail.co.uk/docs/getting-started/initial-setup
22. Aventail ™, Routing: https://docs.aventail.co.uk/docs/fleet/routing
23. Aventail ™, Pricing: https://aventail.co.uk/#pricing

All sources were read on 15 November 2026.

We use optional cookies and tracking to identify visiting companies, load our contact form, measure Google Ads download clicks and understand page use with PostHog on our homepage, Connect and How it works pages, Ollama and LM Studio comparison guides and campaign pages. Cookie policy (https://aventail.co.uk/cookies)

## Structured data

```json
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "Organization",
      "@id": "https://aventail.co.uk/#organization",
      "name": "Aventail",
      "alternateName": "Locai",
      "legalName": "Loc.ai Ltd",
      "description": "Aventail, formerly Locai, was founded in 2026 and is a graduate of Google AI First. It gives enterprises the full AI stack to adopt AI securely: a built-in inference engine, deployment of supported models across approved hardware, on-device classification and policy-based routing between those machines and approved external AI providers, central management and an employee workspace. Organisations use Aventail to put approved information to work while controlling where inference requests run.",
      "url": "https://aventail.co.uk/",
      "logo": "https://aventail.co.uk/apple-touch-icon.png",
      "email": "hello@aventail.co.uk",
      "hasCredential": [
        {
          "@type": "EducationalOccupationalCredential",
          "name": "Cyber Essentials",
          "credentialCategory": "certification",
          "url": "https://aventail.co.uk/trust#cyber-essentials"
        }
      ]
    },
    {
      "@type": "Article",
      "@id": "https://aventail.co.uk/guides/claude-code-lm-studio#page",
      "url": "https://aventail.co.uk/guides/claude-code-lm-studio",
      "name": "Claude Code + LM Studio: run Claude Code on a local model",
      "description": "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.",
      "publisher": {
        "@id": "https://aventail.co.uk/#organization"
      },
      "headline": "Claude Code + LM Studio: run Claude Code on a local model",
      "datePublished": "2026-11-23",
      "dateModified": "2026-11-23T19:37:53.694136+00:00",
      "image": "https://aventail-ai-platform.lovable.app/images/share/og-home-v7.jpg",
      "author": {
        "@id": "https://aventail.co.uk/#organization"
      }
    },
    {
      "@type": "BreadcrumbList",
      "@id": "https://aventail.co.uk/guides/claude-code-lm-studio#breadcrumb",
      "itemListElement": [
        {
          "@type": "ListItem",
          "position": 1,
          "name": "Home",
          "item": "https://aventail.co.uk/"
        },
        {
          "@type": "ListItem",
          "position": 2,
          "name": "Guides",
          "item": "https://aventail.co.uk/guides"
        },
        {
          "@type": "ListItem",
          "position": 3,
          "name": "Claude Code + LM Studio: run Claude Code on a local model",
          "item": "https://aventail.co.uk/guides/claude-code-lm-studio"
        }
      ]
    }
  ]
}
```