Claude Code Router

Enhance Your AI Coding Workflow with Flexible Model Routing

Claude Code Router Illustration

Quick Start with Claude Code Router

Follow these simple steps to get started:

Installation

npm install -g @anthropic-ai/claude-code
npm install -g @musistudio/claude-code-router
ccr code
View Configuration Example (Optional)
{
  "Providers": [
    {
      "name": "openrouter",
      "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",
      "api_base_url": "https://api.deepseek.com/chat/completions",
      "api_key": "sk-xxx",
      "models": ["deepseek-chat", "deepseek-reasoner"],
      "transformer": {
        "use": ["deepseek"],
        "deepseek-chat": {
          "use": ["tooluse"]
        }
      }
    },
    {
      "name": "ollama",
      "api_base_url": "http://localhost:11434/v1/chat/completions",
      "api_key": "ollama",
      "models": ["qwen2.5-coder:latest"]
    },
    {
      "name": "gemini",
      "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",
      "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"
  }
}

What is Claude Code Router?

Claude Code Router appears to be an extension of Claude Code, a command-line tool for agentic coding developed by Anthropic. It enables users to direct coding requests to various AI models, offering more flexibility in how they interact with these models. This can be particularly helpful for tailoring coding assistance to specific needs.

The primary source for understanding Claude Code Router is the GitHub repository musistudio/claude-code-router, which describes it as a foundation for coding infrastructure, enabling interaction with the model while receiving updates from Anthropic. This suggests it is a community-driven project that builds on Anthropic’s official tools, offering additional customization options.

Key Points about Claude Code Router:

Features of Claude Code Router

Claude Code Router’s core functionality revolves around routing requests to various AI models, supporting providers such as OpenRouter, DeepSeek, Ollama, Gemini, and Volcengine. Specific models mentioned include google/gemini-2.5-pro-preview, anthropic/claude-3.5-sonnet, and deepseek-chat, among others. This routing capability is configured via a JSON file, typically located at `~/.claude-code-router/config.json`, allowing users to specify default models, background tasks, thinking/reasoning models, and models for long contexts (exceeding 32K).

Key Capabilities:

Multi-model Routing

Route queries to any provider or model, with dynamic switching using commands like `/model provider,model`.

Specialized Model Roles

Designate models for background tasks, high-reasoning tasks (think mode), and long contexts.

Extensibility

Supports image and web-search tools, detailed logging, and GitHub Actions integration.

Flexible Configuration

Fully customizable via a JSON config file (`~/.claude-code-router/config.json`) for providers and routing rules.

How to Use Claude Code Router

From what we can tell, Claude Code Router lets you choose different AI models for different tasks, such as background tasks or handling large amounts of code. You can install it via npm, configure it through a JSON file, and switch models using simple commands, making it user-friendly for developers.

Installation & Usage:

  1. Prerequisites: Install Node.js and npm (or yarn) on your system.
  2. Install Anthropic’s Claude Code CLI: Run npm install -g @anthropic-ai/claude-code.
  3. Install the Router: Run npm install -g @musistudio/claude-code-router. This adds a ccr command.
  4. Start the Router: Run ccr code. This effectively launches the Claude Code CLI through the router.
  5. (Optional) Configure Routing: Create or edit ~/.claude-code-router/config.json. Define your `Providers` (name, API base URL, API key, available models, any transformers) and your `Router` rules (which provider-model to use by default or for special cases).

After this setup, you simply use Claude Code as normal. The Claude Code Router will intercept each request and forward it according to your config. You can also manually change models at runtime with the /model provider,model command.

Frequently Asked Questions about Claude Code Router

1. What is the main purpose of Claude Code Router?

Claude Code Router is designed to enhance Claude Code by allowing users to route coding requests to various AI models, providing greater flexibility and customization in their AI coding workflows.

2. How does Claude Code Router differ from Claude Code?

Claude Code is Anthropic's command-line tool for agentic coding. Claude Code Router is a community-driven extension that builds upon Claude Code by adding the capability to route requests to different AI models, which Claude Code itself does not natively support.

3. Which AI models and providers does Claude Code Router support?

It supports a variety of providers and models, including OpenRouter, DeepSeek, Ollama (for local models), Google Gemini, and Volcengine. Specific models like google/gemini-2.5-pro-preview, anthropic/claude-3.5-sonnet, and deepseek-chat are mentioned.

4. How is Claude Code Router configured?

Configuration is primarily done via a JSON file, typically located at `~/.claude-code-router/config.json`. This file allows users to define default models, background tasks, thinking/reasoning models, and models for long contexts.

5. Can I switch models dynamically while using Claude Code Router?

Yes, you can switch models on the fly using commands like `/model provider,model` within the Claude Code interface, for example, `/model openrouter,anthropic/claude-3.5-sonnet`.

6. What are the benefits of using specialized model roles?

Specialized model roles allow you to optimize for different tasks. For instance, a simpler model can handle background tasks, a powerful model can be used for reasoning, and a model optimized for long contexts can manage large conversations, balancing speed, cost, and capability.

7. Does Claude Code Router integrate with GitHub Actions?

Yes, it supports integration with GitHub Actions, allowing for streamlined development workflows and automated code reviews or issue bots using any configured model.

8. Is Claude Code Router open-source?

Yes, Claude Code Router is an open-source Node.js CLI released under the MIT License, making it free to use and modify.

9. What are the installation steps for Claude Code Router?

First, install Node.js and npm. Then, install Anthropic’s Claude Code CLI (`npm install -g @anthropic-ai/claude-code`), followed by Claude Code Router (`npm install -g @musistudio/claude-code-router`). Finally, start it with `ccr code`.

10. Can Claude Code Router help reduce costs for AI coding?

Yes, by allowing you to route requests to more cost-effective models for specific tasks (e.g., DeepSeek for reasoning, or local models via Ollama for background tasks), it can significantly reduce the overall cost of AI coding assistance compared to using a single, expensive model.