Agents & CLIs

Claude Code

Run Claude Code through RouterPlex with claude-code-router.

Claude Code speaks Anthropic's native Messages API, which RouterPlex doesn't expose — so it can't point at us directly. The bridge is Claude Code Router (CCR): it runs a local gateway that translates Claude Code's requests to the OpenAI format and routes each request role to the model you choose.

Works on macOS, Linux, and Windows.

  1. Install. Download the installer for your OS from the CCR releases page (macOS .dmg, Windows installer, Linux package), and install Claude Code itself if you haven't:
bash
npm install -g @anthropic-ai/claude-code
  1. Add RouterPlex as a provider. In CCR open Providers → Add Provider → Other / custom API endpoint and fill in:
text
Name: routerplex
Base URL: https://api.routerplex.com/v1
Protocol: OpenAI compatible (chat/completions)
API Key: sk-... # your RouterPlex key
Models: claude-opus-4-8, claude-sonnet-4-6, claude-haiku-4-5, gemini-3.1-pro

Run the connectivity check if offered, then save.

  1. Map routing roles. In the routing settings, assign a model per role:
RoleUsed forSuggested model
defaultnormal turnsclaude-sonnet-4-6
thinkextended reasoningclaude-opus-4-8
backgroundcheap housekeeping callsclaude-haiku-4-5
longContextrequests above the token thresholdgemini-3.1-pro (1M context)
  1. Start the gateway. Open Server → Start — CCR listens on http://localhost:8080.
  1. Point Claude Code at it. The cross-platform way is Claude Code's own settings file — create ~/.claude/settings.json (Windows: %USERPROFILE%\.claude\settings.json):
json
{
"env": {
"ANTHROPIC_BASE_URL": "http://localhost:8080",
"ANTHROPIC_AUTH_TOKEN": "ccr"
}
}

Or per shell session — macOS/Linux:

bash
export ANTHROPIC_BASE_URL=http://localhost:8080
export ANTHROPIC_AUTH_TOKEN=ccr # any value, unless you set an API key in CCR
claude

Windows (PowerShell):

powershell
$env:ANTHROPIC_BASE_URL = "http://localhost:8080"
$env:ANTHROPIC_AUTH_TOKEN = "ccr"
claude

Run /status inside Claude Code to confirm it's talking to the router.

Option B — classic CLI (headless / servers) #

The npm CLI still works and needs no GUI. Install both:

bash
npm install -g @anthropic-ai/claude-code @musistudio/claude-code-router

Configure RouterPlex in ~/.claude-code-router/config.json (Windows: %USERPROFILE%\.claude-code-router\config.json):

json
{
"Providers": [
{
"name": "routerplex",
"api_base_url": "https://api.routerplex.com/v1/chat/completions",
"api_key": "sk-...",
"models": ["claude-opus-4-8", "claude-sonnet-4-6", "claude-haiku-4-5", "gemini-3.1-pro"]
}
],
"Router": {
"default": "routerplex,claude-sonnet-4-6",
"think": "routerplex,claude-opus-4-8",
"background": "routerplex,claude-haiku-4-5",
"longContext": "routerplex,gemini-3.1-pro",
"longContextThreshold": 60000
}
}

Then start Claude Code through the router (it sets the env vars for you):

bash
ccr code

Switch models inside a session with /model routerplex,claude-opus-4-8.

Tip: give the router its own key with a budget — coding agents can burn tokens fast.