Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

488 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code Router

A powerful tool to route Claude Code requests to different models and customize any request.

Discord

✨ Features

  • Model Routing: Route requests to different models based on your needs (e.g., background tasks, thinking, long context).
  • Multi-Provider Support: Supports various model providers like OpenRouter, DeepSeek, Ollama, Gemini, Volcengine, and SiliconFlow.
  • Request/Response Transformation: Customize requests and responses for different providers using transformers.
  • Dynamic Model Switching: Switch models on-the-fly within Claude Code using the /model command.
  • CLI Model Management: Manage models and providers directly from the terminal with ccr model.
  • GitHub Actions Integration: Trigger Claude Code tasks in your GitHub workflows.
  • Plugin System: Extend functionality with custom transformers.

🐳 Running as a Local Docker Proxy

The fastest way to run Claude Code Router locally without installing Node.js dependencies is via Docker using just.

Prerequisites: Docker, just (brew install just), and API keys for your chosen providers.

Step 1 — Copy templates

just setup

Creates config.jsonc from config.example.jsonc and .env from .env.example. Both files are gitignored and never committed.

Step 2 — Fill in your values

config.jsonc — set your providers, router rules, and the APIKEY that protects the proxy:

{
  "APIKEY": "my-local-secret",   // shared secret between Claude Code and the proxy
  "HOST": "0.0.0.0",
  "PORT": "3456",
  "Providers": [ /* ... */ ],
  "Router": { /* ... */ }
}

.env — add the API keys referenced by $VAR placeholders in config.jsonc:

ANTHROPIC_API_KEY=sk-ant-...
OPENROUTER_API_KEY=sk-or-...

Step 3 — Build the image

just build

Builds the TypeScript packages and Docker image. Only needed once, and again after code changes.

Step 4 — Start the proxy

just local-proxy

Starts the router on port 3456, mounting the project-local config.jsonc and loading secrets from .env. The image runs directly — no process manager overhead.

Already have ~/.claude-code-router/config.* from an existing CCR install? Use just local-run instead — it mounts your home-dir config directly so you don't need a project-level config.jsonc or .env.

Step 5 — Configure your shell

To route all future Claude Code sessions through the proxy automatically:

just setup local-proxy   # or: just shell-setup

This reads APIKEY and PORT from config.jsonc and appends a guarded block to ~/.zshrc and/or ~/.bashrc / ~/.bash_profile (idempotent — safe to run again):

# CCR: Claude Code Router local proxy
export ANTHROPIC_AUTH_TOKEN="my-local-secret"
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
export NO_PROXY="127.0.0.1"
export DISABLE_TELEMETRY="true"
export DISABLE_COST_WARNINGS="true"

Apply to the current session without reopening your terminal:

source ~/.zshrc   # or source ~/.bashrc

To undo, remove the block between # CCR: Claude Code Router local proxy and the next blank line from your shell config.

Step 6 — Worktree development (optional)

When working in a git worktree or any secondary checkout, you can run an isolated dev container without touching the main ccr-local-proxy:

just worktree-dev

This starts a container named ccr-wt-<directory> on a random free port, using the worktree's own config.json / config.jsonc and .env. To run from inside a worktree when the Justfile lives in the main repo:

just --justfile /path/to/main/Justfile --working-directory $(pwd) worktree-dev

