Skip to main content

Local-first, free-first, fallback-built-in LLM router. Claude Code / OpenAI compatible.

Project description

CodeRouter

ローカル LLM で Claude Code を動かすと壊れる問題、
ルーター 1 つで直します。

CI version python deps license

English · 日本語 · 10 分で動かす · 設計詳細


何ができるか — 30 秒で

あなたのエージェント (Claude Code / gemini-cli / codex)
        │
        ▼
  ┌─ CodeRouter ─┐
  │  翻訳 + 修復  │──→  ① ローカル (Ollama — 無料・最速)
  │  ガード + 監視 │──→  ② 無料クラウド (OpenRouter / NIM)
  │  自動フォールバック │──→  ③ 有料 (Claude — opt-in 時のみ)
  └──────────────┘

やってくれること:

  • ローカルモデルが壊した tool calling を Claude Code に届く前に修復する
  • 1 つ目が落ちたら自動で次のプロバイダに切り替える
  • 有料 API は明示的に許可したときだけ使う (デフォルトは無料のみ)
  • 8 時間回しても止まらないように 6 種類のガードで守る
  • 何がおかしいか coderouter doctor コマンド一発で診断する

インストール (3 行)

# 1. サンプル設定を置く
mkdir -p ~/.coderouter
curl -fsSL https://raw.githubusercontent.com/zephel01/CodeRouter/main/examples/providers.yaml \
  > ~/.coderouter/providers.yaml

# 2. 起動 (Python 3.12+)
uvx --from coderouter-cli coderouter serve --port 8088

恒久インストールしたい場合: uv tool install coderouter-cli


Claude Code で使う

# ターミナル 1
coderouter serve --port 8088

# ターミナル 2
ANTHROPIC_BASE_URL=http://localhost:8088 ANTHROPIC_AUTH_TOKEN=dummy claude

これだけ。Claude Code はいつも通り動きますが、裏ではローカルの Ollama が答えています。


自分に必要?

あなたの状況 CodeRouter は?
Claude Code + ローカル Ollama で tool calling が壊れる 必須 — wire 変換 + tool 修復
Claude Code + ローカルで長時間回すと止まる 便利 — 6 系統ガード + self-healing
codex / gemini-cli + Ollama 直繋ぎで動いてる オプション — フォールバックが欲しいなら
Claude API を直接叩いてて問題ない 不要

詳細は → 要否判定ガイド


主な機能

接続と修復

機能 何をしてくれるか
Wire 翻訳 Claude Code (Anthropic形式) ↔ Ollama (OpenAI形式) を自動変換
Tool-call 修復 ローカルモデルがテキストで吐いた JSON を正しい tool_use ブロックに復元
3 層フォールバック ローカル → 無料クラウド → 有料の順に自動切替
出力フィルタ <think> タグ漏れ、stop marker 漏れを自動除去

長時間運用ガード

ガード 何から守るか
Context Budget メッセージが溜まりすぎて context window 溢れ → 自動 trim
Drift Detection モデルの応答品質が徐々に劣化 → 別 provider に切替 or KV cache flush
Self-healing backend が落ちた → 自動除外 + restart + 回復 probe で自動復帰
Tool Loop Guard 同じツールを無限に呼び続ける → 検知して停止
Memory Pressure GPU メモリ不足を検知 → 軽量モデルに切替
Mid-stream Guard 応答途中で落ちた → 溜まったテキストを安全に返却

診断と可視化

機能 何がわかるか
coderouter doctor プロバイダの問題を 6 プローブで即診断 + 修正パッチ出力
/dashboard ブラウザで今何が起きてるかリアルタイム確認
coderouter audit guard 発火履歴を検索
coderouter replay provider 切替の効果を統計比較 (A/B 分析)
Continuous Probe idle 時も定期的に backend を監視

設定例 (最小)

# ~/.coderouter/providers.yaml
default_profile: claude-code

