Claude Code CLI

Install Claude Code, connect it to OneRouter's Claude-native endpoint, and verify the active credential and model.

Managing multiple providers?

Use the CC-Switch guide to keep OneRouter and other Claude Code providers side by side and switch them visually.

Install Claude Code

Use the native installer when available. If Node.js is already managed on the machine, the npm package is also supported. Do not run a global npm install with sudo.

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

Verify the installation

If the command is not found immediately after installation, close and reopen the terminal so the updated PATH is loaded.

claude --version

Temporary configuration

Set the variables in the same terminal session that launches Claude Code. ANTHROPIC_AUTH_TOKEN sends a Bearer credential; use ANTHROPIC_API_KEY only when the client specifically requires x-api-key.

export ANTHROPIC_BASE_URL="https://onerouter.com"
export ANTHROPIC_AUTH_TOKEN="YOUR_ONEROUTER_API_KEY"
claude

Persistent configuration

Store personal provider settings in the user-level Claude configuration. Avoid committing credentials to .claude/settings.json; use ignored local configuration when a project-specific override is required.

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://onerouter.com",
    "ANTHROPIC_AUTH_TOKEN": "YOUR_ONEROUTER_API_KEY"
  }
}

Optional model mapping

Claude Code uses Haiku, Sonnet, and Opus as internal speed tiers. Map each tier only when you want explicit control, and use complete OneRouter model slugs available to the current key. Keep the default model aligned with one of the mapped tiers.

Check Text & Chat Models or GET /v1/models before saving. A model name copied from another provider may not be available to your OneRouter key.

{
  "ANTHROPIC_DEFAULT_HAIKU_MODEL": "<FAST_MODEL_SLUG>",
  "ANTHROPIC_DEFAULT_SONNET_MODEL": "<BALANCED_MODEL_SLUG>",
  "ANTHROPIC_DEFAULT_OPUS_MODEL": "<STRONG_MODEL_SLUG>",
  "ANTHROPIC_MODEL": "<DEFAULT_MODEL_SLUG>"
}

Verify the connection

Start Claude Code and run /status. Confirm the Anthropic base URL, credential source, and selected model. Then send a short prompt such as Reply with OK only.

Troubleshooting

SymptomHow to fix it
The tool asks you to sign inSet the key before the first launch and start Claude from the same terminal.
/status has no base URLThe environment did not reach the process; reopen the terminal and export it again.
401Check whether Bearer and x-api-key modes match the variable you selected.
404Use the API root only; do not append /v1 or duplicate /v1/messages.
Model is missingUse the complete model slug and verify key permissions.