Point Claude Code at the printed URL (e.g. http://127.0.0.1:57031) by setting ANTHROPIC_BASE_URL for that session.

List all worktree containers:

just worktree-list

🚀 Getting Started

1. Installation

First, ensure you have Claude Code installed:

npm install -g @anthropic-ai/claude-code

Then, install Claude Code Router:

npm install -g @musistudio/claude-code-router

2. Configuration

Create and configure your ~/.claude-code-router/config.json file. For more details, you can refer to config.example.jsonc.

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". This is an HTTP tunnel — it wraps the TCP connection to the upstream provider (useful for corporate proxies).
  • PROXY_HOP (optional): A label identifying this CCR instance in a proxy chain (e.g. "edge", "dmz", "internal"). When the metrics plugin is enabled, this value is added as the hop label to ccr_provider_routes_total and ccr_tokens_total, so you can track routing and token usage at every layer. See Proxy Chains for a full walkthrough.
  • LOG (optional): You can enable logging by setting it to true. When set to false, no log files will be created. Default is true.
  • 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 ~/.claude-code-router/logs/ directory with filenames like ccr-*.log
    • Application-level logs: Routing decisions and business logic events are logged in ~/.claude-code-router/claude-code-router.log
  • APIKEY (optional): You can set a secret key to authenticate requests. When set, clients must provide this key in the Authorization header (e.g., Bearer your-secret-key) or the x-api-key header. Example: "APIKEY": "your-secret-key".

Router Debug Endpoint

For local development, you can expose an in-memory log of recent routing decisions via a debug API endpoint.

Set the DEBUG_ROUTER=true environment variable to enable it. The endpoint GET /api/debug/router-logs will return the last 100 routing decisions, each containing timestamp, requestId, sessionId, model, scenario, and tokenCount.

To protect the endpoint with HTTP Basic Auth, also set DEBUG_ROUTER_USER and DEBUG_ROUTER_PASS. If these are not set, the endpoint is unprotected.

DEBUG_ROUTER=true DEBUG_ROUTER_USER=dev DEBUG_ROUTER_PASS=secret ccr start
curl -u dev:secret http://localhost:3456/api/debug/router-logs

Note: This endpoint is intended for local development only. Do not enable it in shared or production environments.

  • HOST (optional): You can set the host address for the server. If APIKEY is not set, the host will be forced to 127.0.0.1 for security reasons to prevent unauthorized access. Example: "HOST": "0.0.0.0".

  • NON_INTERACTIVE_MODE (optional): When set to true, 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.

  • Providers: Used to configure different model providers.

  • Router: Used to set up routing rules. default specifies 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:

{
  "OPENAI_API_KEY": "$OPENAI_API_KEY",
  "GEMINI_API_KEY": "${GEMINI_API_KEY}",
  "Providers": [
    {
      "name": "openai",
      "api_base_url": "https://api.openai.com/v1/chat/completions",
      "api_key": "$OPENAI_API_KEY",
      "models": ["gpt-5", "gpt-5-mini"]
    }
  ]
}

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:

{
  "APIKEY": "your-secret-key",
  "PROXY_URL": "http://127.0.0.1:7890",
  "LOG": true,
  "API_TIMEOUT_MS": 600000,
  "NON_INTERACTIVE_MODE": false,
  "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"]
      }
    },
    {
      "name": "modelscope",
      "api_base_url": "https://api-inference.modelscope.cn/v1/chat/completions",
      "api_key": "",
      "models": ["Qwen/Qwen3-Coder-480B-A35B-Instruct", "Qwen/Qwen3-235B-A22B-Thinking-2507"],
      "transformer": {
        "use": [
          [
            "maxtoken",
            {
              "max_tokens": 65536
            }
          ],
          "enhancetool"
        ],
        "Qwen/Qwen3-235B-A22B-Thinking-2507": {
          "use": ["reasoning"]
        }
      }
    },
    {
      "name": "dashscope",
      "api_base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
      "api_key": "",
      "models": ["qwen3-coder-plus"],
      "transformer": {
        "use": [
          [
            "maxtoken",
            {
              "max_tokens": 65536
            }
          ],
          "enhancetool"
        ]
      }
    },
    {
      "name": "aihubmix",
      "api_base_url": "https://aihubmix.com/v1/chat/completions",
      "api_key": "sk-",
      "models": [
        "Z/glm-4.5",
        "claude-opus-4-20250514",
        "gemini-2.5-pro"
      ]
    }
  ],
  "Router": {
    "default": "deepseek,deepseek-chat",
    "background": "ollama,qwen2.5-coder:latest",
    "think": "deepseek,deepseek-reasoner",
    "longContext": "openrouter,google/gemini-2.5-pro-preview",
    "longContextThreshold": 60000,
    "webSearch": "gemini,gemini-2.5-flash",
    "image": "openrouter,anthropic/claude-sonnet-4"
  }
}

