Claude Code CLI
This guide shows how to install and configure Claude Code CLI with WorldRouter.
Claude Code is Anthropic’s terminal coding agent. It reads its endpoint and credentials from environment variables, so pointing it at WorldRouter is just a handful of exports — no patches, wrappers, or forks.
For Claude Code, use Claude-family models only (claude-opus-*,
claude-sonnet-*, claude-haiku-* from the Models page). Claude
Code talks to WorldRouter via the Anthropic Messages API; routing OpenAI- or
Gemini-family models through that path may fail or behave unexpectedly. Keep
this in mind whenever you set ANTHROPIC_MODEL or any of the role-specific
model variables in step 2.
Quick Start
1. Install Claude Code CLI
Run Anthropic's native installer (macOS, Linux, WSL).
curl -fsSL https://claude.ai/install.sh | bashOn Windows PowerShell:
PowerShell installer for Windows.
irm https://claude.ai/install.ps1 | iexOr via npm (Node.js 18 or later):
Alternative install via npm — needs Node.js 18 or later.
npm install -g @anthropic-ai/claude-codeOnce the installer finishes, verify the binary is on your PATH:
claude --versionA successful install prints a single line like 1.x.y (Claude Code) (the exact version varies). If you see claude: command not found, re-open your terminal so the new PATH entry is picked up, or follow the installer’s manual PATH instructions.
Keep Claude Code up to date. Anthropic ships new Claude families (e.g.
claude-opus-4-7) frequently, and older Claude Code releases may not yet
recognize the newest model IDs — calls can fail with “unknown model” or fall
back to a stale default. If you plan to use the latest model on the
Models page, run claude update (or re-run the installer) before
setting ANTHROPIC_MODEL so your CLI is on the most recent version.
2. Connect Claude Code CLI to WorldRouter
Claude Code reads its endpoint and credentials from these four environment variables:
ANTHROPIC_BASE_URL— the WorldRouter endpoint.ANTHROPIC_AUTH_TOKEN— your WorldRouter API key.ANTHROPIC_API_KEY— must be set to an empty string. If it has any value, Claude Code prefers it overANTHROPIC_AUTH_TOKENand falls back toapi.anthropic.com.ANTHROPIC_MODEL— the default model. Required because Claude Code’s built-in default isn’t currently served on WorldRouter.
Pick the path that matches what you want
There are four ways to make Claude Code see those four values. Skim the table, then jump to the matching subsection below.
| You want… | Use this method | Scope |
|---|---|---|
| A one-shot test (CI, multi-account swap) | Inline at launch | Just this one claude invocation |
| The current shell only (kick the tires) | Export in current session | Until you close this terminal |
| A specific project | Repo-scoped settings file | Inside one project directory |
| Every Claude Code session, everywhere | Shell profile or user-scoped settings file | All terminals, all projects |
If you are not sure, start with 2.1 Inline at launch to confirm the connection works, then come back and add the 2.3 shell profile version once you are happy.
2.1 Inline at launch (one-shot)
Prepend the variables to a single claude invocation. Nothing is persisted; close the terminal and the values are gone.
ANTHROPIC_BASE_URL="https://inference-api.worldrouter.ai" \
ANTHROPIC_AUTH_TOKEN="your_api_key" \
ANTHROPIC_API_KEY="" \
ANTHROPIC_MODEL="claude-opus-4-6" \
claude2.2 Export in the current shell
Run the exports once in this terminal. Other terminals (and a fresh login) will not see them.
export WORLDROUTER_API_KEY="your_api_key"
export ANTHROPIC_BASE_URL="https://inference-api.worldrouter.ai"
export ANTHROPIC_AUTH_TOKEN="$WORLDROUTER_API_KEY"
export ANTHROPIC_API_KEY="" # Important: must be explicitly empty
export ANTHROPIC_MODEL="claude-opus-4-6"2.3 Shell profile (global, persistent)
Append the same exports to your shell startup file (~/.zshrc for zsh, ~/.bashrc for bash) so every new shell picks them up automatically.
export WORLDROUTER_API_KEY="your_api_key"
export ANTHROPIC_BASE_URL="https://inference-api.worldrouter.ai"
export ANTHROPIC_AUTH_TOKEN="$WORLDROUTER_API_KEY"
export ANTHROPIC_API_KEY="" # Important: must be explicitly empty
export ANTHROPIC_MODEL="claude-opus-4-6"Then reload the profile in this terminal — newly-opened terminals get it for free.
source ~/.zshrc # or: source ~/.bashrc2.4 Settings file (Claude-Code-only, per project or per user)
Persist the same values inside a JSON file Claude Code reads on every launch — no shell configuration needed. Two scopes:
~/.claude/settings.json— applies to every Claude Code session for this user..claude/settings.jsoninside a project — applies only when Claude Code is launched from that project directory; overrides user-scope.
{
"env": {
"ANTHROPIC_BASE_URL": "https://inference-api.worldrouter.ai",
"ANTHROPIC_AUTH_TOKEN": "your_api_key",
"ANTHROPIC_API_KEY": "",
"ANTHROPIC_MODEL": "claude-opus-4-6"
}
}Do not add /v1 to ANTHROPIC_BASE_URL. Claude Code appends the
Anthropic API path itself. This is the opposite of Codex and OpenCode, which
expect the /v1 suffix on OPENAI_BASE_URL.
3. Start your session
Launch Claude Code from a shell where the configuration is in effect.
cd your-project
claude4. Verify
Send a one-shot prompt from a shell where the four env vars (or the settings file) are in effect:
claude "Reply with 'ok' if you can see this."You have a working setup if all three of the checks below hold:
- Claude Code returns a normal answer. A reply such as
ok(or any natural-language sentence) — not an error, not an interactive sign-in prompt — means the request reached WorldRouter and a model responded. - The active model is the Claude-family model you set. Inside an interactive
claudesession, run/status— the active model line should match yourANTHROPIC_MODEL(for example,claude-opus-4-6). If you see a different model orapi.anthropic.com, the env vars did not load (re-check Step 2). - The call shows up in WorldRouter usage. Open the Activity dashboard; the request and its token count should appear within a few seconds, and your credit balance on the Credits page should drop accordingly.
If you only see #1 but not #2 or #3, Claude Code is still talking to Anthropic directly — most often because ANTHROPIC_API_KEY is non-empty and outranking ANTHROPIC_AUTH_TOKEN. Empty it and try again.
How It Works
Claude Code talks to the Anthropic Messages API directly — ${ANTHROPIC_BASE_URL}/v1/messages. WorldRouter is Anthropic-compatible at that endpoint, so Claude Code reaches WorldRouter exactly the way it would reach api.anthropic.com. Usage is billed against your WorldRouter credits and shows up in the dashboard. (Reminder: only Claude-family models — see the warning at the top of this page.)
Configuring Models (optional, advanced)
You only need
ANTHROPIC_MODELto get started. If you followed step 2, you have already set it and Claude Code will route every request to that single model — you can stop here and skip the rest of this section.The role-specific variables below are optional advanced settings for users who want different models for different jobs (for example, Opus for planning, Haiku for background work). They sit alongside the same
ANTHROPIC_BASE_URL/ANTHROPIC_AUTH_TOKEN/ emptyANTHROPIC_API_KEYsetup — they only override which model is used, never how Claude Code authenticates.
| Variable | Role | Required? |
|---|---|---|
ANTHROPIC_MODEL | Main session model. | Yes |
ANTHROPIC_DEFAULT_OPUS_MODEL | Default when Claude Code routes to the Opus tier (/opus, planning). | Optional |
ANTHROPIC_DEFAULT_SONNET_MODEL | Default when Claude Code routes to the Sonnet tier (/sonnet). | Optional |
ANTHROPIC_DEFAULT_HAIKU_MODEL | Default when Claude Code routes to the Haiku tier. | Optional |
ANTHROPIC_SMALL_FAST_MODEL | Background work — message titles, summarization, agent loops. | Optional |
Optional: assign a specific WorldRouter model to each role Claude Code routes to. The main session uses ANTHROPIC_MODEL; subagents and tier-specific commands fall back to the variables below.
# Main session model (required)
export ANTHROPIC_MODEL="claude-opus-4-6"
# Tier-specific defaults (used by /opus, /sonnet, /haiku and similar)
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-4-6"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-4-6"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5-20251001"
# Background work (titles, summarization, agent loops)
export ANTHROPIC_SMALL_FAST_MODEL="claude-haiku-4-5-20251001"All values must be Claude-family model IDs listed on the Models page (case-sensitive).
Troubleshooting
Troubleshooting
▸Authentication error (401 Unauthorized)
echo $ANTHROPIC_AUTH_TOKEN returns your WorldRouter key in the shell that launched Claude Code, and echo $ANTHROPIC_API_KEY is empty. If ANTHROPIC_API_KEY has any value, Claude Code uses it instead of ANTHROPIC_AUTH_TOKEN and the request is rejected. If you edited your shell profile but skipped source ~/.zshrc (or ~/.bashrc), the new values are not yet loaded — reload the profile or open a fresh terminal.▸Want a different model?
ANTHROPIC_MODEL to claude-opus-4-6 because Claude Code's built-in default isn't currently served on WorldRouter. To use a different model, set ANTHROPIC_MODEL to any ID from the WorldRouter Models page (IDs are case-sensitive), or switch models inside Claude Code.▸404 on /v1/messages
/v1 suffix — Claude Code appends it automatically. Copy the URL shown in the Base URL section above.