Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@openrouter/cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Claude Code for Open Router
A simple and easy to use utility to login to open router and use any model with claude code!
✨ Features
- Model Routing: Route requests to different models based on your needs (e.g., background tasks, thinking, long context).
- Dynamic Model Switching: Switch models on-the-fly within Claude Code using the
/modelcommand.
🚀 Getting Started
1. Installation
First, ensure you have Claude Code installed:
npm install -g @anthropic-ai/claude-codeThen, install Claude Code Router:
npm install -g @openrouter/claude-code2. Configuration
Create and configure your ~/.openrouter/claude-code-proxy.json file. For more details, you can refer to config.example.json.
The config.json file has several key sections:
PROXY_URL(optional): You can set a proxy for API requests, for example:"PROXY_URL": "http://127.0.0.1:7890".LOG(optional): You can enable logging by setting it totrue. When set tofalse, no log files will be created. Default istrue.LOG_LEVEL(optional): Set the logging level. Available options are:"fatal","error","warn","info","debug","trace". Default is"debug".Logging Systems: The Claude Code Router uses two separate logging systems:
- Server-level logs: HTTP requests, API calls, and server events are logged using pino in the
~/.copenrouter/logs/directory with filenames likeopenrouter-*.log - Application-level logs: Routing decisions and business logic events are logged in
~/.openrouter/router.log
- Server-level logs: HTTP requests, API calls, and server events are logged using pino in the
APIKEY(optional): You can set a secret key to authenticate requests. When set, clients must provide this key in theAuthorizationheader (e.g.,Bearer your-secret-key) or thex-api-keyheader. Example:"APIKEY": "your-secret-key".HOST(optional): You can set the host address for the server. IfAPIKEYis not set, the host will be forced to127.0.0.1for security reasons to prevent unauthorized access. Example:"HOST": "0.0.0.0".NON_INTERACTIVE_MODE(optional): When set totrue, enables compatibility with non-interactive environments like GitHub Actions, Docker containers, or other CI/CD systems. This sets appropriate environment variables (CI=true,FORCE_COLOR=0, etc.) and configures stdin handling to prevent the process from hanging in automated environments. Example:"NON_INTERACTIVE_MODE": true.models: Used to set up routing rules.defaultspecifies the default model, which will be used for all requests if no other route is configured.API_TIMEOUT_MS: Specifies the timeout for API calls in milliseconds.
Environment Variable Interpolation
Claude Code Router supports environment variable interpolation for secure API key management. You can reference environment variables in your config.json using either $VAR_NAME or ${VAR_NAME} syntax:
{
"OPENROUTER_API_KEY": "$OPENROUTER_API_KEY"
}This allows you to keep sensitive API keys in environment variables instead of hardcoding them in configuration files. The interpolation works recursively through nested objects and arrays.
Here is a comprehensive example:
{
"OPENROUTER_API_KEY": "$OPENROUTER_API_KEY",
"LOG": true,
"models": {
"default": "deepseek/deepseek-chat",
"background": "qwen/qwen3-30b-a3b",
"think": "deepseek/deepseek-reasoner",
"longContext": "google/gemini-2.5-pro-preview",
"longContextThreshold": 60000,
"webSearch": "google/gemini-2.5-flash:online"
}
}3. Running Claude Code with the Router
Start Claude Code using the router:
openrouter codeNote: After modifying the configuration file, you need to restart the service for the changes to take effect:
openrouter restart
This will open a web-based interface where you can easily view and edit your config.json file.

Models
The models object defines which model to use for different scenarios:
default: The default model for general tasks.background: A model for background tasks. This can be a smaller, local model to save costs.think: A model for reasoning-heavy tasks, like Plan Mode.longContext: A model for handling long contexts (e.g., > 60K tokens).longContextThreshold(optional): The token count threshold for triggering the long context model. Defaults to 60000 if not specified.webSearch: Used for handling web search tasks and this requires the model itself to support the feature. You will also need to add the:onlinesuffix after the model name.
You can also switch models dynamically in Claude Code with the /model command:
/model model_name
Example: /model anthropic/claude-3.5-sonnet
Subagent Routing
For routing within subagents, you must specify a particular provider and model by including <OR-CC-SUBAGENT-MODEL>model</OR-CC-SUBAGENT-MODEL> at the beginning of the subagent's prompt. This allows you to direct specific subagent tasks to designated models.
Example:
<OR-CC-SUBAGENT-MODEL>anthropic/claude-3.5-sonnet</OR-CC-SUBAGENT-MODEL>
Please help me analyze this code snippet for potential optimizations...