Applying Multiple Providers to the Router

Each slot in the Router object can independently target a different provider,model pair, letting you optimise for cost, speed, and capability across task types — all from a single configuration file.

Slot Triggered when Recommended model type
default All general requests Most capable model available
background Claude Code requests a Haiku-variant model (model name contains haiku) Cheap or local model (e.g. Ollama)
think Plan Mode (extended thinking enabled) Model with strong reasoning / chain-of-thought
longContext Token count exceeds longContextThreshold Model with a large context window
webSearch Request includes a web_search tool Model with native search grounding
image (beta) CCR's built-in image agent activates Vision-capable / multimodal model

Because each provider uses its own api_key: "$ENV_VAR" reference, you only need to export the keys for the providers you actually use — unused providers do not require their variables to be set.

# Keys required for the example config above
export ANTHROPIC_API_KEY=sk-ant-…   # default, think (background), image slots
export OPENROUTER_API_KEY=sk-or-…   # longContext, webSearch slots
export DEEPSEEK_API_KEY=sk-…        # think slot
# Ollama runs locally — no key needed (background slot)

A complete annotated example is provided in config.example.jsonc at the repository root.

When you need fully independent routing profiles (e.g. a cheap "fast" profile and a powerful "research" profile that callers can select at request time), use Routers instead of Router. The two are mutually exclusive — when Routers is present, Router is ignored.

Validating a Router Configuration

There is no dedicated ccr validate command. Validation happens automatically at startup and at request time:

  1. Startup schema check — when ccr start loads config.json, the config is validated against a schema and any violations are printed as warnings before the server starts. Structural issues (wrong field type, invalid provider,model format, missing required Routers.default key) appear here. If a Routers block is present without a "default" key the server will refuse to start.

  2. Token-count probe — with the server running, send a lightweight request to confirm a specific provider,model pair resolves correctly:

    curl -s -X POST http://127.0.0.1:3456/v1/messages/count_tokens \
      -H "x-api-key: your-secret-key" \
      -H "Content-Type: application/json" \
      -d '{"model": "deepseek,deepseek-chat", "messages": [{"role": "user", "content": "hi"}]}'
    # Returns: {"input_tokens": <n>, "tokenizer": "tiktoken"}

    A successful response confirms the provider and model name are recognised. A 400 or 500 indicates a misconfiguration.

  3. Live routing log — set "LOG_LEVEL": "debug" in your config and watch the log file to see which slot and model each request is routed to:

    tail -f ~/.claude-code-router/logs/ccr-*.log | grep "scenarioType\|Using"
  4. Manual model override — inside Claude Code, use /model provider,model-name to force a specific model and confirm the provider responds correctly before relying on automatic routing.

3. Running Claude Code with the Router

Start Claude Code using the router:

ccr code

Note: After modifying the configuration file, you need to restart the service for the changes to take effect:

ccr restart

4. UI Mode

For a more intuitive experience, you can use the UI mode to manage your configuration:

ccr ui

This will open a web-based interface where you can easily view and edit your config.json file.

UI

5. CLI Model Management

For users who prefer terminal-based workflows, you can use the interactive CLI model selector:

ccr model

This command provides an interactive interface to:

  • View current configuration:
  • See all configured models (default, background, think, longContext, webSearch, image)
  • Switch models: Quickly change which model is used for each router type
  • Add new models: Add models to existing providers
  • Create new providers: Set up complete provider configurations including:
    • Provider name and API endpoint
    • API key
    • Available models
    • Transformer configuration with support for:
      • Multiple transformers (openrouter, deepseek, gemini, etc.)
      • Transformer options (e.g., maxtoken with custom limits)
      • Provider-specific routing (e.g., OpenRouter provider preferences)

