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.
⭐ 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)
# 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 startNow 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.
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.
- 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.
v0.2 adds streaming passthrough for both Claude Code and Codex CLI. End-to-end usable as a daily driver.
- 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, andround-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/messagesand OpenAI-compatible/v1/chat/completions - Prometheus-compatible
/metricsendpoint (requests, ledger writes, dispatcher retries, stream chunks) - Terminal-friendly ledger queries:
ccg-router ledger summary --since 7dandccg-router ledger recent -n 20— no need to drop intosqlite3 - Optional encrypted ledger at rest (AES-256-GCM, append-only, zero new dependencies). See
docs/encrypted-ledger.md. CLI:ccg-router ledger encrypt|decrypt.
- Hosted preset registry
- Encrypted local ledger
- Advanced dashboard analytics
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.gitccg-router init
export ANTHROPIC_BASE_URL=http://127.0.0.1:17180
export OPENAI_BASE_URL=http://127.0.0.1:17180
ccg-router startOpen http://127.0.0.1:17180/ui/.
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.
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.
- Anthropic-compatible
/v1/messages - OpenAI-compatible
/v1/chat/completions - Three routing strategies
- Local SQLite usage ledger
- Signed preset registry loader
- Read-only local UI
| 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 |
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.
- Claude Code router
- Codex CLI router
- OpenAI-compatible proxy
- Anthropic-compatible proxy
- Local usage ledger
- ccg-router vs claude-code-router
- 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
- Claude Code router
- Codex CLI router
- Route Claude Code to OpenAI-compatible APIs
- Codex CLI OpenAI-compatible router
- ANTHROPIC_BASE_URL local router
- OPENAI_BASE_URL local router
- Claude Code usage tracking
- Local LLM router for AI coding CLI tools
- Use one local router for Claude Code and Codex CLI
- Run an OpenAI-compatible and Anthropic-compatible local proxy
- Track Claude Code and Codex CLI usage locally
- ANTHROPIC_BASE_URL not working with Claude Code
- OPENAI_BASE_URL not working with Codex CLI
- Homebrew install problem
- go install ccg-router@latest problem
- ccg-router doctor failed
See docs/configuration.md.
See docs/routing-strategies.md.
See docs/preset-registry.md.
- v0.1: local daemon, routing, ledger, registry verification, UI
- v0.2: streaming passthrough for both protocols
- Later: encrypted ledger, plugin hooks, deeper usage analytics
See docs/faq.md.
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
Run make test before opening a PR. Keep public docs focused on local routing, official direct upstream examples, privacy, and reproducible behavior.
Apache-2.0
