AI Agent Hub
AI エージェント / プラグイン情報メディア
← 一覧へ
Claude Code Router
CLAUDE

Claude Code Router

Claude Code Router

Claude Code のリクエストを任意のモデルへ転送するルーター。OpenRouter / DeepSeek / Ollama などへブリッジしコスト削減やローカルLLM運用を実現。

原文: Use Claude Code as the foundation for coding infrastructure, allowing you to decide how to interact with the model while enjoying updates from Anthropic.
#router#proxy#model-bridge
REPO STATS

リポジトリ統計

⭐ Stars
33.6k
🍴 Forks
2.7k
⚠️ Open Issues
919
🌿 Language
TypeScript
📄 License
MIT
🕒 最終更新
2026.03.04 (2か月前)
📅 公開日
2025.02.25
🌿 Branch
main
README

ドキュメント

— AI による自動翻訳 (2026.05.07 更新)

Discord


このプロジェクトは Z.ai によってスポンサーされており、GLM CODING PLAN でのサポートを受けています。

GLM CODING PLAN は AI コーディング向けに設計されたサブスクリプションサービスで、月額わずか $10 から始まります。10 以上の人気 AI コーディングツール(Claude Code、Cline、Roo Code など)にアクセスできる GLM-4.7 & (GLM-5 は Pro ユーザーのみ利用可能)モデルを提供し、開発者に一流で高速、安定したコーディング体験を提供します。

GLM CODING PLAN で 10% 割引を取得:https://z.ai/subscribe?ic=8JVLJQFSKB

CLI ツールスタイルの観点からのエージェントツールのプログレッシブディスクロージャー

Claude Code リクエストをさまざまなモデルにルーティングし、リクエストをカスタマイズできる強力なツールです。

✨ 機能

  • モデルルーティング:ニーズに基づいてリクエストを異なるモデルにルーティングできます(例:バックグラウンドタスク、思考、長いコンテキスト)。
  • マルチプロバイダーサポート:OpenRouter、DeepSeek、Ollama、Gemini、Volcengine、SiliconFlow などのさまざまなモデルプロバイダーをサポートしています。
  • リクエスト/レスポンス変換:トランスフォーマーを使用して、異なるプロバイダーのリクエストとレスポンスをカスタマイズできます。
  • 動的モデル切り替え:Claude Code 内で /model コマンドを使用してモデルをオンザフライで切り替えられます。
  • CLI モデル管理:ターミナルから ccr model でモデルとプロバイダーを直接管理できます。
  • GitHub Actions 統合:GitHub ワークフローで Claude Code タスクをトリガーできます。
  • プラグインシステム:カスタムトランスフォーマーで機能を拡張できます。

🚀 始めてみよう

1. インストール

まず、Claude Code がインストールされていることを確認してください:

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

次に、Claude Code Router をインストールします:

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

2. 設定

~/.claude-code-router/config.json ファイルを作成・設定してください。詳しくは config.example.json を参照できます。

config.json ファイルにはいくつかの主要なセクションがあります:

  • PROXY_URL (オプション):API リクエストのプロキシを設定できます。例:"PROXY_URL": "http://127.0.0.1:7890"

  • LOG (オプション):true に設定するとログを有効にできます。false に設定すると、ログファイルは作成されません。デフォルトは true です。

  • LOG_LEVEL (オプション):ログレベルを設定します。利用可能なオプションは:"fatal""error""warn""info""debug""trace" です。デフォルトは "debug" です。

  • ログシステム:Claude Code Router は 2 つの独立したログシステムを使用します:

    • サーバーレベルログ:HTTP リクエスト、API 呼び出し、サーバーイベントは pino を使用して ~/.claude-code-router/logs/ ディレクトリに ccr-*.log のようなファイル名でログされます。
    • アプリケーションレベルログ:ルーティング決定とビジネスロジックイベントは ~/.claude-code-router/claude-code-router.log にログされます。
  • APIKEY (オプション):リクエストを認証するためのシークレットキーを設定できます。設定された場合、クライアントは Authorization ヘッダー(例:Bearer your-secret-key)または x-api-key ヘッダーでこのキーを提供する必要があります。例:"APIKEY": "your-secret-key"

  • HOST (オプション):サーバーのホストアドレスを設定できます。APIKEY が設定されていない場合、セキュリティ上の理由から不正アクセスを防ぐためホストは 127.0.0.1 に強制されます。例:"HOST": "0.0.0.0"

  • NON_INTERACTIVE_MODE (オプション):true に設定すると、GitHub Actions、Docker コンテナ、その他の CI/CD システムなどのインタラクティブでない環境との互換性が有効になります。これは適切な環境変数(CI=trueFORCE_COLOR=0 など)を設定し、自動環境でプロセスがハングするのを防ぐために stdin ハンドリングを設定します。例:"NON_INTERACTIVE_MODE": true

  • Providers:異なるモデルプロバイダーを設定するために使用されます。

  • Router:ルーティングルールを設定するために使用されます。default はデフォルトモデルを指定し、他のルートが設定されていない場合はすべてのリクエストに使用されます。

  • API_TIMEOUT_MS:API 呼び出しのタイムアウトをミリ秒で指定します。

