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

# Claude Code Setup Guide

> Connect Claude Code to Crazyrouter through the Anthropic Messages API, with full step-by-step instructions from Git and Node.js to installation commands, environment variables, and first-run validation

> 更新日: 2026-06-06

Claude Code is one of the best terminal coding tools to connect to Crazyrouter. It speaks the Anthropic Messages API directly and works especially well for code reading, editing, refactoring, command execution, tool use, and long-context repository analysis.

## Overview

With a few environment variables, Claude Code can send Anthropic requests directly to Crazyrouter:

* recommended protocol: `Anthropic Messages API`
* base URL: `https://api.crazyrouter.com`
* default international API base URL: `https://api.crazyrouter.com`
* auth variable: `ANTHROPIC_API_KEY`
* recommended default model: `claude-opus-4-8`

<Tip>
  Claude Code appends the Anthropic request path itself, so the base URL must stay at the site root: `https://api.crazyrouter.com`. Do not append `/v1` or `/v1/messages`.
</Tip>

<Card title="View the Claude Code one-click setup repository" icon="github" href="https://github.com/xujfcn/crazyrouter-claude-code">
  If you want a script to install Claude Code and write the Crazyrouter environment variables for you, review the crazyrouter-claude-code repository.
</Card>

## Best For

* developers who want Crazyrouter as the backend for Claude Code
* users who want stable tool use, long context, and terminal-first coding workflows
* teams that want Claude Code billed separately from Cursor, Codex, or Aider
* cross-platform setups that need one consistent CLI configuration

## Protocol Used

Recommended protocol: `Anthropic Messages API`

Use:

```text theme={null}
ANTHROPIC_BASE_URL=https://api.crazyrouter.com
```

For the default international API entry, use:

```text theme={null}
ANTHROPIC_BASE_URL=https://api.crazyrouter.com
```

Do not use:

* `https://api.crazyrouter.com/v1`
* `https://api.crazyrouter.com/v1/messages`
* `https://api.crazyrouter.com/v1/complete`
* `https://api.crazyrouter.com/v1`
* `https://api.crazyrouter.com/v1/messages`

## System Requirements And Prerequisites

