Tutorial: Using Local Models with Claude
Code
This guide helps you configure Claude Code to run with local LLMs. By using a local proxy,
you can route Claude Code requests to models running on your own machine.
Tools used in this guide:
● LM Studio: To host and serve local models.
● Claude Code Router: To act as the local proxy for Claude Code.
Part 1: LM Studio Setup
First, we need to set up the inference server that will run the local model.
1. Install LM Studio: Download and install it from [Link].
2. Download a Model:
○ Search for a model inside LM Studio, or run the following command in your terminal
to download openai/gpt-oss-20b (used as the example in this guide):
lms get openai/gpt-oss-20b
3. Configure the Server:
○ Open the Inference Server tab in LM Studio.
○ Load openai/gpt-oss-20b into the server.
○ Crucial Step: Set the "Context Length" to the maximum available token length to
ensure Claude Code functions correctly.
○ Start the server.
Checkpoint: Ensure your server is running and the model is loaded before
proceeding.
Part 2: Claude Code Router Setup
Next, we will install the router to bridge Claude Code and LM Studio.
1. Installation
Ensure you have the base Claude Code tool installed. If not, install it first:
npm install -g @anthropic-ai/claude-code
Then, install the Claude Code Router:
npm install -g @musistudio/claude-code-router
2. Configuration
Launch the router's configuration UI:
Run ccr ui
Add a New Provider:
1. Click Add Provider.
2. API Path: Enter [Link] (or your specific LM Studio local
address).
3. API Key: Enter any random string (LM Studio local server usually ignores this, but a value
is required).
4. Model: Enter openai/gpt-oss-20b.
5. Click Save.
General Settings:
1. Locate your Claude binary path by running which claude in your terminal.
2. Copy that path into the General Settings tab in the UI. (The first icon in the top right
bar.)
3. Set openai/gpt-oss-20b as the Default Model.
Finalize:
1. Click Save & Restart to apply all settings.
2. Verify the setup by running:
ccr model
Ensure openai/gpt-oss-20b is listed and configured properly.
Part 3: Activate the Environment
To enable local support for the current session, you need to inject specific environment
variables.
Run the following command:
eval "$(ccr activate)"
What this does:
This command configures your shell to route Claude traffic through the local router. It sets
variables such as:
● ANTHROPIC_BASE_URL: Points to your local router (Default: [Link]
● ANTHROPIC_AUTH_TOKEN: Sets the API key from your config.
● NO_PROXY: Prevents interference (Sets to [Link]).
● DISABLE_TELEMETRY & DISABLE_COST_WARNINGS: optimizes the local experience.
Note: These variables are only valid for your current shell session.
To make this persistent, add eval "$(ccr activate)" to your shell configuration file
(e.g., ~/.zshrc or ~/.bashrc).
Part 4: Running Claude Code Locally
You are now ready to use Claude Code with your local model.
1. Start the Router: Ensure the service is running in the background.
ccr start
2. Launch Claude:
claude
3. Verify:
○ Interact with Claude in the terminal.
○ Check the LM Studio logs; you should see inference requests appearing as Claude
generates responses.