The CLI tool validates all inputs and provides helpful prompts to guide you through the configuration process, making it easy to manage complex setups without editing JSON files manually.

6. Presets Management

Presets allow you to save, share, and reuse configurations easily. You can export your current configuration as a preset and install presets from files or URLs.

# Export current configuration as a preset
ccr preset export my-preset

# Export with metadata
ccr preset export my-preset --description "My OpenAI config" --author "Your Name" --tags "openai,production"

# Install a preset from local directory
ccr preset install /path/to/preset

# List all installed presets
ccr preset list

# Show preset information
ccr preset info my-preset

# Delete a preset
ccr preset delete my-preset

Preset Features:

  • Export: Save your current configuration as a preset directory (with manifest.json)
  • Install: Install presets from local directories
  • Sensitive Data Handling: API keys and other sensitive data are automatically sanitized during export (marked as {{field}} placeholders)
  • Dynamic Configuration: Presets can include input schemas for collecting required information during installation
  • Version Control: Each preset includes version metadata for tracking updates

Preset File Structure:

~/.claude-code-router/presets/
├── my-preset/
│   └── manifest.json    # Contains configuration and metadata

7. Activate Command (Environment Variables Setup)

The activate command allows you to set up environment variables globally in your shell, enabling you to use the claude command directly or integrate Claude Code Router with applications built using the Agent SDK.

To activate the environment variables, run:

eval "$(ccr activate)"

This command outputs the necessary environment variables in shell-friendly format, which are then set in your current shell session. After activation, you can:

  • Use claude command directly: Run claude commands without needing to use ccr code. The claude command will automatically route requests through Claude Code Router.
  • Integrate with Agent SDK applications: Applications built with the Anthropic Agent SDK will automatically use the configured router and models.

The activate command sets the following environment variables:

  • ANTHROPIC_AUTH_TOKEN: API key from your configuration
  • ANTHROPIC_BASE_URL: The local router endpoint (default: http://127.0.0.1:3456)
  • NO_PROXY: Set to 127.0.0.1 to prevent proxy interference
  • DISABLE_TELEMETRY: Disables telemetry
  • DISABLE_COST_WARNINGS: Disables cost warnings
  • API_TIMEOUT_MS: API timeout from your configuration

Note: Make sure the Claude Code Router service is running (ccr start) before using the activated environment variables. The environment variables are only valid for the current shell session. To make them persistent, you can add eval "$(ccr activate)" to your shell configuration file (e.g., ~/.zshrc or ~/.bashrc).

Providers

The Providers array is where you define the different model providers you want to use. Each provider object requires:

  • name: A unique name for the provider.
  • api_base_url: The full API endpoint for chat completions.
  • api_key: Your API key for the provider.
  • models: A list of model names available from this provider.
  • transformer (optional): Specifies transformers to process requests and responses.

Transformers

Transformers allow you to modify the request and response payloads to ensure compatibility with different provider APIs.

  • Global Transformer: Apply a transformer to all models from a provider. In this example, the openrouter transformer is applied to all models under the openrouter provider.

    {
      "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"
      ],
      "transformer": { "use": ["openrouter"] }
    }
  • Model-Specific Transformer: Apply a transformer to a specific model. In this example, the deepseek transformer is applied to all models, and an additional tooluse transformer is applied only to the deepseek-chat model.

    {
      "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"] }
      }
    }
  • Passing Options to a Transformer: Some transformers, like maxtoken, accept options. To pass options, use a nested array where the first element is the transformer name and the second is an options object.

    {
      "name": "siliconflow",
      "api_base_url": "https://api.siliconflow.cn/v1/chat/completions",
      "api_key": "sk-xxx",
      "models": ["moonshotai/Kimi-K2-Instruct"],
      "transformer": {
        "use": [
          [
            "maxtoken",
            {
              "max_tokens": 16384
            }
          ]
        ]
      }
    }

