Skip to content

XZXY-AI/ccg-router

ccg-router · Local router for Claude Code + Codex CLI

English · 中文 · 日本語 · 한국어 · Español · Português

One local daemon. Both Claude Code and Codex CLI talk to it. Anthropic-compatible and OpenAI-compatible on the same port — plus a local SQLite ledger for every request.

CI Latest Release License Go Report GitHub stars

⭐ Star this repo if you keep both Claude Code and Codex CLI installed — it actually helps other dual-CLI users find this.

Last updated: 2026-05-23 · Latest: v0.4.0 (encrypted ledger · dashboard · streaming · /metrics) · Try the live demo dashboard (no install)

ccg-router serves Claude Code and Codex CLI from one local port

What it does in 30 seconds

# 1. Install
brew install XZXY-AI/tap/ccg-router

# 2. Init + point both CLIs at the local router
ccg-router init
export ANTHROPIC_BASE_URL=http://127.0.0.1:17180
export OPENAI_BASE_URL=http://127.0.0.1:17180

# 3. Start it
ccg-router start

Now Claude Code and Codex CLI both flow through one daemon. Your provider keys stay in ~/.config/ccg-router/config.toml. Every request is logged to a local SQLite ledger you can query with sqlite3.

How is this different from claude-code-router?

claude-code-router ccg-router
Claude Code routing
Codex CLI routing
One daemon for both CLIs
Local SQLite usage ledger
Multiple routing strategies prefer-cheaper / prefer-capable / round-robin
Hosted control plane — (also no)

If you only use Claude Code, claude-code-router is more mature for the single-CLI case. ccg-router exists for the dual-CLI workflow.

Why try it today

  • You bounce between Claude Code and Codex CLI and the env-var dance is annoying.
  • You want a per-request local ledger so you can answer "how much did this side project actually cost me?" without a hosted dashboard.
  • You want one config to switch routing strategy per workload, instead of editing your shell rc.

If none of those apply, you probably don't need this yet — star the repo and check back in a few weeks when v0.2 lands streaming.

Status

v0.2 adds streaming passthrough for both Claude Code and Codex CLI. End-to-end usable as a daily driver.

What Works Today

  • Claude Code router endpoint for Anthropic-compatible /v1/messages
  • Codex CLI router endpoint for OpenAI-compatible /v1/chat/completions
  • Local OpenAI-compatible and Anthropic-compatible proxy on one port
  • Routing strategies: prefer-cheaper, prefer-capable, and round-robin
  • Local SQLite usage ledger for request metadata
  • Signed preset registry loader
  • Read-only local dashboard at /ui/
  • Streaming passthrough for both Anthropic-compatible /v1/messages and OpenAI-compatible /v1/chat/completions
  • Prometheus-compatible /metrics endpoint (requests, ledger writes, dispatcher retries, stream chunks)
  • Terminal-friendly ledger queries: ccg-router ledger summary --since 7d and ccg-router ledger recent -n 20 — no need to drop into sqlite3
  • Optional encrypted ledger at rest (AES-256-GCM, append-only, zero new dependencies). See docs/encrypted-ledger.md. CLI: ccg-router ledger encrypt|decrypt.

Not Yet

  • Hosted preset registry
  • Encrypted local ledger
  • Advanced dashboard analytics

Quickstart

Install with Homebrew, the release installer, Go, or Docker:

brew install XZXY-AI/tap/ccg-router
curl -fsSL https://raw.githubusercontent.com/XZXY-AI/ccg-router/main/scripts/install.sh | bash
go install github.com/XZXY-AI/ccg-router/cmd/ccg-router@latest

# Or build a local Docker image (two-stage, distroless runtime ~12MB):
docker build -t ccg-router:dev https://github.com/XZXY-AI/ccg-router.git
ccg-router init
export ANTHROPIC_BASE_URL=http://127.0.0.1:17180
export OPENAI_BASE_URL=http://127.0.0.1:17180
ccg-router start

Open http://127.0.0.1:17180/ui/.

How it works

Claude Code sends Anthropic-compatible requests to 127.0.0.1:17180. Codex CLI sends OpenAI-compatible requests to the same daemon. ccg-router normalizes the request, selects an upstream, forwards the raw body, and records a local ledger row.

Overhead

The router adds a small, measurable amount of latency. From internal/dispatch/dispatcher_bench_test.go on an AMD EPYC 9V45 (loopback httptest upstream, no real network):

Microbench ns/op Note
BenchmarkRewriteModel_NoMap 5.3 ns model_map unused — effectively free per request
BenchmarkRewriteModel (one rewrite) 15,469 ns (~15 µs) with a 1-entry model_map table
BenchmarkDispatcher_Do_EndToEnd 81 µs full dispatcher round-trip incl. retry-wrap and ledger setup
BenchmarkDirectHTTP_Baseline 108 µs identical request without ccg-router in the path

So in this test rig the router adds no measurable latency vs direct — the dispatcher's connection-pooled client makes up for the rewrite cost. Real-world overhead is dominated by the upstream provider's network RTT (tens of milliseconds), against which sub-100 µs of router work disappears.

Reproduce: make bench.

Features

  • Anthropic-compatible /v1/messages
  • OpenAI-compatible /v1/chat/completions
  • Three routing strategies
  • Local SQLite usage ledger
  • Signed preset registry loader
  • Read-only local UI

Compare

Need Best fit
Route only Claude Code traffic claude-code-router
Share one local routing layer across Claude Code and Codex CLI ccg-router
Manually switch ANTHROPIC_BASE_URL and OPENAI_BASE_URL Shell env vars
Keep provider keys local while using multiple compatible APIs ccg-router

Search Terms

People usually find this project while looking for a Claude Code router, Codex CLI router, OpenAI-compatible proxy, Anthropic-compatible proxy, local LLM router, AI coding CLI router, or local Claude Code usage tracking.

Guides

Running it in production

  • Operations guide — deployment topologies, systemd / launchd / docker setup, reverse proxy + TLS, machine sizing, capacity planning
  • Runbook — playbooks for the 13 most common incidents (daemon won't start, 502 storms, ledger bloat, key recovery, etc.)
  • Architecture — internal packages, threading model, streaming pass-through, ledger durability (for contributors)
  • Encrypted ledger deep-dive — threat model, AES-256-GCM details, key rotation, compaction
  • Provider compatibility — Anthropic / OpenAI / OpenRouter / DeepSeek / Groq / Together / Ollama / LM Studio

SEO Landing Pages

Tutorials

Troubleshooting

Configuration

See docs/configuration.md.

Routing strategies

See docs/routing-strategies.md.

Preset registry

See docs/preset-registry.md.

Roadmap

  • v0.1: local daemon, routing, ledger, registry verification, UI
  • v0.2: streaming passthrough for both protocols
  • Later: encrypted ledger, plugin hooks, deeper usage analytics

FAQ

See docs/faq.md.

Community

Star the repo: https://github.com/XZXY-AI/ccg-router Discussions: https://github.com/XZXY-AI/ccg-router/discussions Hub: https://github.com/XZXY-AI/awesome-ai-coding-cli

Star history

Star history of XZXY-AI/ccg-router

Contributing

Run make test before opening a PR. Keep public docs focused on local routing, official direct upstream examples, privacy, and reproducible behavior.

License

Apache-2.0