| Item                | Notes                                                              |
| ------------------- | ------------------------------------------------------------------ |
| Crazyrouter account | Create one at [crazyrouter.com](https://crazyrouter.com)           |
| Crazyrouter token   | Create a dedicated `sk-...` token for Claude Code                  |
| Git                 | `git 2.23+` is recommended for reviewing and rolling back AI edits |
| Node.js             | `Node.js 18+` is recommended                                       |
| Claude Code         | Use a current stable release                                       |
| Claude model access | Allow at least `claude-opus-4-8` on the token                      |

Suggested starter allowlist:

* `claude-opus-4-8`
* `claude-opus-4-8`

## Full Install Paths By OS

### Recommended Windows path

On Windows, the safest path is: `Git` + `Node.js` + `npm global install for Claude Code` + `PowerShell` for environment variables.

Recommended order:

1. Install Git
2. Install Node.js LTS
3. Install Claude Code with npm
4. Set temporary variables in PowerShell
5. Persist user-level variables in PowerShell

Recommended verification:

```powershell theme={null}
git --version
node -v
npm -v
claude --version
where.exe git
where.exe node
where.exe claude
```

If `claude --version` is still not found, close and reopen PowerShell before retrying.

### Recommended macOS path

On macOS, the smoothest path is usually: `Xcode Command Line Tools` + `Homebrew` + `Git` + `Node.js` + `npm global install for Claude Code` + `~/.zshrc` for persistent environment variables.

Recommended order:

1. Install Xcode Command Line Tools
2. Install Homebrew if needed
3. Install Git and Node.js
4. Install Claude Code with npm
5. Persist variables in `~/.zshrc`
6. Open a fresh terminal and verify the binary path

Recommended verification:

```bash theme={null}
git --version
node -v
npm -v
claude --version
which git
which node
which claude
```

### Why you should not append API paths manually

Claude Code uses the Anthropic-native protocol. You only provide the site root:

```text theme={null}
ANTHROPIC_BASE_URL=https://api.crazyrouter.com
```

The default international API entry also uses only the site root:

```text theme={null}
ANTHROPIC_BASE_URL=https://api.crazyrouter.com
```

Do not append `/v1`, `/v1/messages`, or any specific API path the way you would with an OpenAI-compatible client.

If you prefer a script that installs Claude Code and writes the Crazyrouter-related environment variables automatically, see [crazyrouter-claude-code](https://github.com/xujfcn/crazyrouter-claude-code). That repository provides one-click setup scripts for Windows, macOS, and Linux; this guide keeps the full manual path so you can audit each setting.

## Full Setup From Scratch

<Steps>
  <Step title="Step 1: Install Git">
    If Git is not installed yet, install it first before touching Claude Code.

    <Tabs>
      <Tab title="Windows PowerShell">
        ```powershell theme={null}
        winget install --id Git.Git -e --source winget
        git --version
        ```
      </Tab>

      <Tab title="macOS">
        ```bash theme={null}
        xcode-select --install
        git --version
        ```

        If you already use Homebrew, you can also run:

        ```bash theme={null}
        brew install git
        git --version
        ```
      </Tab>

      <Tab title="Ubuntu / Debian">
        ```bash theme={null}
        sudo apt update
        sudo apt install -y git
        git --version
        ```
      </Tab>
    </Tabs>

    After installation, set your global identity once:

    ```bash theme={null}
    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    git config --global init.defaultBranch main
    ```
  </Step>

  <Step title="Step 2: Install Node.js 18+">
    Claude Code depends on Node.js. Verify the installed version before going further.

    <Tabs>
      <Tab title="Windows PowerShell">
        ```powershell theme={null}
        winget install OpenJS.NodeJS.LTS
        node -v
        npm -v
        ```
      </Tab>

      <Tab title="macOS">
        ```bash theme={null}
        brew install node
        node -v
        npm -v
        ```
      </Tab>

      <Tab title="Ubuntu / Debian">
        ```bash theme={null}
        sudo apt update
        sudo apt install -y nodejs npm
        node -v
        npm -v
        ```
      </Tab>
    </Tabs>

    If `node -v` is still below 18 after installation, upgrade through `nvm` or the official Node installer before continuing.
  </Step>

  <Step title="Step 3: Install Claude Code">
    <Tabs>
      <Tab title="Windows PowerShell">
        ```powershell theme={null}
        npm install -g @anthropic-ai/claude-code
        claude --version
        where.exe claude
        ```
      </Tab>

      <Tab title="macOS">
        ```bash theme={null}
        npm install -g @anthropic-ai/claude-code
        claude --version
        which claude
        ```
      </Tab>
    </Tabs>

    <Warning>
      Do not use `sudo npm install -g @anthropic-ai/claude-code`. If global npm permissions are broken, fix the npm/Node environment first instead of forcing a privileged install.
    </Warning>
  </Step>

  <Step title="Step 4: Create a dedicated Crazyrouter token for Claude Code">
    Log in to Crazyrouter and create a separate token named something obvious like `claude-code`.

    For the first pass, allow only:

    * `claude-opus-4-8`
    * `claude-opus-4-8`

    Give it its own budget so it does not share spend with Cursor, Codex, or OpenClaw.
  </Step>

  <Step title="Step 5: Set temporary environment variables in the current terminal">
    Start with a temporary setup first. Once validation succeeds, make it persistent.

    <Tabs>
      <Tab title="macOS / Linux">
        ```bash theme={null}
        export ANTHROPIC_BASE_URL=https://api.crazyrouter.com
        export ANTHROPIC_API_KEY=sk-xxx
        echo $ANTHROPIC_BASE_URL
        echo $ANTHROPIC_API_KEY
        ```
      </Tab>

      <Tab title="Windows PowerShell">
        ```powershell theme={null}
        $env:ANTHROPIC_BASE_URL = "https://api.crazyrouter.com"
        $env:ANTHROPIC_API_KEY = "sk-xxx"
        echo $env:ANTHROPIC_BASE_URL
        echo $env:ANTHROPIC_API_KEY
        ```
      </Tab>
    </Tabs>

    Set `ANTHROPIC_BASE_URL` to the root domain `https://api.crazyrouter.com`, not `https://api.crazyrouter.com/v1`.
  </Step>

  <Step title="Step 6: Persist the environment variables">
    Temporary variables disappear after the shell closes. For regular use, write them to your shell profile.

    <Tabs>
      <Tab title="Linux Bash">
        ```bash theme={null}
        echo 'export ANTHROPIC_BASE_URL=https://api.crazyrouter.com' >> ~/.bashrc
        echo 'export ANTHROPIC_API_KEY=sk-xxx' >> ~/.bashrc
        source ~/.bashrc
        ```
      </Tab>

      <Tab title="macOS / Zsh">
        ```bash theme={null}
        echo 'export ANTHROPIC_BASE_URL=https://api.crazyrouter.com' >> ~/.zshrc
        echo 'export ANTHROPIC_API_KEY=sk-xxx' >> ~/.zshrc
        source ~/.zshrc
        ```
      </Tab>

      <Tab title="Windows PowerShell">
        ```powershell theme={null}
        [System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://api.crazyrouter.com", "User")
        [System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-xxx", "User")

        $env:ANTHROPIC_BASE_URL = "https://api.crazyrouter.com"
        $env:ANTHROPIC_API_KEY = "sk-xxx"
        ```
      </Tab>
    </Tabs>

    Persist `ANTHROPIC_BASE_URL` as `https://api.crazyrouter.com`.

    Then open a fresh terminal and re-check:

    <Tabs>
      <Tab title="macOS / Linux">
        ```bash theme={null}
        claude --version
        echo $ANTHROPIC_BASE_URL
        ```
      </Tab>

      <Tab title="Windows PowerShell">
        ```powershell theme={null}
        claude --version
        echo $env:ANTHROPIC_BASE_URL
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Step 7: Prepare your Git repository">
    Claude Code can edit files and run commands. For the first validation, use a repo you know well.

    If the current folder is not a Git repo yet:

    ```bash theme={null}
    git init
    git add .
    git commit -m "chore: initial snapshot before Claude Code"
    ```

    If it is already an existing repo, at least confirm the current state first:

    ```bash theme={null}
    git status
    ```
  </Step>

  <Step title="Step 8: Launch Claude Code and complete the first validation">
    Enter the project directory and run:

    ```bash theme={null}
    cd /path/to/your/project
    claude
    ```

    For the first validation, use this order:

    1. `Reply with only OK`
    2. `Read the current repository structure only. Do not modify any files.`
    3. `Find obvious typos in the README, but do not edit files yet.`

    If all three work and Crazyrouter logs show matching requests, the setup is good.
  </Step>
</Steps>

## Recommended Model Setup

| Use case                        | Recommended model | Why                                                            |
| ------------------------------- | ----------------- | -------------------------------------------------------------- |
| default daily driver            | `claude-opus-4-8` | best balance of quality, speed, and cost for most coding tasks |
| difficult refactors             | `claude-opus-4-8` | stronger complex reasoning, planning, and code understanding   |
| long-context repo analysis      | `claude-opus-4-8` | stable and strong for long sessions                            |
| cost-sensitive first validation | `claude-opus-4-8` | first get the main path working reliably                       |

Recommended rollout: stabilize normal work on `claude-opus-4-8`, then switch to `claude-opus-4-8` only for genuinely heavier tasks.

## Claude Code で Claude 以外のモデルを使う

Claude シリーズに加えて、Crazyrouter は複数のサードパーティモデルを Anthropic Messages プロトコルに変換して提供しています。Claude Code ではモデル名を切り替えるだけで利用できます。以下は **テキスト / system / ツール呼び出し / ストリーミング SSE の 4 項目を実機検証済み** のモデル一覧です。

### 動作確認済みモデル

| モデル ID                                                                        | 提供元           | ツール呼び出し | ストリーミング | 思考                             | 適した用途                |
| ----------------------------------------------------------------------------- | ------------- | ------- | ------- | ------------------------------ | -------------------- |
| `deepseek-v4-pro`                                                             | DeepSeek      | ✅       | ✅       | —                              | 汎用コーディング・リファクタ、コスパ最良 |
| `deepseek-v4-flash`                                                           | DeepSeek      | ✅       | ✅       | ✅ ネイティブ                        | 思考ブロックを表示する推論用途      |
| `deepseek-v4-pro`                                                             | DeepSeek      | ✅       | ✅       | 推論                             | 数学・複雑なロジック           |
| `deepseek-v4-pro` / `deepseek-v4-pro` / `deepseek-v4-pro` / `deepseek-v4-pro` | DeepSeek      | ✅       | ✅       | —                              | 一般的なテキストタスク          |
| `MiniMax-M2.7`                                                                | MiniMax       | ✅       | ✅       | ⚠️ text ブロック内に `<think>` タグで出力 | 長文コンテキスト・中国語タスク      |
| `MiniMax-M2.7`                                                                | MiniMax       | ✅       | ✅       | ⚠️ text ブロック内                  | 一般会話                 |
| `MiniMax-M2.7`                                                                | MiniMax       | ✅       | ✅       | —                              | 思考なし、出力が最もクリーン       |
| `kimi-k2.5` / `kimi-k2` / `kimi-k2-instruct`                                  | Moonshot Kimi | ✅       | ✅       | —                              | 長文コンテキスト、中国語中心の作業    |
| `kimi-k2-thinking`                                                            | Moonshot Kimi | ✅       | ✅       | 推論                             | 複雑な推論                |
| `kimi-k2-0711-preview` / `kimi-k2-0905-preview`                               | Moonshot Kimi | ✅       | ✅       | —                              | スナップショット版            |

> 検証は `https://api.crazyrouter.com/v1/messages` に対し、`anthropic-version: 2023-06-01` ヘッダと標準の Anthropic Messages リクエストを用いて実施。

<Warning>
  以下のモデルは現在 Anthropic プロトコルで `get_channel_failed` を返します（プロトコル非対応ではなく上流チャンネルが未稼働のため）。当面は `/v1/chat/completions`（OpenAI プロトコル）経由で利用してください：

  * `moonshot-v1-8k` / `moonshot-v1-32k` / `moonshot-v1-128k`
  * `kimi-k2-0905`（`-preview` の付かない版）

  `grok-*`、`coze`、`jimeng`、`baidu`、`zhipu`、`tencent`、`xunfei`、`mistral`、`cohere`、`palm` などのチャンネルは Anthropic プロトコル変換が **未実装** のため、Claude Code では使用できません。
</Warning>

### モデルを切り替える方法

Claude Code は `ANTHROPIC_MODEL` 環境変数、またはセッション内の `/model` コマンドでモデルを選択します。値を上記の任意のモデル ID に置き換えてください。

<Tabs>
  <Tab title="macOS / Linux">
    ```bash theme={null}
    export ANTHROPIC_BASE_URL=https://api.crazyrouter.com
    export ANTHROPIC_API_KEY=sk-xxx

    # 既定で DeepSeek V4 Pro を使う
    export ANTHROPIC_MODEL=deepseek-v4-pro
    claude

    # Kimi 思考版に一時切替
    ANTHROPIC_MODEL=kimi-k2-thinking claude

    # MiniMax に一時切替
    ANTHROPIC_MODEL=MiniMax-M2.7 claude
    ```
  </Tab>

  <Tab title="Windows PowerShell">
    ```powershell theme={null}
    $env:ANTHROPIC_BASE_URL = "https://api.crazyrouter.com"
    $env:ANTHROPIC_API_KEY  = "sk-xxx"

    $env:ANTHROPIC_MODEL = "deepseek-v4-pro"
    claude

    # 一時切替
    $env:ANTHROPIC_MODEL = "kimi-k2-thinking"; claude
    $env:ANTHROPIC_MODEL = "MiniMax-M2.7"; claude
    ```
  </Tab>
</Tabs>

セッション中に切り替えることも可能です：

```text theme={null}
/model deepseek-v4-pro
/model kimi-k2-thinking
/model MiniMax-M2.7
```

### 利用上の注意と既知の差異

* **DeepSeek 系**：プロトコル整合性が最も高い。ツール呼び出し・ストリーミング・`stop_reason=tool_use` が Anthropic 仕様と一致し、`deepseek-v4-flash` は `thinking` ブロックをネイティブ返却するため Claude Code に思考ペインが表示されます。**推奨デフォルト：`deepseek-v4-pro`**。
* **Kimi 系**：長文コンテキストが安定。ツール呼び出しも正常。`kimi-k2-thinking` は推論過程を含み、難しいタスクに有効。
* **MiniMax 系**：価格表で `supported_endpoint_types` に `anthropic` が明示されている数少ないモデルで、プロトコル層との適合性が最も高い。ただし `M2.5` / `M2.7` は思考過程を通常の text ブロック内で **`<think>...</think>` タグ** にラップして返すため、Claude Code がそのまま表示します。回避策：
  1. `MiniMax-M2.7` を使う（思考なし）
  2. system プロンプトで「`<think>` タグや思考過程は出力せず、最終回答のみを返してください」と指示する
* **Token ホワイトリスト**：Claude Code 専用 token にモデルホワイトリストを設定している場合、上記モデルも Crazyrouter 管理画面で許可してください。さもないと `403 model not allowed` が返ります。
* **思考と課金**：思考対応モデル（`-thinking`、`-flash`、`reasoner`、`MiniMax-M2.7`）は出力トークンを多く消費します。Claude Code 専用 token に独立した予算上限を設定することを推奨します。

### モデル動作確認のワンライナー

```bash theme={null}
curl -sS https://api.crazyrouter.com/v1/messages \
  -H "Authorization: Bearer $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "max_tokens": 32,
    "messages": [{"role":"user","content":"reply OK"}]
  }'
```

`200` が返り、`content[].text` が空でなければ Claude Code でそのモデルを利用できます。

## Token Setup Best Practices

| Setting                | Recommendation                           | Notes                                                                                     |
| ---------------------- | ---------------------------------------- | ----------------------------------------------------------------------------------------- |
| dedicated token        | Required                                 | Do not share Claude Code tokens with Cursor, Codex, or OpenClaw                           |
| model allowlist        | Strongly recommended                     | Most Claude Code setups only need 1 to 2 Claude models                                    |
| IP restriction         | Recommended on fixed-egress environments | Be careful on laptops with changing IPs                                                   |
| quota cap              | Strongly recommended                     | Long sessions and tool use can steadily consume budget                                    |
| developer / host split | Recommended                              | Give each developer or shared host its own token                                          |
| incident rotation      | Required                                 | If shell history, recordings, or shared terminals expose the token, rotate it immediately |

## Verification Checklist

* [ ] `git --version` works
* [ ] `node -v` is at least 18
* [ ] `claude --version` works
* [ ] `ANTHROPIC_BASE_URL` is set to `https://api.crazyrouter.com`
* [ ] `ANTHROPIC_API_KEY` is set correctly
* [ ] Claude Code launches successfully
* [ ] the first plain-text request succeeds
* [ ] repository read-only inspection works
* [ ] Crazyrouter logs show the Claude Code traffic
* [ ] token quota and model allowlist match your intended setup

## Common Errors And Fixes

| Symptom                                                                     | Likely cause                                                                                                | Fix                                                               |
| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| `claude: command not found`                                                 | Claude Code did not install cleanly, or the npm global path is not on PATH                                  | reinstall and make sure the global npm bin directory is in PATH   |
| Node version is too old                                                     | local Node.js version is below the requirement                                                              | upgrade to Node.js 18+ and reinstall Claude Code                  |
| `401 unauthorized`                                                          | invalid, expired, or badly pasted `ANTHROPIC_API_KEY`                                                       | create a new token and set the variables again                    |
| `403` or `model not allowed`                                                | the token does not allow the selected Claude model                                                          | allow the required model in Crazyrouter                           |
| `404`                                                                       | base URL was set with `/v1` or `/v1/messages`                                                               | reset it to `https://api.crazyrouter.com`                         |
| logs show `/v1/v1/messages`, `/v1/v1/models`, or `/v1/messages/v1/messages` | Claude Code was given a base URL that already contains `/v1` or a full endpoint, then appended its own path | set `ANTHROPIC_BASE_URL` to the root domain with no path          |
| Claude Code still uses old settings                                         | new environment variables were not reloaded                                                                 | reopen the terminal or run `source ~/.bashrc` / `source ~/.zshrc` |
| Git changes become messy                                                    | no repository snapshot was created before AI edits                                                          | commit an initial snapshot before larger changes                  |
| cost is higher than expected                                                | long context, repeated tool use, and long sessions                                                          | shorten sessions, split tasks, and cap budget per token           |

## Performance And Cost Tips

* start with `claude-opus-4-8`
* switch to `claude-opus-4-8` only for hard architecture analysis or heavy refactors
* validate first in a small repo, not a large production repo
* check `git status` before each new task
* watch Crazyrouter logs and quota more closely when tool use becomes frequent

## FAQ

### Which base URL should I use for Claude Code?

Use the site root: `https://api.crazyrouter.com`

For the default international API entry, use the site root: `https://api.crazyrouter.com`

### Why should I not include `/v1` here?

Because Claude Code appends the Anthropic Messages path itself. You only provide the site root.

### What should I use on Windows?

If you mainly develop from the command line, prefer PowerShell or WSL2. In either case, make sure Git, Node.js, and Claude Code itself are installed correctly first.

### On Windows, should I use PowerShell or Git Bash?

For first-time setup, prefer PowerShell. Environment-variable persistence, `where.exe` checks, and user-level configuration are all more direct there.

### Why should I create a Git snapshot before the first real task?

Because Claude Code can edit files and run commands. A clean snapshot makes review and rollback much easier.

### Which model should I try first?

Start with `claude-opus-4-8`. It is usually the safest baseline.

<Note>
  If your first priority is Claude-family models plus a terminal-first coding workflow, Claude Code should be near the front of your Crazyrouter integration order.
</Note>

<Card title="View the crazyrouter-claude-code repository" icon="github" href="https://github.com/xujfcn/crazyrouter-claude-code">
  Review the one-click setup scripts, README, and latest usage notes.
</Card>