Available Built-in Transformers:

  • Anthropic:If you use only the Anthropic transformer, it will preserve the original request and response parameters(you can use it to connect directly to an Anthropic endpoint).
  • deepseek: Adapts requests/responses for DeepSeek API.
  • gemini: Adapts requests/responses for Gemini API.
  • openrouter: Adapts requests/responses for OpenRouter API. It can also accept a provider routing parameter to specify which underlying providers OpenRouter should use. For more details, refer to the OpenRouter documentation. See an example below:
      "transformer": {
        "use": ["openrouter"],
        "moonshotai/kimi-k2": {
          "use": [
            [
              "openrouter",
              {
                "provider": {
                  "only": ["moonshotai/fp8"]
                }
              }
            ]
          ]
        }
      }
  • groq: Adapts requests/responses for groq API.
  • maxtoken: Sets a specific max_tokens value.
  • tooluse: Optimizes tool usage for certain models via tool_choice.
  • gemini-cli (experimental): Unofficial support for Gemini via Gemini CLI gemini-cli.js.
  • reasoning: Used to process the reasoning_content field.
  • sampling: Used to process sampling information fields such as temperature, top_p, top_k, and repetition_penalty.
  • enhancetool: Adds a layer of error tolerance to the tool call parameters returned by the LLM (this will cause the tool call information to no longer be streamed).
  • cleancache: Clears the cache_control field from requests.
  • vertex-gemini: Handles the Gemini API using Vertex authentication.
  • chutes-glm Unofficial support for GLM 4.5 model via Chutes chutes-glm-transformer.js.
  • qwen-cli (experimental): Unofficial support for qwen3-coder-plus model via Qwen CLI qwen-cli.js.
  • rovo-cli (experimental): Unofficial support for gpt-5 via Atlassian Rovo Dev CLI rovo-cli.js.

Custom Transformers:

You can also create your own transformers and load them via the transformers field in config.json.

{
  "transformers": [
    {
      "path": "/User/xxx/.claude-code-router/plugins/gemini-cli.js",
      "options": {
        "project": "xxx"
      }
    }
  ]
}

Router

The Router 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. If you're using openrouter, you need to add the :online suffix after the model name.

  • image (beta): Used for handling image-related tasks (supported by CCR’s built-in agent). If the model does not support tool calling, you need to set the config.forceUseImageAgent property to true.

  • You can also switch models dynamically in Claude Code with the /model command: /model provider_name,model_name Example: /model openrouter,anthropic/claude-3.5-sonnet

Routers (header-based multi-router)

Use Routers instead of Router to select a named router config via the x-ccr-route HTTP header. Each key is a named router profile; the "default" key is required and is used when the header is absent or the named key is not found.

When Routers is present, Router is ignored.

{
  "Routers": {
    "default": {
      "default":    "anthropic,claude-sonnet-4-6",
      "background": "ollama,qwen2.5-coder:latest",
      "think":      "deepseek,deepseek-reasoner",
      "longContext": "openrouter,google/gemini-2.5-pro-preview",
      "longContextThreshold": 60000,
      "webSearch":  "openrouter,google/gemini-2.5-flash:online"
    },
    "fast": {
      "default":    "anthropic,claude-haiku-4-5-20251001",
      "background": "ollama,qwen2.5-coder:latest",
      "think":      "deepseek,deepseek-chat"
    },
    "powerful": {
      "default":    "anthropic,claude-opus-4-7",
      "background": "anthropic,claude-haiku-4-5-20251001",
      "think":      "anthropic,claude-opus-4-7",
      "longContext": "openrouter,google/gemini-2.5-pro-preview"
    }
  }
}

Send x-ccr-route: fast to use the lightweight profile. Send x-ccr-route: powerful for the high-quality profile. Omit the header (or send an unrecognised value) to fall back to default.

Note: Routers requires a "default" key. The server will refuse to start if it is missing.

Custom Router

