# Use Claude Code and Codex with your models

Run Claude Code or Codex on a local model of your Hearthscale Server, on this device or on another of your devices, from Settings → Model API or with one command.


Claude Code and Codex can use the local models of your Hearthscale Servers in place of a cloud model. The model can run on this device or on another of your devices, such as a device with a large graphics card while you work on a laptop.

Turn on the model API in **Settings → Model API**, then start a tool from that page or with `hearthscale launch`. Hearthscale changes no file of either tool. When you start `claude` or `codex` on their own, they keep your usual setup and account.

## Set it up in Settings {#settings}

::::steps
:::step

### Turn on the model API

Open **Settings → Model API** and turn on **Let programs on this device use your models**. The page shows the **Address** and the **Token**, and lists the chat models of your devices under the name of each device, each with its id.

:::
:::step

### Choose a model

Under **Coding tools**, choose a model in the menu on the card of Claude Code or Codex. Choose a model that can use tools, with a long context. See [Choose a model](#model).

:::
:::step

### Open a folder

Choose **Open in a folder…** and select your project's folder. Your default terminal app opens in that folder, and the tool starts there on the model you chose.

:::
::::

If a tool is not installed, the terminal says so, with a link to [Install Claude Code or Codex](#install).

:::callout{type="info" title="The tools run with your own access"}
Claude Code and Codex run as your own programs, outside Hearthscale's sandbox and [permission levels](/docs/app/settings/permissions). Their own permission prompts apply.
:::

## Start a tool from the command line {#launch}

In a terminal, go to your project's folder and run `hearthscale launch claude` or `hearthscale launch codex`. If the model API is off, the command turns it on and says so. Without `--model`, it lists the models and asks for a number:

```text
$ hearthscale launch claude
the model API is now on at http://127.0.0.1:7286
  1  Qwen3.5 9B, This device
  2  Qwen3.6 35B-A3B, desk
model number: 2
```

To skip the question, name the model by its id. Words after `--` go to the tool unchanged:

```sh
hearthscale launch claude --model qwen3.5-9b
hearthscale launch codex --model qwen3.6-35b-a3b@desk -- exec "Add a README"
```

`hearthscale model-api` shows whether the model API is on, its address and token, and each model with its id, its device and its context in tokens. `hearthscale model-api on` and `off` turn it on and off, and `hearthscale model-api new-token` replaces the token.

The command sets up only the tool it starts:

- **Claude Code** gets `--model` with the model's id, and `ANTHROPIC_BASE_URL`, `ANTHROPIC_MODEL`, the `ANTHROPIC_DEFAULT_*_MODEL` variables and `CLAUDE_CODE_MAX_CONTEXT_TOKENS`, both in its environment and in an inline `--settings`, which wins over the `env` of your own settings files. Your `ANTHROPIC_API_KEY`, your Bedrock, Vertex AI or Foundry setup, and the other variables that would send its requests elsewhere or name another model do not apply to it. The token goes only in its environment, as `ANTHROPIC_AUTH_TOKEN`, so it never shows in a list of running programs. If the `env` of your own Claude Code settings sets `ANTHROPIC_AUTH_TOKEN`, that token replaces the model API's, and every request fails with 401 and `The request does not carry the model API's token.`
- **Codex** gets a provider named `hearthscale` through `--config` options, with the Responses API at `http://127.0.0.1:7286/v1`, the model's context as `model_context_window`, the model through `--model`, and the token in `HEARTHSCALE_MODEL_API_TOKEN`. These options win over the provider and the model of your own Codex configuration and profiles.

See the [command reference](/docs/developers/reference/cli#launch) for every message and exit status.

## Use a model on another device {#other-devices}

The model API serves the chat models of every Hearthscale Server that Hearthscale on this device uses: the Servers on your account, and the Servers you added that allowed this device. See [Models on your other devices](/docs/app/extend/models#computers) and [Add a device](/docs/app/extend/models#add-computer).

A model on this device has an id made from its name, such as `qwen3.5-9b`. A model on another device adds `@` and that device's name, such as `qwen3.6-35b-a3b@desk`. Capital letters become lower case. Each run of characters other than the letters a to z, the digits, `.` and `_` becomes one hyphen. When another model already has an id, the new one gets `-2`, `-3` and so on before the `@` part. A model keeps its id: after a restart, when other models arrive, and when its device gets a new name, so a tool that you set up once keeps the same model.

The tool runs on this device. It reads and changes files here and runs its commands here. Only its requests to the model go to the other device, over the encrypted connection that Hearthscale already uses for that device's models. That device gets no access to this device's files, commands or credentials.

The other device must be on, with its Server running, and reachable from this device. If it is not, each request fails with `desk does not answer. It may be off, or not on a network this device can reach.`, and `hearthscale launch` stops with the same words. The model keeps its id while the device is off. In **Settings → Providers**, the device's row then says **Offline**. If the other device no longer allows this device, the request fails with `desk has not approved this device. Approve it on that device, then check again.`

## Install Claude Code or Codex {#install}

Hearthscale does not install the tools. Install each one from its maker's instructions:

- **Claude Code**: see [Set up Claude Code](https://code.claude.com/docs/en/setup).
- **Codex**: see [Codex CLI](https://learn.chatgpt.com/docs/codex/cli).

Hearthscale finds each tool by its command, `claude` or `codex`, on your `PATH`. After you install one, open a new terminal before you run `hearthscale launch`, so that the terminal finds the new command.

A tool started this way sends the model API's token with its requests, not your Claude or ChatGPT sign-in, so your plan's usage limits do not apply.

## Choose a model {#model}

- **The model must be able to use tools.** Claude Code and Codex work through tool calls, such as reading a file or running a command. In the Server's [Explore](/docs/server/models/explore), an icon on a result shows that the model can use tools.
- **The model needs a long context, about 64,000 tokens or more.** Both tools send long instructions and the descriptions of their tools with every request.

The context depends on the memory that is free. With no **Context length** set, the Server gives a model the longest context at which every layer fits on the graphics card, up to the model's limit. A smaller model, or a smaller quantization of it, leaves room for a longer context. To ask for a longer one, set **Context length** in the model's [Load settings](/docs/server/models/settings#load). The layers that do not fit on the card then go to system memory, which makes the model slower. See [How the Server plans a load](/docs/server/models/memory#plan).

When a tool starts, Hearthscale gives it the model's context: the context the model is loaded with, or the context its Server plans for it in the memory that is free. The tool then compacts the conversation before it grows past that length. After you change a model's context, start the tool again so that it reads the new length.

To compare models for coding, with their scores on independent tests and the memory of their context for each size of graphics card, see [Best local LLM for coding](/blog/local-llm-for-coding).

## What Claude Code still sends to Anthropic {#anthropic}

Your prompts, your files and the model's answers go only to your Servers. Claude Code still makes some requests of its own: usage metrics, reports you send with `/feedback`, session quality surveys, its update checks, and a safety check that sends Anthropic the host name of each address its WebFetch tool opens.

To turn these off, add this to Claude Code's settings file, `~/.claude/settings.json`:

```json title="~/.claude/settings.json"
{
  "env": {
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
  },
  "skipWebFetchPreflight": true
}
```

`CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` turns off all of these but the WebFetch check, automatic updates included, so update Claude Code yourself with `claude update`. `skipWebFetchPreflight` turns off the WebFetch check. The settings apply to every Claude Code session, also with your Anthropic account. See [Data usage](https://code.claude.com/docs/en/data-usage#telemetry-services) in Claude Code's documentation.

## Use the model API from other programs {#api}

Any program that lets you set a base URL for OpenAI's or Anthropic's API can use the model API. It answers only on this device, and only while Hearthscale runs. Apps in Hearthscale cannot reach it; they use your models through Hearthscale itself, with their permissions.

| Setting                      | Value                                                                    |
| ---------------------------- | ------------------------------------------------------------------------ |
| Base URL for OpenAI's API    | `http://127.0.0.1:7286/v1`                                               |
| Base URL for Anthropic's API | `http://127.0.0.1:7286`                                                  |
| API key                      | The token from **Settings → Model API**, or from `hearthscale model-api` |
| Model                        | A model's id, as `GET /v1/models` lists it                               |

Every request carries the token, as `Authorization: Bearer <token>` or as `x-api-key: <token>`.

| Method and path                  | Purpose                                                                   |
| -------------------------------- | ------------------------------------------------------------------------- |
| `GET /v1/models`                 | The chat models of your devices, each with its `id`, `name` and `device`. |
| `POST /v1/chat/completions`      | Chat in the shape of OpenAI's Chat Completions API.                       |
| `POST /v1/responses`             | Chat in the shape of OpenAI's Responses API.                              |
| `POST /v1/messages`              | Chat in the shape of Anthropic's Messages API.                            |
| `POST /v1/messages/count_tokens` | Count the input tokens of a Messages request.                             |

Each request goes to the Server of the model it names, and the answer, streamed or whole, comes back as that Server sends it. The options of each route are those of the Server's API. See [Endpoints](/docs/server/api/endpoints).

The example reads the token from the environment variable `HEARTHSCALE_MODEL_API_TOKEN`, so set it first:

```sh
curl http://127.0.0.1:7286/v1/chat/completions \
  -H "Authorization: Bearer $HEARTHSCALE_MODEL_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen3.5-9b", "messages": [{"role": "user", "content": "Hello!"}]}'
```

| Status | What it means, and what to do                                                                                                                |
| ------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| 400    | The body is not a JSON object, or it names no model. The Server also answers 400 for a request it cannot read.                               |
| 401    | The request has no token, or not the current one. Copy the token again.                                                                      |
| 403    | The request names a host other than `127.0.0.1` or `localhost`, as a page in a browser can.                                                  |
| 404    | The model API has no model with this id. Check it against `GET /v1/models`.                                                                  |
| 413    | The body is larger than 50 MiB. Send fewer or smaller pictures.                                                                              |
| 503    | The device of the model is off, its Server does not answer, or it no longer allows this device. The message names the device and what to do. |
| Other  | The Server's own answer. See [If a request fails](/docs/server/api#if-a-request-fails).                                                      |

The model API's own errors have the shape of the route: Anthropic's on `/v1/messages` and `/v1/messages/count_tokens`, and OpenAI's `error` object on the others. The Server's errors have Anthropic's shape on `/v1/messages` and `/v1/messages/count_tokens` and OpenAI's on `/v1/responses`. On `/v1/chat/completions` they have the Server's own shape, `{"error": {"code": …, "message": …}}`.

:::callout{type="warn" title="Keep the token private"}
Anyone with the token can use your models from this device. Choose **New token** in **Settings → Model API** to stop the old one from working.
:::
