A small Zsh script for running Claude Code with a local model hosted by LM Studio.
The script automatically:
- Finds the model currently loaded in LM Studio.
- Configures the environment variables needed for Claude Code to use LM Studio's Anthropic-compatible API.
- Launches Claude Code using the loaded model.
- Passes any additional command-line arguments through to Claude Code.
This makes switching between local models easy: load the model you want in LM Studio, then run the script.
You'll need:
- macOS
- Zsh
- LM Studio with the
lmsCLI installed - Claude Code
- Python 3
- A model loaded in LM Studio that works well with tool/function calling
Verify the commands are available:
lms --version
claude --version
python3 --versionStart the LM Studio API server:
lms server start --port 1234Alternatively, start the server from the Developer section of LM Studio.
Load the model you want Claude Code to use.
You can see currently loaded models with:
lms psor inspect the JSON representation with:
lms ps --jsonSave the script as:
~/bin/claude-local
Make it executable:
chmod +x ~/bin/claude-localMake sure ~/bin is in your PATH. For example, add this to ~/.zshrc:
export PATH="$HOME/bin:$PATH"Then reload your shell:
source ~/.zshrcLoad a model in LM Studio and run:
claude-localThe script determines the loaded model and launches Claude Code with it.
For example:
$ claude-local
LM Studio model: qwen/qwen3-coder-30b
Launching Claude Code...
Arguments are passed directly to claude.
For example:
claude-local --dangerously-skip-permissionsor:
claude-local -p "Explain this project"Conceptually, the script runs:
Claude Code
│
│ Anthropic Messages API
▼
localhost:1234
│
▼
LM Studio
│
▼
Loaded local model
Claude Code continues to provide the agent environment and tools, while inference is performed by the model running locally in LM Studio.
The launcher configures:
ANTHROPIC_BASE_URL=http://localhost:1234
ANTHROPIC_AUTH_TOKEN=lmstudio
CLAUDE_CODE_ATTRIBUTION_HEADER=0
ANTHROPIC_MODEL=<loaded LM Studio model>These variables exist only for the launcher process and the Claude Code process it starts. They do not need to be added permanently to your shell configuration.
The default configuration assumes LM Studio's Require Authentication option is disabled.
If you've enabled authentication in LM Studio, replace:
export ANTHROPIC_AUTH_TOKEN="lmstudio"with your LM Studio API token.
There's no need to modify the script when switching models.
Simply load another model in LM Studio:
LM Studio → Load Model
and run:
claude-localagain.
The launcher discovers the currently loaded model each time it starts.
Claude Code is useful as an agentic coding environment independently of the Claude models themselves. It provides capabilities such as:
- Project exploration
- File reading and editing
- Shell commands
- Search and grep
- Agentic coding workflows
CLAUDE.md- Skills
- MCP servers
- Subagents
- Permission management
LM Studio can expose local models through an Anthropic-compatible /v1/messages API, allowing Claude Code to use a locally hosted model instead of sending inference requests to Anthropic.
This is particularly useful for experimenting with coding models such as Qwen, Nemotron, and other models available through LM Studio.
Not every local model will work equally well with Claude Code.
Claude Code is an agentic workload. A model needs to do more than generate good source code. In particular, good results depend heavily on:
- Tool/function calling
- Instruction following
- Structured output
- Long-context performance
- Reasoning across multiple tool calls
- Understanding command output
- Recovering from failed commands
- Iteratively modifying a codebase
A model that performs well in an ordinary LM Studio chat session may therefore perform poorly when used through Claude Code.
A reasonably large context window is also recommended. Agent sessions can consume context quickly, so 32K or greater is a useful starting point, with 64K+ preferable for larger coding sessions.
Install or enable the LM Studio CLI and verify:
lms --versionInstall Claude Code and verify:
claude --versionCheck:
lms psIf nothing is listed, load a model in LM Studio before running claude-local.
Check the server:
lms server statusStart it if necessary:
lms server start --port 1234You can also test the OpenAI-compatible models endpoint directly:
curl http://localhost:1234/v1/modelsThe connection may be working correctly while the model itself struggles with Claude Code's tool-calling protocol.
Try a model specifically designed or tuned for coding and agentic tool use.
The model inference performed through this configuration is sent to your local LM Studio server rather than Anthropic's model API.
However, Claude Code itself may have features that communicate with external services. Don't assume that using a local inference endpoint makes every aspect of Claude Code completely offline.
- LM Studio — Claude Code integration: https://lmstudio.ai/docs/integrations/claude-code
- LM Studio documentation: https://lmstudio.ai/docs
- Claude Code documentation: https://docs.anthropic.com/en/docs/claude-code
This script is small enough to use however you find useful. If you're publishing it as a Gist, consider adding an MIT license if you want to explicitly permit reuse.