profiles:
  - name: claude-code
    providers: [ollama-local, openrouter-free]

providers:
  - name: ollama-local
    kind: openai_compat
    base_url: http://localhost:11434/v1
    model: qwen3-coder:7b

  - name: openrouter-free
    kind: openai_compat
    base_url: https://openrouter.ai/api/v1
    model: qwen/qwen3-coder:free
    api_key_env: OPENROUTER_API_KEY

もっと詳しい設定 → 利用ガイド · 設計詳細


ドキュメント

やりたいこと ドキュメント
すぐ動かす Quickstart
使いこなす 利用ガイド
無料で回す 無料枠ガイド
詰まった トラブルシューティング
設計を知りたい アーキテクチャ詳細
全リリース履歴 CHANGELOG

English: Quickstart · Usage guide · Free-tier · Troubleshooting


トラブルシューティング (早見表)

まず: coderouter doctor --check-model <provider名> を走らせてください。大体これで原因がわかります。

症状 原因 詳細
401 エラー API キー未設定 / .envexport 忘れ §1
返信が空 / 意味不明 Ollama の num_ctx が 2048 に切り詰め §3
<think> タグが漏れる output_filters: [strip_thinking] を付ける §3
Claude Code でツール呼び出しがおかしい tool-call 修復が効いてない §4

http://localhost:8088/dashboard を開いておくと、ほとんどの問題が見て 10 秒でわかります。


技術スペック

  • ランタイム依存: fastapi / uvicorn / httpx / pydantic / pyyaml の 5 個のみ
  • テスト: 964 本 (41 sub-release 連続で依存追加なし)
  • 対応 OS: macOS (Apple Silicon 推奨) / Linux / Windows WSL2
  • 対応 backend: Ollama / llama.cpp / LM Studio / vLLM / MLX-LM / OpenRouter / NVIDIA NIM / Anthropic API
  • ライセンス: MIT

エコシステム

CodeRouter は backend ルーター層として独立して動きます。OPENAI_BASE_URL を CodeRouter に向けるだけで、他プロジェクトを無改造で吸収:

  • Voice Bridge — リアルタイム音声翻訳 + AI 音声チャット。CodeRouter 経由でローカル LLM のフォールバックを効かせると、ずんだもんが沈黙しなくなる

Security

シークレットは環境変数に置きます。docs/security.md に完全な方針と報告手順があります。

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coderouter_cli-2.3.0a4.tar.gz (963.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coderouter_cli-2.3.0a4-py3-none-any.whl (292.2 kB view details)

Uploaded Python 3

File details

Details for the file coderouter_cli-2.3.0a4.tar.gz.

File metadata

  • Download URL: coderouter_cli-2.3.0a4.tar.gz
  • Upload date:
  • Size: 963.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coderouter_cli-2.3.0a4.tar.gz
Algorithm Hash digest
SHA256 72afa41af1b5d91c2451553c105b4aa0b5bc3bf32aa76e88c3270cbecac68a5b
MD5 6fd097ccea0d2ddf9cb7a665649bfc17
BLAKE2b-256 0a82adf65d068bb7f6ecb0ca29515221e55473d5024c2ece150b7f17f9d5f347

See more details on using hashes here.

Provenance

The following attestation bundles were made for coderouter_cli-2.3.0a4.tar.gz:

Publisher: release.yml on zephel01/CodeRouter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coderouter_cli-2.3.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for coderouter_cli-2.3.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 8648a2c6d4043f5536822afae3575dccc5557dafb7ea86f3d02c50595ec795db
MD5 90cfc316622ed22692972b703ab602ac
BLAKE2b-256 bdf62e6c97b6e4ac3ba27f216c94703c7ce6ab92206a1f92ded7860a9990825a

See more details on using hashes here.

Provenance

The following attestation bundles were made for coderouter_cli-2.3.0a4-py3-none-any.whl:

Publisher: release.yml on zephel01/CodeRouter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page