Claude Code CLI
Run Anthropic's official Claude Code CLI against ToRouter — full agentic coding without an Anthropic-only key.
Claude Code is Anthropic's official terminal agent. It speaks the native Anthropic Messages API, which ToRouter exposes 1:1 — so the CLI works against ToRouter unchanged once you set two environment variables.
Configuration
| Variable | Value |
|---|---|
ANTHROPIC_BASE_URL | https://portal.torouter.ai |
ANTHROPIC_API_KEY | sk-*** |
The model is selected per-session via the CLI flag --model or the /model slash command; default is the current flagship Claude.
Install & run
npm install -g @anthropic-ai/claude-code
export ANTHROPIC_BASE_URL=https://portal.torouter.ai
export ANTHROPIC_API_KEY=sk-***
claudenpm install -g @anthropic-ai/claude-code
$env:ANTHROPIC_BASE_URL = "https://portal.torouter.ai"
$env:ANTHROPIC_API_KEY = "sk-***"
claudeInside the CLI:
> /model claude-opus-4-7
> Refactor src/server.go for readabilityPrompt caching is on by default
Claude Code aggressively uses cache_control on system prompts and recent turns. ToRouter forwards cache_control unchanged for both direct Anthropic and Anthropic-on-OpenRouter routing, so your effective cost on long sessions matches Anthropic's published cached pricing.
Gotchas
- Use
https://portal.torouter.aiforANTHROPIC_BASE_URL— no/v1suffix. Claude Code appends/v1/messagesitself. claude /loginis the OAuth login flow for Anthropic-direct billing; when using ToRouter you skip it entirely — the env vars are sufficient.- Persist the env vars in your shell profile (
~/.zshrc,~/.bashrc) or use a.envloader so new terminal sessions pick them up. - Tool-use heavy sessions can hit per-key rate limits; tune them in the ToRouter console under Keys → Rate limits.