# Claude Code with Local LLM

## Overview

* A local computer isn't going to compete with a datacenter anytime soon but maybe you're without Internet, want additional data privacy, or have hit your Claude Code subscription limit for the month. In such cases, we can setup Claude Code to work with local LLMs.

{% hint style="info" %}
These same steps can be used for non-local models e.g., if you have an AI server rig, you can point Claude Code (and most other apps) to the model hosted there.&#x20;
{% endhint %}

***

## Setup

### LM Studio

* Download a model, for help checkout [LM Studio](/ai/running-llms-locally/lm-studio.md#discovering-and-downloading-models)&#x20;
* Start a server, via GUI see [LM Studio](/ai/running-llms-locally/lm-studio.md#start-lm-studio-server) or run this

{% code overflow="wrap" %}

```bash
## 25k recommended for claude code usage
lms load openai/gpt-oss-20b --context-length 25000

lms server start --port 1234
```

{% endcode %}

### Claude Code Setup — Terminal

* In the terminal run the below making sure to swap out the port and model based on your needs

{% code overflow="wrap" %}

```bash
export ANTHROPIC_BASE_URL=http://localhost:1234
export ANTHROPIC_AUTH_TOKEN=lmstudio
```

{% endcode %}

* Make sure this is the model you've downloaded and have running locally

{% code overflow="wrap" %}

```zsh
claude --model openai/gpt-oss-20b
```

{% endcode %}

* In Claude, we can see the local model is being used

<figure><img src="/files/lPKBF4MdBuvwIRFbWG3t" alt=""><figcaption></figcaption></figure>

### Claude Code Setup — VS Code

* In VS Code, hit `CMD + SHIFT + P`  and open `Preferences: Open User Settings (JSON)` and paste this snippet within the main `{ }`&#x20;
* Make sure swap out the the URL as needed

{% code overflow="wrap" %}

```json
"claudeCode.environmentVariables": [
        {
            "name": "ANTHROPIC_BASE_URL",
            "value": "http://localhost:1234"
        },
        {
            "name": "ANTHROPIC_AUTH_TOKEN",
            "value": "lmstudio"
        }
    ],
```

{% endcode %}

### Validating Setup — Developer Logs

* Within LMStudio, we can view the developer logs to validate our interaction with Claude is leveraging the local LLM

<figure><img src="/files/NpsNVzr7PkiHzCCpMrJI" alt=""><figcaption></figcaption></figure>

***

## Resources

* <https://lmstudio.ai/blog/claudecode>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.techwithtyler.dev/ai/running-llms-locally/claude-code-with-local-llm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
