Skip to content

Using Agent Router with Claude Code

Install Claude Code

bash
pnpm install -g @anthropic-ai/claude-code
bash
npm install -g @anthropic-ai/claude-code
bash
yarn global add @anthropic-ai/claude-code

Configure Environment Variables

Enter the following commands in your terminal to set environment variables for using AgentRouter's Anthropic API:

bash
# Set AgentRouter's API base URL
export ANTHROPIC_BASE_URL=https://agentrouter.org/

# Set your AgentRouter API key, available at https://agentrouter.org/console/token
export ANTHROPIC_AUTH_TOKEN=sk-xxx
export ANTHROPIC_API_KEY=sk-xxx
powershell
# Set AgentRouter's API base URL
$env:ANTHROPIC_BASE_URL="https://agentrouter.org/"

# Set your AgentRouter API key, available at https://agentrouter.org/console/token
$env:ANTHROPIC_AUTH_TOKEN="sk-xxx"
$env:ANTHROPIC_API_KEY="sk-xxx"
cmd
# Set AgentRouter's API base URL
set ANTHROPIC_BASE_URL=https://agentrouter.org/

# Set your AgentRouter API key, available at https://agentrouter.org/console/token
set ANTHROPIC_AUTH_TOKEN=sk-xxx
set ANTHROPIC_API_KEY=sk-xxx

IMPORTANT

Make sure to replace sk-xxx with the Token provided by AgentRouter. You can get your API Key from the AgentRouter Console.

Launch Directly

After configuring the environment variables, use your terminal to open the project directory you want to work with, then run the following command to start Claude Code:

bash
# Navigate to project directory
cd my-project

# Launch Claude Code directly
claude
powershell
# Navigate to project directory
cd my-project

# Launch Claude Code directly
claude
cmd
# Navigate to project directory
cd my-project

# Launch Claude Code directly
claude

Model Selection

You can control Claude Code's model choice using environment variables:

VariableDescription
ANTHROPIC_MODELPrimary model for Claude Code. Accepts a model alias (e.g., sonnet, haiku) or a full model name.
ANTHROPIC_SMALL_FAST_MODELFast, low-latency model for lightweight/background operations. Deprecated and kept only for backward compatibility.

Recommended model names for example:

claude-sonnet-4-5-20250929 claude-sonnet-4-5-20250514 claude-haiku-4-5-20251001 claude-3-5-haiku-20241022

bash
# Primary model
export ANTHROPIC_MODEL=claude-sonnet-4-5-20250929
# Fast model for lightweight ops (deprecated; use only if needed)
export ANTHROPIC_SMALL_FAST_MODEL=claude-3-5-haiku-20241022

# Launch Claude Code
claude
powershell
# Primary model
$env:ANTHROPIC_MODEL = "claude-sonnet-4-5-20250929"
# Fast model for lightweight ops (deprecated; use only if needed)
$env:ANTHROPIC_SMALL_FAST_MODEL = "claude-3-5-haiku-20241022"

# Launch Claude Code
claude
bash
# Primary model
set ANTHROPIC_MODEL=claude-sonnet-4-5-20250929
# Fast model for lightweight ops (deprecated; use only if needed)
set ANTHROPIC_SMALL_FAST_MODEL=claude-3-5-haiku-20241022

# Launch Claude Code
claude

NOTE

ANTHROPIC_SMALL_FAST_MODEL is deprecated. Migrate when possible to the recommended Haiku defaults. Until migration, it will still be honored for legacy fast/background operations. ANTHROPIC_MODEL remains the primary control for interactive coding and general tasks.

agentrouter.org