Configure Claude Code with AnRouter
Set up the CLI, the VS Code extension, and both Claude Desktop paths, then verify the route and switch models.
Claude Code sends requests to an Anthropic Messages endpoint, so its Base URL must omit /v1. AnRouter accepts that protocol, but Anthropic does not promise full Claude Code compatibility for non-Claude models. Validate tool use and editing workflows before using one on a real project.
1. Install
# macOS / Linux / WSL
curl -fsSL https://claude.ai/install.sh | bash
claude --version
claude doctor
Windows PowerShell: irm https://claude.ai/install.ps1 | iex
Desktop app: download the installer from claude.ai/download — a .dmg on macOS, an .exe on Windows. Package managers work too: brew install --cask claude-code or winget install Anthropic.ClaudeCode.
2. Get an AnRouter API key
- Register at anrouter.com and sign in.
- Open the dashboard and go to API Keys.
- Create a key and copy it. Treat it like a password — never commit it to a repository.
3. Run a temporary test
export ANTHROPIC_BASE_URL="https://api.anrouter.com"
export ANTHROPIC_AUTH_TOKEN="your_anrouter_api_key"
export ANTHROPIC_MODEL="glm-5.3"
claude
4. Persist the Claude Code settings
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"env": {
"ANTHROPIC_BASE_URL": "https://api.anrouter.com",
"ANTHROPIC_AUTH_TOKEN": "your_anrouter_api_key",
"ANTHROPIC_MODEL": "glm-5.3"
}
}
claude or anthropic. AnRouter IDs such as glm-5.3 do not appear automatically, so specify ANTHROPIC_MODEL explicitly.POST /v1/messages but not Claude Code's optional POST /v1/messages/count_tokens route. Ordinary Messages requests can work, but a client feature that specifically calls server-side token counting may fail. Do not treat one successful chat as proof of full Claude Code compatibility.5. VS Code extension
- Install the official Claude Code extension and first confirm that
claudecan complete a request through AnRouter in a terminal. - The extension and CLI share
~/.claude/settings.jsonby default, so prefer the shared configuration above. - If the extension does not read the shared variables or still prompts for sign-in, press ⌘/Ctrl + Shift + P and run Preferences: Open User Settings (JSON).
- After changing variables, run Developer: Reload Window and send a short test request.
Only when extension-specific settings are needed, merge the following fields into the existing VS Code user settings without deleting other entries:
{
"claudeCode.disableLoginPrompt": true,
"claudeCode.environmentVariables": [
{ "name": "ANTHROPIC_BASE_URL", "value": "https://api.anrouter.com" },
{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "your_anrouter_api_key" },
{ "name": "ANTHROPIC_MODEL", "value": "glm-5.3" }
]
}
6. Claude Desktop: the Code tab
Local Code sessions in Claude Desktop can reuse Claude Code settings. If the desktop app does not inherit shell variables, add them through the Local environment settings. This path still uses ANTHROPIC_BASE_URL=https://api.anrouter.com without /v1.
7. Claude Desktop: third-party inference
- In Claude Desktop, open Help → Troubleshooting → Enable Developer Mode.
- Open Developer → Configure Third-Party Inference… and choose Gateway.
- Set Gateway base URL to
https://api.anrouter.com, enter the AnRouter API key, choose bearer authentication, and select Static API key. - Test the connection, enter an exact AnRouter model ID in Models, then choose Apply locally.
https://api.anrouter.com without /v1; Claude Desktop uses /v1/messages when it sends the request. Open the image at full size for detail.https://api.anrouter.com. Do not enter the complete /v1/messages request URL either. OpenAI-compatible clients such as Hermes and OpenCode use https://api.anrouter.com/v1. A read-only window indicates that the organization has locked these values through managed configuration; contact the administrator.References: Claude Code LLM gateway · VS Code integration · Claude Desktop third-party inference