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.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.
Overview
With a few environment variables, Claude Code can send Anthropic requests directly to Crazyrouter:- recommended protocol:
Anthropic Messages API - base URL:
https://crazyrouter.com - China-optimized base URL:
https://cn.crazyrouter.com - auth variable:
ANTHROPIC_API_KEY - recommended default model:
claude-sonnet-4-6
View the Claude Code one-click setup repository
If you want a script to install Claude Code and write the Crazyrouter environment variables for you, review the crazyrouter-claude-code repository.
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:
https://crazyrouter.com/v1https://crazyrouter.com/v1/messageshttps://crazyrouter.com/v1/completehttps://cn.crazyrouter.com/v1https://cn.crazyrouter.com/v1/messages
System Requirements And Prerequisites
| Item | Notes |
|---|---|
| Crazyrouter account | Create one at 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-sonnet-4-6 on the token |
claude-sonnet-4-6claude-opus-4-6
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:
- Install Git
- Install Node.js LTS
- Install Claude Code with npm
- Set temporary variables in PowerShell
- Persist user-level variables in PowerShell
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:
- Install Xcode Command Line Tools
- Install Homebrew if needed
- Install Git and Node.js
- Install Claude Code with npm
- Persist variables in
~/.zshrc - Open a fresh terminal and verify the binary path
Why you should not append API paths manually
Claude Code uses the Anthropic-native protocol. You only provide the site root:/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. 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
Step 1: Install Git
If Git is not installed yet, install it first before touching Claude Code.After installation, set your global identity once:
- Windows PowerShell
- macOS
- Ubuntu / Debian
Step 2: Install Node.js 18+
Claude Code depends on Node.js. Verify the installed version before going further.If
- Windows PowerShell
- macOS
- Ubuntu / Debian
node -v is still below 18 after installation, upgrade through nvm or the official Node installer before continuing.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-sonnet-4-6claude-opus-4-6
Step 5: Set temporary environment variables in the current terminal
Start with a temporary setup first. Once validation succeeds, make it persistent.If you use the China-optimized route, set
- macOS / Linux
- Windows PowerShell
ANTHROPIC_BASE_URL to the root domain https://cn.crazyrouter.com, not https://cn.crazyrouter.com/v1.Step 6: Persist the environment variables
Temporary variables disappear after the shell closes. For regular use, write them to your shell profile.If you use the China-optimized route, persist
- Linux Bash
- macOS / Zsh
- Windows PowerShell
ANTHROPIC_BASE_URL as https://cn.crazyrouter.com.Then open a fresh terminal and re-check:- macOS / Linux
- Windows PowerShell
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:If it is already an existing repo, at least confirm the current state first:
Step 8: Launch Claude Code and complete the first validation
Enter the project directory and run:For the first validation, use this order:
Reply with only OKRead the current repository structure only. Do not modify any files.Find obvious typos in the README, but do not edit files yet.
Recommended Model Setup
| Use case | Recommended model | Why |
|---|---|---|
| default daily driver | claude-sonnet-4-6 | best balance of quality, speed, and cost for most coding tasks |
| difficult refactors | claude-opus-4-6 | stronger complex reasoning, planning, and code understanding |
| long-context repo analysis | claude-sonnet-4-6 | stable and strong for long sessions |
| cost-sensitive first validation | claude-sonnet-4-6 | first get the main path working reliably |
claude-sonnet-4-6, then switch to claude-opus-4-6 only for genuinely heavier tasks.
Using Non-Claude Models in Claude Code
Beyond the native Claude family, Crazyrouter exposes several third-party models through the Anthropic Messages protocol. You can use them in Claude Code simply by switching the model name. The list below has been end-to-end verified (text / system / tool use / streaming SSE all pass).Verified working models
| Model ID | Provider | Tool Use | Streaming | Thinking | Best For |
|---|---|---|---|---|---|
deepseek-v4-pro | DeepSeek | ✅ | ✅ | — | General coding & refactors, best price/perf |
deepseek-v4-flash | DeepSeek | ✅ | ✅ | ✅ native | Reasoning with visible thinking blocks |
deepseek-reasoner | DeepSeek | ✅ | ✅ | reasoning | Math / complex logic |
deepseek-chat / deepseek-v3 / deepseek-v3.2 / deepseek-r1 | DeepSeek | ✅ | ✅ | — | General text tasks |
MiniMax-M2.7 | MiniMax | ✅ | ✅ | ⚠️ inside text block as <think> tags | Long-context CN tasks |
MiniMax-M2.5 | MiniMax | ✅ | ✅ | ⚠️ inside text block | General chat |
MiniMax-M2.1 | MiniMax | ✅ | ✅ | — | No thinking, cleanest output |
kimi-k2.5 / kimi-k2 / kimi-k2-instruct | Moonshot Kimi | ✅ | ✅ | — | Long-context, CN-heavy work |
kimi-k2-thinking | Moonshot Kimi | ✅ | ✅ | reasoning | Complex reasoning |
kimi-k2-0711-preview / kimi-k2-0905-preview | Moonshot Kimi | ✅ | ✅ | — | Snapshot versions |
Tested againsthttps://crazyrouter.com/v1/messageswithanthropic-version: 2023-06-01using a standard Anthropic Messages payload.
How to switch models
Claude Code picks the model from theANTHROPIC_MODEL environment variable, or via the in-session /model command. Replace the value with any model ID from the table above.
- macOS / Linux
- Windows PowerShell
Usage notes and known differences
- DeepSeek family: highest protocol fidelity. Tool calls, streaming, and
stop_reason=tool_useall match Anthropic’s spec;deepseek-v4-flashreturns nativethinkingblocks that Claude Code renders as a thinking pane. Recommended default:deepseek-v4-pro. - Kimi family: strong long-context behavior, tool calls work normally.
kimi-k2-thinkingincludes a reasoning trace, useful for hard tasks. - MiniMax family: the only models whose pricing entry explicitly advertises
anthropicinsupported_endpoint_types, so the protocol layer is the most direct fit. However,M2.5/M2.7emit their reasoning as a regular text block wrapped in<think>...</think>tags — Claude Code will display them verbatim. Two ways to avoid this:- Use
MiniMax-M2.1(no thinking trace). - Add a system prompt: “Do not output
<think>tags or your reasoning, only return the final answer.”
- Use
- Token allowlist: if your Claude Code-dedicated token has model allowlisting enabled, add the models above to it in the Crazyrouter dashboard, otherwise you will get
403 model not allowed. - Thinking and billing: thinking-enabled models (
-thinking,-flash,reasoner,MiniMax-M2.5/2.7) consume extra output tokens. Set a separate budget cap on the Claude Code token.
One-line check that a model works
200 response with non-empty content[].text means Claude Code can use this model.
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 --versionworks -
node -vis at least 18 -
claude --versionworks -
ANTHROPIC_BASE_URLis set tohttps://crazyrouter.comorhttps://cn.crazyrouter.com -
ANTHROPIC_API_KEYis 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://crazyrouter.com or https://cn.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-sonnet-4-6 - switch to
claude-opus-4-6only for hard architecture analysis or heavy refactors - validate first in a small repo, not a large production repo
- check
git statusbefore 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://crazyrouter.com
For the China-optimized route, use the site root: https://cn.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 withclaude-sonnet-4-6. It is usually the safest baseline.
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.
View the crazyrouter-claude-code repository
Review the one-click setup scripts, README, and latest usage notes.