> ## Documentation Index
> Fetch the complete documentation index at: https://www.agent37.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Host Claude Code

> Run Anthropic's Claude Code on its own always-on instance, signed in to your own Anthropic account.

The `agent37-claude-code` [template](https://www.agent37.com/docs/agents-api/templates.md) runs Claude Code, Anthropic's coding agent, on an Agent37 instance: an always-on computer with the same chat API, sessions, files, and URLs as every other template. The image is lean, with no browser and no desktop. Claude Code runs on **your own Anthropic account**: Agent37 never supplies or bills Claude model usage, and there is no managed-model option on this template, so connect your account before the first chat turn.

```text title="Paste this into your coding agent" wrap theme={null}
Read https://www.agent37.com/docs/llms-full.txt.
I want Claude Code on its own always-on instance, signed in to my own Anthropic account.
Create it with POST /v1/instances using the agent37-claude-code template; ask me for the token from claude setup-token and pass it as CLAUDE_CODE_OAUTH_TOKEN in env.
Done when a message to https://{instanceId}.agent37.app/v1/responses returns a reply from Claude Code.
My key is in AGENT37_API_KEY.
```

## Create the instance

One call to the Sandbox API at `https://api.agent37.com`:

```bash curl theme={null}
curl -X POST https://api.agent37.com/v1/instances \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "template": "agent37-claude-code" }'
```

The `201` response carries the instance id and its URL, `https://{instanceId}.agent37.app`, which routes to the gateway on port `3737`. The terminal is on port `7681` and the file browser on `8080`, each at `https://{instanceId}-{port}.agent37.app`; see [Instance and preview URLs](https://www.agent37.com/docs/agents-api/urls.md).

## Connect your Claude account

Three ways to connect. Until one of them is done, a chat turn fails with `auth_error`, and `GET /v1/health?agent=claude-code` on the instance URL reports `"healthy": false`.

**Log in from the instance terminal.** Mint a [signed URL](https://www.agent37.com/docs/agents-api/urls.md#browser-access-with-signed-urls) for the terminal port:

```bash curl theme={null}
curl -X POST https://api.agent37.com/v1/instances/ab12cd34ef/signed-url \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "port": 7681 }'
```

Open the returned `url` in a browser and run `claude auth login` in the shell. The login persists on the instance volume, so it survives restarts and updates.

**Set `CLAUDE_CODE_OAUTH_TOKEN`.** The way to go when your app provisions instances headlessly. Generate the token on your own machine with `claude setup-token`, then pass it as [instance env](https://www.agent37.com/docs/agents-api/instance-environment.md) on the create call:

```bash curl theme={null}
curl -X POST https://api.agent37.com/v1/instances \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "template": "agent37-claude-code", "env": { "CLAUDE_CODE_OAUTH_TOKEN": "..." } }'
```

**Set `ANTHROPIC_API_KEY`.** Same shape: pass an Anthropic API key as `env` on create instead.

## Send the first message

Chat is the instance URL plus a path, with the same `sk_live_` key sent as the `X-Agent37-Key` header. `claude-code` is the template's default agent, so there is no `agent` field to pass:

```bash curl theme={null}
curl https://ab12cd34ef.agent37.app/v1/responses \
  -H "X-Agent37-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "input": "Clone github.com/expressjs/express and summarize how routing works." }'
```

Set `"stream": true` to receive the turn as Server-Sent Events instead of one JSON body, and reuse the returned `session_id` to continue the thread. See [Send a message](https://www.agent37.com/docs/agents-api/chat.md) and [Streaming](https://www.agent37.com/docs/agents-api/streaming.md).

## Models

`GET /v1/models` on the instance lists five aliases: `default`, `fable`, `opus`, `sonnet`, and `haiku`, all with provider `anthropic`. Pass one as `model` on a turn. Usage bills to your Anthropic account, not your Agent37 wallet. See [Models](https://www.agent37.com/docs/agents-api/models.md).

## Bring your own model

Claude Code can run on a different model provider entirely: point it at any Anthropic-compatible Messages endpoint with two more `env` entries on the create call. With OpenRouter:

```bash curl theme={null}
curl -X POST https://api.agent37.com/v1/instances \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "template": "agent37-claude-code",
    "env": {
      "ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
      "ANTHROPIC_AUTH_TOKEN": "<your OpenRouter key>"
    }
  }'
```

No Anthropic account is needed: model usage bills the key behind `ANTHROPIC_AUTH_TOKEN`, and health reports healthy once the instance is up. To pin what each [model alias](#models) runs, add role variables as provider slugs: `ANTHROPIC_DEFAULT_SONNET_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_HAIKU_MODEL`, and `ANTHROPIC_DEFAULT_FABLE_MODEL` (for example `"ANTHROPIC_DEFAULT_OPUS_MODEL": "anthropic/claude-opus-5"`, so a turn with `"model": "opus"` runs that slug). Claude Code is built for Anthropic models; pointing a role at another family can mishandle the tool calls it edits files with.

Runnable version: [claude-code-byo-model](https://github.com/agent37-platform/examples/tree/main/claude-code-byo-model) in the examples repo.

## Connect apps

[App integrations](https://www.agent37.com/docs/agents-api/integrations.md) work here like on every system template: drive the `/v1/integrations` endpoints to connect your users' Gmail, Slack, Notion, and hundreds of other apps, and the platform registers its Composio MCP server with Claude Code automatically.

## Custom image

To add your own tools, build on the clean base image, which ships Claude Code and the gateway with no managed integrations, the same pattern as `hermes-base`:

```dockerfile theme={null}
FROM ghcr.io/agent37-platform/claude-code-base:latest
```

See [Build a custom image](https://www.agent37.com/docs/agents-api/custom-image.md).

## Image source

The image behind `agent37-claude-code` is built from a public Dockerfile, [`images/b2b/claude-code`](https://github.com/agent37-platform/templates/tree/main/images/b2b/claude-code) in [agent37-platform/templates](https://github.com/agent37-platform/templates). Read it, or point your coding agent at it, to see exactly what the instance has installed and how the entrypoint configures Claude Code at boot. It is the fastest way to tell whether something comes from the image or from your own setup.

Each published version is a git tag in that repo, `b2b-claude-code/<tag>`, matching `agent37-claude-code@<tag>`. `main` can be ahead of what you run, so take the tag from the template's `image_ref` on [`GET /v1/templates`](https://www.agent37.com/docs/agents-api/templates) and open that tag.

## Troubleshooting

| Symptom | Fix |
| - | - |
| A turn fails with `auth_error` | No Claude account is connected yet: connect one of the three ways above. |
| `GET /v1/health?agent=claude-code` reports `"healthy": false` | Same cause: the harness reports unhealthy until an account is connected. `ok: true` alone only means the gateway is up. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.