---
title: "Claude Code integration"
description: "Settings for using Claude Code with MiniRouter."
canonical_url: "https://minirouter.sh/docs/integrations/claude-code"
markdown_url: "https://minirouter.sh/docs/integrations/claude-code.md"
last_updated: "2026-09-26"
---

# Claude Code

Run Anthropic's terminal coding agent on any model in the MiniRouter catalog.

[Get a key](https://minirouter.sh/key)

[Claude Code](https://code.claude.com/docs) is Anthropic's coding agent for the terminal. MiniRouter serves the Anthropic [Messages API](https://minirouter.sh/docs/parameters), so Claude Code runs on any tool-capable model in the [catalog](https://minirouter.sh/models), a [preset](https://minirouter.sh/docs/presets) or a [router](https://minirouter.sh/docs/auto-router), with one balance and per-key [spend limits](https://minirouter.sh/docs/rate-limits).

> **Note:** `ANTHROPIC_BASE_URL` takes the bare host, `https://api.minirouter.sh`. Claude Code adds `/v1/messages` itself.

## Quick start

### 1. Install Claude Code

**macOS / Linux**

```sh
curl -fsSL https://claude.ai/install.sh | bash
```

**Windows**

```powershell
irm https://claude.ai/install.ps1 | iex
```

**Homebrew**

```sh
brew install --cask claude-code
```

### 2. Point Claude Code at MiniRouter

[Create a key](https://minirouter.sh/key), then set these in the shell that launches Claude Code.

**macOS / Linux**

```sh
export MINIROUTER_KEY=mr-live-YOUR-KEY-HERE
export ANTHROPIC_BASE_URL=https://api.minirouter.sh
export ANTHROPIC_AUTH_TOKEN="$MINIROUTER_KEY"
export ANTHROPIC_MODEL="zai/glm-5.3-flash"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=1000000

claude --model "$ANTHROPIC_MODEL"
```

**Windows**

```powershell
$env:MINIROUTER_KEY = "mr-live-YOUR-KEY-HERE"
$env:ANTHROPIC_BASE_URL = "https://api.minirouter.sh"
$env:ANTHROPIC_AUTH_TOKEN = $env:MINIROUTER_KEY
$env:ANTHROPIC_MODEL = "zai/glm-5.3-flash"
$env:CLAUDE_CODE_MAX_CONTEXT_TOKENS = "1000000"

claude --model $env:ANTHROPIC_MODEL
```

| Setting | Value |
| --- | --- |
| `ANTHROPIC_BASE_URL` | `https://api.minirouter.sh`. Use the bare host. Claude Code adds /v1/messages itself. |
| `ANTHROPIC_AUTH_TOKEN` | `$MINIROUTER_KEY`. Shell only. Settings files keep env values literal, so use apiKeyHelper there. |
| `ANTHROPIC_MODEL` | `zai/glm-5.3-flash`. Use the full ID of a tool-capable model from the live catalog, or a preset such as @preset/your-preset. |
| `CLAUDE_CODE_MAX_CONTEXT_TOKENS` | `1000000`. Optional. Claude Code assumes a 200K window for any model it does not know and compacts early; set the model's real window. |

> **Tip:** Give Claude Code its own key, so its spend shows separately in [Usage](https://minirouter.sh/dashboard/usage) and a limit stops only Claude Code.

### 3. Check the connection

Run `/status` inside the session. It names the base URL and `ANTHROPIC_AUTH_TOKEN` as the credential.

> **Warning:** A credential variable replaces your claude.ai login for the session. Unset it to go back to your subscription.

### 4. Send a prompt

Ask for anything, then open [Activity](https://minirouter.sh/dashboard/activity). The request lists its model, tokens and exact cost.

## Switch models

Behind a custom `ANTHROPIC_BASE_URL`, Claude Code passes any model ID through unchecked.

| Where | Scope |
| --- | --- |
| `/model zai/glm-5.3-flash` | Inside a session. Saved as your default. |
| `claude --model zai/glm-5.3-flash` | One run. |
| `ANTHROPIC_MODEL` | Every run from that shell. |

| Model ID | Answers with |
| --- | --- |
| `@preset/your-slug` | Your saved [preset](https://minirouter.sh/docs/presets). Change it in [Presets](https://minirouter.sh/dashboard/presets) without touching the shell. |
| `minirouter/auto:code` | A tool-capable model [Auto](https://minirouter.sh/docs/auto-router) picks. |
| `minirouter/fusion` | The model [Fusion](https://minirouter.sh/docs/fusion) picks per request. |

## Map every model slot

Background work and subagents use their own slots. Point each at a MiniRouter model.

| Variable | Used for |
| --- | --- |
| `ANTHROPIC_DEFAULT_OPUS_MODEL` | `/model opus`. |
| `ANTHROPIC_DEFAULT_SONNET_MODEL` | `/model sonnet`. |
| `ANTHROPIC_DEFAULT_HAIKU_MODEL` | `/model haiku` and background tasks such as session titles. |
| `CLAUDE_CODE_SUBAGENT_MODEL` | Subagents. |

```sh
export ANTHROPIC_DEFAULT_OPUS_MODEL="openai/gpt-6-sol"
export ANTHROPIC_DEFAULT_SONNET_MODEL="zai/glm-5.3-flash"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="openai/gpt-6-luna"
export CLAUDE_CODE_SUBAGENT_MODEL="zai/glm-5.3-flash"
```

## Save it in settings

Settings files keep the setup across shells. `env` values are literal, so `apiKeyHelper` reads the key from your shell instead.

```json
{
  "apiKeyHelper": "echo $MINIROUTER_KEY",
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.minirouter.sh",
    "ANTHROPIC_MODEL": "zai/glm-5.3-flash"
  }
}
```

| File | Applies to |
| --- | --- |
| `~/.claude/settings.json` | You, every project. |
| `.claude/settings.json` | Everyone in the project. Commit it. |
| `.claude/settings.local.json` | You, this project only. |

- A settings-file `env` value wins over the same shell export.
- An exported `ANTHROPIC_AUTH_TOKEN` or `ANTHROPIC_API_KEY` wins over `apiKeyHelper`. Unset them.

> **Warning:** Never put the key in `.claude/settings.json`. That file is committed.

## Run headless

`claude -p` runs one task without the interactive session. Use it in scripts and CI, or see [Automatic code review](https://minirouter.sh/docs/guides/code-review) for a pull request workflow.

```sh
claude -p "Run the tests and fix failures" \
  --model zai/glm-5.3-flash \
  --allowedTools "Bash,Read,Edit" \
  --output-format json
```

| Flag | Does |
| --- | --- |
| `--model` | Any MiniRouter model ID. |
| `--allowedTools` | Tools that run without a prompt. |
| `--output-format json` | Prints the result as JSON. |

The cost Claude Code prints is its own estimate. Your charge is in [Activity](https://minirouter.sh/dashboard/activity).

## Keep spend in check

- [Own key](https://minirouter.sh/dashboard/keys): One key per person or pipeline.
- [Spend cap](https://minirouter.sh/docs/rate-limits): Daily or monthly limit on that key.
- [Activity](https://minirouter.sh/dashboard/activity): Every request and its cost.

Restrict models or filter content with [Guardrails](https://minirouter.sh/docs/guardrails). Rolling out to a team? See [Teams](https://minirouter.sh/docs/teams).

## Recommended models

| Model | Why |
| --- | --- |
| [`zai/glm-5.3-flash`](https://minirouter.sh/models/zai/glm-5.3-flash) | Best current balance of coding ability, agentic performance, context and cost. |
| [`openai/gpt-5.6-sol`](https://minirouter.sh/models/openai/gpt-5.6-sol) | Higher-intelligence option when task quality matters more than spend. |
| [`spacexai/grok-4.6`](https://minirouter.sh/models/spacexai/grok-4.6) | Strong agentic alternative with a 500K-token window. |
| [`google/gemini-3.8-flash`](https://minirouter.sh/models/google/gemini-3.8-flash) | Multimodal coding alternative with a 1M-token window. |

Browse every model in the [catalog](https://minirouter.sh/models).

## Troubleshooting

### Claude Code calls api.anthropic.com instead of MiniRouter

ANTHROPIC_BASE_URL was not exported into the shell that launched Claude Code. Set it to the bare MiniRouter host, then start a new Claude Code process from that shell.

### The selected model name is rejected

Claude aliases such as sonnet and opus are not MiniRouter model IDs. Pass a full author/name ID from the current catalog with --model.

Error: [404 `unknown_model`](https://minirouter.sh/docs/errors#unknown_model).

### "is not a model this version of Claude Code recognizes" at startup

Local metadata only; requests still work. Claude Code assumes a 200K window for unknown models, so set CLAUDE_CODE_MAX_CONTEXT_TOKENS to the model's real window to stop early compaction.

### 401 on every request

Wrong or rotated key. Keys start with mr-live-; after a rotation the old key keeps working for 24 hours, then dies.

Error: [401 `invalid_api_key`](https://minirouter.sh/docs/errors#invalid_api_key).

### 402 before any tokens arrive

Balance below the estimated cost of the request. Top up (from $0.50 with direct Solana payments) — and watch the x-minirouter-balance-usd header, the low-balance signal every response carries.

Error: [402 `insufficient_credits`](https://minirouter.sh/docs/errors#insufficient_credits).

Every error code, with its fix: [Errors](https://minirouter.sh/docs/errors).

## Next steps

- [Presets](https://minirouter.sh/docs/presets): Save a model and its settings under one name.
- [Guardrails](https://minirouter.sh/docs/guardrails): Budgets and model lists per key.
- [Auto router](https://minirouter.sh/docs/auto-router): Let MiniRouter pick the model.