For more advanced routing logic, you can specify a custom router script via the CUSTOM_ROUTER_PATH in your config.json. This allows you to implement complex routing rules beyond the default scenarios.

In your config.json:

{
  "CUSTOM_ROUTER_PATH": "/User/xxx/.claude-code-router/custom-router.js"
}

The custom router file must be a JavaScript module that exports an async function. This function receives the request object and the config object as arguments and should return the provider and model name as a string (e.g., "provider_name,model_name"), or null to fall back to the default router.

Here is an example of a custom-router.js based on custom-router.example.js:

// /User/xxx/.claude-code-router/custom-router.js

/**
 * A custom router function to determine which model to use based on the request.
 *
 * @param {object} req - The request object from Claude Code, containing the request body.
 * @param {object} config - The application's config object.
 * @returns {Promise<string|null>} - A promise that resolves to the "provider,model_name" string, or null to use the default router.
 */
module.exports = async function router(req, config) {
  const userMessage = req.body.messages.find((m) => m.role === "user")?.content;

  if (userMessage && userMessage.includes("explain this code")) {
    // Use a powerful model for code explanation
    return "openrouter,anthropic/claude-3.5-sonnet";
  }

  // Fallback to the default router configuration
  return null;
};
Subagent Routing

For routing within subagents, you must specify a particular provider and model by including <CCR-SUBAGENT-MODEL>provider,model</CCR-SUBAGENT-MODEL> at the beginning of the subagent's prompt. This allows you to direct specific subagent tasks to designated models.

Example:

<CCR-SUBAGENT-MODEL>openrouter,anthropic/claude-3.5-sonnet</CCR-SUBAGENT-MODEL>
Please help me analyze this code snippet for potential optimizations...

Status Line (Beta)

To better monitor the status of claude-code-router at runtime, version v1.0.40 includes a built-in statusline tool, which you can enable in the UI. statusline-config.png

The effect is as follows: statusline

🤖 GitHub Actions

Integrate Claude Code Router into your CI/CD pipeline. After setting up Claude Code Actions, modify your .github/workflows/claude.yaml to use the router:

name: Claude Code

on:
  issue_comment:
    types: [created]
  # ... other triggers

jobs:
  claude:
    if: |
      (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
      # ... other conditions
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Prepare Environment
        run: |
          curl -fsSL https://bun.sh/install | bash
          mkdir -p $HOME/.claude-code-router
          cat << 'EOF' > $HOME/.claude-code-router/config.json
          {
            "log": true,
            "NON_INTERACTIVE_MODE": true,
            "OPENAI_API_KEY": "${{ secrets.OPENAI_API_KEY }}",
            "OPENAI_BASE_URL": "https://api.deepseek.com",
            "OPENAI_MODEL": "deepseek-chat"
          }
          EOF
        shell: bash

      - name: Start Claude Code Router
        run: |
          nohup ~/.bun/bin/bunx @musistudio/claude-code-router@1.0.8 start &
        shell: bash

      - name: Run Claude Code
        id: claude
        uses: anthropics/claude-code-action@beta
        env:
          ANTHROPIC_BASE_URL: http://localhost:3456
        with:
          anthropic_api_key: "any-string-is-ok"

Note: When running in GitHub Actions or other automation environments, make sure to set "NON_INTERACTIVE_MODE": true in your configuration to prevent the process from hanging due to stdin handling issues.

This setup allows for interesting automations, like running tasks during off-peak hours to reduce API costs.

📝 Further Reading

❤️ Support & Sponsoring

If you find this project helpful, please consider sponsoring its development. Your support is greatly appreciated!

ko-fi

Paypal

Alipay WeChat Pay

Our Sponsors

A huge thank you to all our sponsors for their generous support!

(If your name is masked, please contact me via my homepage email to update it with your GitHub username.)

About

Use Claude Code as the foundation for coding infrastructure, allowing you to decide how to interact with the model while enjoying updates from Anthropic.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages