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
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.
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.
If a tool is not installed, the terminal says so, with a link to Install Claude Code or Codex.
Claude Code and Codex run as your own programs, outside Hearthscale's sandbox and permission levels. Their own permission prompts apply.
Start a tool from the command line
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:
$ 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:
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
--modelwith the model's id, andANTHROPIC_BASE_URL,ANTHROPIC_MODEL, theANTHROPIC_DEFAULT_*_MODELvariables andCLAUDE_CODE_MAX_CONTEXT_TOKENS, both in its environment and in an inline--settings, which wins over theenvof your own settings files. YourANTHROPIC_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, asANTHROPIC_AUTH_TOKEN, so it never shows in a list of running programs. If theenvof your own Claude Code settings setsANTHROPIC_AUTH_TOKEN, that token replaces the model API's, and every request fails with 401 andThe request does not carry the model API's token. - Codex gets a provider named
hearthscalethrough--configoptions, with the Responses API athttp://127.0.0.1:7286/v1, the model's context asmodel_context_window, the model through--model, and the token inHEARTHSCALE_MODEL_API_TOKEN. These options win over the provider and the model of your own Codex configuration and profiles.
See the command reference for every message and exit status.
Use a model on another device
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 and Add a device.
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
Hearthscale does not install the tools. Install each one from its maker's instructions:
- Claude Code: see Set up Claude Code.
- Codex: see 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
- 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, 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. 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.
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.
What Claude Code still sends to 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:
{
"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 in Claude Code's documentation.
Use the model API from other programs
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.
The example reads the token from the environment variable HEARTHSCALE_MODEL_API_TOKEN, so set it first:
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. |
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": …}}.
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.
Last updated on