Claude Code Router (CCR)

repository·main·Indexed 12 days ago

https://github.com/musistudio/claude-code-router

A local model gateway and control plane for centralizing the management of multiple AI agents and providers. CCR version 3.0.20 provides a single stable endpoint for coding tools with features for advanced routing, fallback, and observability, including a CLI and web management UI.

Tokens
77.9K
Snippets
147
Records
339
Agent score
98%

What's inside Claude Code Router

  1. Overview of Claude Code Router configuration areas

    main

    Claude Code Router configuration is organized into several functional areas. To manage your setup, you can navigate through the following main configuration categories:

    Main Configuration Pages

    • Overview dashboard: Monitor system status, account balance, usage widgets, edit layouts, and manage share cards.
    • Provider config: Configure upstream services, including protocols, Base URLs, model lists, and credentials.
    • Agent Config: Define agent launch methods, models, scopes, multi-instance launching, and Bot binding for supported agents (e.g., Claude Code, Codex, OpenCode, Grok CLI, Kimi CLI, Kilo CLI, Pi, ZCode, and Claude Design).
    • API keys: Manage client access keys, set expiration dates, and define local limits.
    • Logs and observability: Access request logs, Agent execution traces, tool calls, and tool results.
    • Server: Configure the local gateway listener, including host, port, proxy mode, system proxy, network capture, and CA certificates.

    Settings Pages

    • Config database location: Manage the SQLite configuration database location used by the desktop app.
    • Tray configuration: Customize the tray icon, balance progress indicators, and tray window widgets.
  2. What is Claude Code Router (CCR)?

    main

    Claude Code Router (CCR) is a local model gateway designed to manage multiple AI agents and providers from a single interface. It acts as a proxy that receives requests from agents (such as Claude Code or Codex), routes them to specified providers based on your configuration, and provides comprehensive logging and observability.

    Core Capabilities

    • Multi-Provider Connectivity: Connect to OpenRouter, DeepSeek, Z.AI, or any service compatible with OpenAI, Anthropic, or Gemini APIs. Supports multi-key rotation and usage tracking.
    • Smart Routing: Implement conditional rules, request rewrites, automatic retries on failure, and fallback models. This allows Claude Code Subagents and Workflows to automatically select appropriate models.
    • Fusion Models: Create new model capabilities by combining a base text model with vision, web search, image/video generation, or custom MCP tools.
    • ToolHub: Consolidate multiple MCP (Model Context Protocol) servers into a single, dynamic tool-resolution entry point.
    • AgentClaw: Expose local agents to IM platforms like Slack, Discord, and Weixin, turning your local machine's agent into a reachable bot.
    • Observability: Detailed request logs capture provider, model, latency, token usage, and cost. The Observability page provides execution traces for each agent.
  3. Overview of Claude Code Router core capabilities

    main

    Claude Code Router (CCR) provides a unified management layer for AI agents and providers. Its core capabilities include:

    • Agents: Managed profiles for various agents (Claude Code, Claude Design, Codex, Grok CLI, Kimi CLI, Kilo Code, OpenCode, Pi, and ZCode) with model overrides, scopes, environment settings, and multi-instance workflows.
    • Providers: Support for presets and custom endpoints, protocol probing, model discovery, connectivity checks, and credential pooling.
    • Models & Routing: A searchable catalog with model descriptions, header/body condition routing, prefixes, rewrites, retries, and ordered fallbacks.
    • Tools & Extensions: Features like Fusion models, ToolHub, built-in browser automation (with Chrome login-state import), and gateway plugins.
    • Access & Quotas: Management of CCR client keys with expiration and limits on local requests, tokens, and images.
    • Observability: Detailed tracking of requests/responses, resolved providers/models, latency, token usage, estimated costs, and agent traces.
    • AgentClaw: Agent relay capabilities through various messaging platforms including Weixin iLink, WeCom, Slack, Discord, Telegram, LINE, Feishu, and DingTalk.
  4. What is Claude Code Router?

    main

    Claude Code Router (CCR) is a local model gateway and control plane designed for programming agents. It provides a stable local entry point for various agents (such as Claude Code, Codex, Grok CLI, Kimi CLI, etc.) to connect to your chosen AI providers.

    Key capabilities include:

    • Unified Management: Manage all agents and providers in one place instead of maintaining separate configurations for each client.
    • Seamless Switching: Change providers or models without modifying individual agent configuration files.
    • Resilience: Maintain request availability through retries, credential pooling, key rotation, and fallback mechanisms.
    • Model Enhancement: Extend existing models via Fusion vision, web search, MCP tools, and ToolHub extensions.
    • Observability: Monitor real-time operations via request logs, including final routing, latency, token usage, cost estimation, and account status.
  5. Core Capabilities of Claude Code Router

    main

    Claude Code Router (CCR) provides a unified management layer for AI agents and providers. Its core capabilities include:

    • Agent Management: Configuration profiles for Claude Code, Claude Design, Codex, Grok CLI, Kimi CLI, Kilo Code, OpenCode, Pi, and ZCode. Supports model coverage, scope management, environment variables, CLI/App entry points, and multi-instance workflows.
    • Provider Management: Built-in presets and custom endpoints, protocol detection, model discovery, connectivity testing, local session/login state import, and support for single keys or credential pools.
    • Model & Routing: Searchable model directory, model descriptions for task selection, Header/Body conditional routing, model prefixing, request rewriting, retries, and ordered fallback mechanisms.
    • Tools & Extensions: Fusion models, ToolHub, built-in browser automation, Chrome session import, wrapper/core gateway plugins, local routing, and virtual models.
    • Access & Quotas: Independent CCR client keys with configurable expiration dates and limits for local requests, tokens, and images.
    • Logging & Observability: Detailed request/response logs, tracking of final provider/model/credential used, status, latency, token usage, cost estimation, tool calls, and Agent execution chains.
    • AgentClaw: Relay Agent capabilities through messaging platforms including WeChat iLink, Enterprise WeChat, Slack, Discord, Telegram, LINE, Feishu, and DingTalk.
  6. What is AgentClaw and how does it work?

    main

    AgentClaw is CCR's agent relay capability that connects a local agent (running on your computer via CCR) to Instant Messaging (IM) platforms like Slack, Discord, Telegram, etc.

    It allows you to:

    • Watch agent output remotely.
    • Continue conversations from mobile devices.
    • Answer permission requests (e.g., shell access) via IM.
    • Take over (Handoff) when your computer is locked.

    Lifecycle & Companion Worker: AgentClaw relies on a companion worker process that follows the lifecycle of the Agent App opened in CCR.

    • Starting: Opening an Agent App (like Claude App or Codex App) from CCR starts the companion worker and the Bot connection.
    • Stopping: Closing the App stops both the worker and the Bot connection.
    • Note on CLI agents: CLI-only agents (like Claude Code or Codex CLI) can route model requests through CCR, but they do not support Bot forwarding or IM relay.
  7. What is ToolHub and when to use it

    main

    ToolHub is a mechanism to collapse multiple MCP (Model Context Protocol) servers into a single, compact entry point (ccr-toolhub). This allows agents to lazy-load task-specific tools only when needed, rather than eagerly loading a massive tool list into the context.

    Key Benefits

    • Context Savings: Large, low-frequency tool catalogs stay out of the agent's primary tool list, reducing context usage and the risk of tool misuse.
    • Lazy Loading: Tools are only resolved and invoked when a task actually requires them.

    Meta Tools Provided

    • tool_hub.resolve: Searches the available MCP tool catalog for the current task.
    • tool_hub.invoke: Calls the specific MCP tool selected for the task.

    When to use: Use ToolHub for tools that are useful occasionally but don't need to be active for every single task. Do not use ToolHub for simple local tasks like file manipulation or basic conversation, as these usually benefit from being eagerly available.

  8. Manage CCR credentials

    main

    CCR uses three distinct types of credentials. Do not confuse them:

    1. CCR_WEB_AUTH_TOKEN: Used for Management UI and RPC authentication. This is a container environment variable. If not set, a random one is generated on every start.
    2. CCR client API key: Used for Model gateway request authentication. Configured via the API Keys page in the UI.
    3. Upstream provider credential: Used by CCR to call model providers (e.g., Anthropic, OpenAI). Configured via the Providers page in the UI.
  9. Understand CCR extension types and surfaces

    main

    CCR uses two distinct extension layers depending on where the code needs to run:

    1. Wrapper plugins (plugins config): Run in CCR Desktop's Electron wrapper process. Use these for local HTTP routes, local backends, proxy capture routing, built-in browser entries, and provider account meters.
    2. Core gateway plugins (providerPlugins or plugins[].coreGateway.providerPlugins): Run in the core gateway runtime. Use these for upstream providers, auth methods, or internal core gateway behavior.

    An extension package can expose three independent surfaces. By default, all three are enabled, but you can disable them by setting them to false in the config:

    SurfaceConfig KeyCapabilities
    Appsurfaces.appsBuilt-in browser entries (via apps config or ctx.registerApp)
    Gatewaysurfaces.gatewayGateway routes, proxy routes, HTTP backends, core gateway config, and virtual model config
    Providersurfaces.providerCore provider plugins and provider account connectors
  10. Use the Observability page to diagnose agents

    main

    The Observability page is used to inspect an agent's execution trace and performance. It is specifically useful for diagnosing:

    • Agents getting stuck or stalled.
    • Unexpected tool results.
    • Slow execution steps.
    • Context flow that does not match expectations.

    The page displays which step called which tool, the tool's return value, the duration of each step, and where failures occurred.

  11. How Claude Code Router works

    main

    CCR acts as an intermediary between your coding agents and your AI providers. Agents send requests to the CCR local gateway, which then applies your configured profiles, routing rules, credentials, and tools to resolve the request to a specific provider, model, and account.

    Workflow Architecture:

    Claude Code · Claude Design · Codex · Grok CLI · Kimi CLI · Kilo Code · OpenCode · Pi · ZCode · Compatible API clients
                                  │
                                  ▼
                     Claude Code Router :3456
              Profiles · Routing · Credentials · Tools · Logs
                                  │
                                  ▼
                 Selected provider, model, and account
    Claude Code · Claude Design · Codex · Grok CLI · Kimi CLI · Kilo Code · OpenCode · Pi · ZCode · Compatible API clients
                                  │
                                  ▼
                     Claude Code Router :3456
              Profiles · Routing · Credentials · Tools · Logs
                                  │
                                  ▼
                 Selected provider, model, and account
  12. Choose between Forwarding and Handoff for Telegram

    main

    When configuring a Telegram bot for an Agent Profile, you can choose how messages are delivered based on your device state:

    FeatureBehaviorBest Use Case
    Forward agent messagesForwards messages regardless of whether your screen is locked or unlocked.When you want full, continuous output in Telegram.
    HandoffOnly forwards messages after the screen locks. Requires Idle seconds and a target device configuration.When you only want lock-screen alerts and don't want interruptions while active.

    Tip: For lock-screen-only alerts, enable Handoff and ensure Forward agent messages is disabled.