環境変数の補間

Claude Code Router は、安全な API キー管理のための環境変数補間をサポートしています。config.json$VAR_NAME または ${VAR_NAME} 構文を使用して環境変数を参照できます。

{
  "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"]
    }
  ]
}

これにより、機密の API キーを設定ファイルにハードコードする代わりに、環境変数に保持できます。補間はネストされたオブジェクトと配列を通じて再帰的に機能します。

以下に包括的な例を示します。

{
  "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"
  }
}

3. ルーターを使用した Claude Code の実行

ルーターを使用して Claude Code を起動します:

ccr code

注記: 設定ファイルを修正した後は、変更を反映させるためにサービスを再起動する必要があります:

ccr restart

4. UI モード

より直感的なエクスペリエンスのために、UI モードを使用して設定を管理できます:

ccr ui

これにより、config.json ファイルを簡単に表示・編集できるウェブベースのインターフェースが開きます。

UI

5. CLI モデル管理

ターミナルベースのワークフローを好むユーザーのために、対話的な CLI モデルセレクターを使用できます:

ccr model

このコマンドは以下を行うための対話的インターフェースを提供します:

  • 現在の設定を表示:
  • 設定されたすべてのモデルを参照 (default、background、think、longContext、webSearch、image)
  • モデルを切り替える: 各ルータータイプで使用されるモデルを素早く変更
  • 新しいモデルを追加: 既存のプロバイダーにモデルを追加
  • 新しいプロバイダーを作成: 以下を含む完全なプロバイダー設定をセットアップ:
    • プロバイダー名と API エンドポイント
    • API キー
    • 利用可能なモデル
    • 以下をサポートするトランスフォーマー設定:
      • 複数のトランスフォーマー (openrouter、deepseek、gemini など)
      • トランスフォーマーオプション (例: カスタム制限付き maxtoken)
      • プロバイダー固有のルーティング (例: OpenRouter プロバイダー設定)

CLI ツールはすべての入力を検証し、設定プロセスをガイドするための有用なプロンプトを提供することで、JSON ファイルを手動で編集することなく複雑なセットアップを簡単に管理できます。

6. プリセット管理

プリセットを使用することで、設定を簡単に保存・共有・再利用できます。現在の設定をプリセットとしてエクスポートしたり、ファイルまたは URL からプリセットをインストールできます。

# 現在の設定をプリセットとしてエクスポート
ccr preset export my-preset

# メタデータ付きでエクスポート
ccr preset export my-preset --description "My OpenAI config" --author "Your Name" --tags "openai,production"

# ローカルディレクトリからプリセットをインストール
ccr preset install /path/to/preset

# インストール済みのすべてのプリセットをリスト表示
ccr preset list

# プリセット情報を表示
ccr preset info my-preset

# プリセットを削除
ccr preset delete my-preset

プリセット機能:

  • エクスポート: 現在の設定をプリセットディレクトリ (manifest.json を含む) として保存
  • インストール: ローカルディレクトリからプリセットをインストール
  • 機密データの処理: API キーやその他の機密データはエクスポート時に自動的にサニタイズされます ({{field}} プレースホルダーとしてマーク)
  • 動的設定: プリセットはインストール時に必要な情報を収集するための入力スキーマを含めることができます
  • バージョン管理: 各プリセットはアップデート追跡用のバージョンメタデータを含みます

プリセットファイル構造:

~/.claude-code-router/presets/
├── my-preset/
│   └── manifest.json    # 設定とメタデータを含む

7. アクティベートコマンド (環境変数のセットアップ)

activate コマンドを使用すると、環境変数をシェルでグローバルに設定でき、claude コマンドを直接使用したり、Agent SDK を使用して構築されたアプリケーションと Claude Code Router を統合したりできます。

環境変数を有効化するには、以下を実行します:

eval "$(ccr activate)"

— GitHub から取得した原文(一部省略の場合あり)

Discord


This project is sponsored by Z.ai, supporting us with their GLM CODING PLAN.

GLM CODING PLAN is a subscription service designed for AI coding, starting at just $10/month. It provides access to their flagship GLM-4.7 & (GLM-5 Only Available for Pro Users)model across 10+ popular AI coding tools (Claude Code, Cline, Roo Code, etc.), offering developers top-tier, fast, and stable coding experiences.

Get 10% OFF GLM CODING PLAN:https://z.ai/subscribe?ic=8JVLJQFSKB

Progressive Disclosure of Agent Tools from the Perspective of CLI Tool Style

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

✨ 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.

🚀 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.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 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".

  • 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"
  }
}

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 "
RELATED

同じカテゴリの他のツール