claude-code-router MCP Server: Unifying LLM Access for Claude Code
claude-code-router MCP Server: Unifying LLM Access for Claude Code
The claude-code-router MCP Server provides a flexible routing layer for Claude Code requests, enabling developers to direct interactions to a variety of LLM providers and models. This TypeScript-based server allows you to leverage Claude Code as a foundation for coding infrastructure while maintaining control over model access and configuration.
Routing Claude Code Requests
At its core, claude-code-router acts as a proxy for Claude Code, allowing you to customize and route requests to different models and providers. This means you can continue to use the familiar Claude Code interface while dynamically switching between services like OpenRouter, DeepSeek, Ollama, Gemini, and Volcengine. The server supports changing models and integrates with GitHub Actions for CI/CD workflows.
To get started, first ensure you have Claude Code installed, then install the router:
npm install -g @anthropic-ai/claude-code
npm install -g @musistudio/claude-code-routerOnce installed, you can start Claude Code through the router:
ccr codeConfiguring LLM Providers and Routing Rules
The power of claude-code-router comes from its customizable configuration. You define providers and routing rules in a ~/.claude-code-router/config.json file. This file specifies API bases, keys, and available models for each provider.
Here's an example of a comprehensive configuration:
{
"Providers": [
{
"name": "openrouter",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "sk-xxx",
"models": [
"google/gemini-2.5-pro-preview",
"anthropic/claude-sonnet-4",
"anthropic/claude-3.5-sonnet",
"anthropic/claude-3.7-sonnet:thinking"
],
"transformer": {
"use": ["openrouter"]
}
},
{
"name": "deepseek",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "https://api.deepseek.com/chat/completions",
"api_key": "sk-xxx",
"models": ["deepseek-chat", "deepseek-reasoner"],
"transformer": {
"use": ["deepseek"],
"deepseek-chat": {
// Enhance tool usage for the deepseek-chat model using the ToolUse transformer.
"use": ["tooluse"]
}
}
},
{
"name": "ollama",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "http://localhost:11434/v1/chat/completions",
"api_key": "ollama",
"models": ["qwen2.5-coder:latest"]
},
{
"name": "gemini",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "https://generativelanguage.googleapis.com/v1beta/models/",
"api_key": "sk-xxx",
"models": ["gemini-2.5-flash", "gemini-2.5-pro"],
"transformer": {
"use": ["gemini"]
}
},
{
"name": "volcengine",
// IMPORTANT: api_base_url must be a complete (full) URL.
"api_base_url": "https://ark.cn-beijing.volces.com/api/v3/chat/completions",
"api_key": "sk-xxx",
"models": ["deepseek-v3-250324", "deepseek-r1-250528"],
"transformer": {
"use": ["deepseek"]
}
}
],
"Router": {
"default": "deepseek,deepseek-chat",
"background": "ollama,qwen2.5-coder:latest",
"think": "deepseek,deepseek-reasoner",
"longContext": "openrouter,google/gemini-2.5-pro-preview"
}
}Within the Providers array, each object defines a connection to an LLM service, including its name, api_base_url, api_key, and a list of models it supports. Some providers also include transformer configurations, which can enhance model capabilities, such as enabling tool usage for deepseek-chat.
The Router object defines specific routing rules. For instance, default directs requests to deepseek,deepseek-chat, while longContext routes to openrouter,google/gemini-2.5-pro-preview. This allows developers to map different types of Claude Code requests to the most suitable LLM and provider, optimizing for cost, performance, or specific model capabilities.