Running Claude Code with a Local Model (LM Studio)
A simple guide to using Claude Code with a model running on your own machine, instead of the paid Anthropic API. No global settings are changed.
What you need
- Claude Code already installed.
- LM Studio installed and a model downloaded.
Step 1: Install LM Studio
Download LM Studio from lmstudio.ai and install it like any normal app. Make sure to enable the developer mode during installation or after the first launch.
Step 2: Download a model
In LM Studio, use the search/discover tab to download one of these. Start with the smallest your machine can run:
| Model | Size on disk | Notes |
|---|
google/gemma-4-e4b | ~6.4 GB | Smallest, runs on most laptops |
google/gemma-4-31b-qat | ~17.6 GB | Larger, better quality, needs more RAM |
qwen/qwen3.6-35b-a3b | ~19 GB | Largest, best at coding/tool use |
Step 3: Load the model and start the server
Go to LM Studio's "Developer" tab. Click Load Model and pick your downloaded model. When it shows READY, it is loaded into memory. Then flip the Status toggle at the top so the server is running. Both are needed: READY means the model is in memory, the toggle means the API is actually listening.
Important: When you load the model, set the Context Length to at least 32K (32768) in the load settings. Claude Code sends large requests, and the default context window is too small, which causes it to fail and retry endlessly. Higher is better if your RAM allows.
The server runs at http://localhost:1234.
Step 4: Confirm the model ID
On the right panel, the API Model Identifier shows the exact ID (e.g. google/gemma-4-31b-qat). This guide already uses these IDs in the script below, so you only need this if you download something different.
Tip: Just-In-Time (JIT) model loading is enabled by default in LM Studio (under Server Settings). With it on, LM Studio automatically loads whichever model your script names, so you can switch models from the command line without manually loading each one first. If you've turned it off, load the matching model in LM Studio before running the script.
Step 5: Create and use a reusable shortcut
Save this as claude-local.sh. It maps short names to the full model IDs, so you just pick one:
#!/usr/bin/env bash
# Usage: ./claude-local.sh [gemma-small|gemma-big|qwen] (defaults to gemma-small)
case "$1" in
gemma-big) MODEL="google/gemma-4-31b-qat" ;;
qwen) MODEL="qwen/qwen3.6-35b-a3b" ;;
gemma-small|"") MODEL="google/gemma-4-e4b" ;;
*) echo "Unknown model '$1'. Use: gemma-small | gemma-big | qwen"; exit 1 ;;
esac
shift 2>/dev/null
ANTHROPIC_BASE_URL=http://localhost:1234 \
ANTHROPIC_AUTH_TOKEN=lmstudio \
ANTHROPIC_MODEL="$MODEL" \
claude "$@"
Make it executable once:
chmod +x claude-local.sh
Then run Claude Code with whichever model is loaded in LM Studio:
./claude-local.sh gemma-small # Gemma 4 E4B
./claude-local.sh gemma-big # Gemma 4 31B Qat
./claude-local.sh qwen # Qwen3.6 35B
These settings apply only to that run, so your normal Claude Code setup stays untouched. Make sure the model you pass matches the one currently loaded (READY) in LM Studio.
Switching models later
Click Eject in LM Studio, load a different model, wait for READY, then run the script with the matching short name. The server keeps running across swaps, so no restart needed.
Notes
- The server must stay running in LM Studio while you use Claude Code.
- Smaller models are weaker at the tool calling Claude Code relies on, so expect rough edges. Qwen tends to handle this best.
- Set LM Studio's context length as high as your hardware allows for better results.