🪨 why use many token when few token do trick — Claude Code skill that cuts 65% of tokens by talking like caveman
Model router proxy for Claude Code, Codex, and apps
Weave Router sits between your agent or app and model providers, then chooses a model for each request. It works as an OpenAI-compatible and Anthropic-compatible gateway, with a local scoring path and optional HMM policy sidecar for routing decisions.
Builders who want Claude Code, Codex, Cursor, or an app to use one routing endpoint for model choice.
You can send every request through one endpoint and let the router pick the model without changing your workflow.
What it does
Per-request model routing
Chooses a model for each upstream request instead of using one fixed model for the whole session.
Multi-API support
Handles Anthropic Messages, OpenAI Chat Completions, Gemini native, and OpenAI-compatible providers.
Local routing scorer
Uses an in-process embedder and cluster scorer to make routing decisions quickly on your own machine.
Hosted and self-hosted setup
Works as a managed endpoint with `npx @weave-os/router` or as a local stack with Postgres and the router service.
Agent wiring for Claude Code and Codex
Installs config for Claude Code and Codex, including project-scoped setup and native Codex skills.
Observability and usage tracking
Exports OTLP traces and records usage so you can inspect routing and provider behavior.
How to get it
- 1The fastest way: point Claude Code, Codex, opencode, or pi at the hosted Weave Router…
npx @weave-os/router
- 2The default stack uses the in-process cluster scorer. To run the frozen HMM policy as a…
echo 'GOOGLE_API_KEY=...' >> .env.local make up-hmm
README
One endpoint. Every model. Always the right one.
A drop-in proxy for Anthropic, OpenAI, and Gemini that picks the best model for every request: using a tiny on-box embedder, not a vibes-based prompt.
Built by Weave: The #1 engineering intelligence platform, loved by Robinhood, PostHog, Reducto, and hundreds of others.
What it does
Point Claude Code, Codex, Cursor, or your own app at localhost:8080. The router:
- 🎯 Routes per action. A cluster scorer derived from Avengers-Pro [^1] picks the right model from your enabled providers, for every upstream API request. (See docs/SEMANTICS.md for the canonical terminology: the router routes per action, not per turn.)
- 🔌 Speaks everyone's API. Anthropic Messages, OpenAI Chat Completions, Gemini native. Streaming, tools, vision, the works.
- 🧠 Knows OSS too. DeepSeek, Kimi, GLM, Qwen, Llama, Mistral via OpenRouter (or any OpenAI-compatible endpoint).
- 🔒 BYOK by default. Provider keys stay on your box, encrypted at rest.
- 📊 Observable. OTLP traces out of the box. See them in the Weave dashboard (http://localhost:8080/ui/dashboard) or drop in Honeycomb, Datadog, Grafana, whatever.
30-second quickstart
The fastest way: point Claude Code, Codex, opencode, or pi at the hosted Weave Router with one command. No clone, no Docker, no Postgres.
npx @weave-os/router
That's it. The installer asks which tool (Claude Code, Codex, opencode, or pi), walks you through scope (user vs. project), grabs a router key, and wires the right config file. Other flavors:
npx @weave-os/router --claude # skip the picker, Claude Code
npx @weave-os/router --codex # skip the picker, OpenAI Codex CLI
npx @weave-os/router --opencode # skip the picker, opencode
npx @weave-os/router --pi # skip the picker, pi + Loom UI
npx @weave-os/router --scope project # per-repo, commits settings.json (or .codex/ / opencode.json)
npx @weave-os/router --local # self-hosted localhost:8080
npx @weave-os/router --base-url https://router.acme.internal
npx @weave-os/router@0.1.0 # pin a version
Requires Node ≥ 18 (Claude Code, opencode, and pi paths also need jq). Full
flag reference: install/npm/README.md.
The npm package is published as @weave-os/router. The former
@workweave/router package remains available as a compatibility alias and
continues to receive the same releases.
Or: self-host the whole stack
If you want the router (and dashboard) running on your own box:
# 1. Drop a provider key in. OpenRouter is the recommended baseline.
echo "OPENROUTER_API_KEY=sk-or-v1-..." >> .env.local
# 2. Set a dashboard password. Without one, inference still runs but
# dashboard administration is disabled.
echo "ROUTER_ADMIN_PASSWORD=replace-with-a-strong-password" >> .env.local
# 3. Boot Postgres + router on :8080 and seed an rk_ key.
make full-setup
The router is up at http://localhost:8080, the dashboard at
http://localhost:8080/ui/, and your rk_... key prints in the logs.
# Call it like Anthropic
curl -sS http://localhost:8080/v1/messages \
-H "Authorization: Bearer rk_..." \
-d '{"model":"claude-sonnet-4-5","max_tokens":256,
"messages":[{"role":"user","content":"hi"}]}'
# ...or like OpenAI
curl -sS http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer rk_..." \
-d '{"model":"gpt-4o-mini",
"messages":[{"role":"user","content":"hi"}]}'
# Peek at the routing decision without proxying
curl -sS http://localhost:8080/v1/route -H "Authorization: Bearer rk_..." -d '...'
What that stack looks like
Only the grey boxes are off your machine. The router, the scorer, Postgres, and your provider keys all stay local; prompts go from the router straight to the provider you configured, never to Weave.
flowchart LR
client["Claude Code, Codex, opencode,<br/>pi, Cursor, your own app"]
router["Router :8080<br/>/v1/messages · /v1/chat/completions<br/>/v1beta/models · /v1/route"]
scorer["Cluster scorer<br/>in-process ONNX embedder"]
hmm["HMM policy sidecar :8093<br/>optional, make up-hmm"]
pg[("Postgres<br/>installations, rk_ keys,<br/>encrypted BYOK keys, usage")]
ui["Dashboard /ui<br/>selfhosted mode only"]
providers["Anthropic · OpenAI · Gemini<br/>OpenRouter and any<br/>OpenAI-compatible endpoint"]
otel["Your OTLP collector<br/>Honeycomb, Datadog, Grafana"]
client -->|"rk_… bearer token,<br/>streamed response back"| router
router -->|"embed and score the action"| scorer
router -.->|"ROUTER_DEFAULT_STRATEGY=hmm"| hmm
router -->|"auth, config, usage"| pg
pg --> ui
router -->|"provider key from env or BYOK"| providers
router -.->|"spans and usage logs"| otel
classDef external fill:#f4f4f5,stroke:#a1a1aa,color:#3f3f46
class providers,otel external
Multi-replica deployments also need Pub/Sub (PUBSUB_*) for cache
invalidation; docker compose runs the emulator for you.
Optional: self-host the frozen HMM policy
The default stack uses the in-process cluster scorer. To run the frozen HMM policy as a companion container, add a Google API key and use the opt-in target:
echo 'GOOGLE_API_KEY=...' >> .env.local
make up-hmm
This does not change the default strategy. See
sidecars/hmm/README.md for artifact verification,
embedding compatibility, and explicit HMM selection.
Wire it into your tools
Claude Code. Run make install-cc to wire Claude Code at the local
self-hosted router (it's also invoked automatically at the end of
make full-setup). For the hosted router, use npx @weave-os/router
above.
Codex (OpenAI CLI). npx @weave-os/router --codex patches
~/.codex/config.toml (or <repo>/.codex/config.toml with --scope project)
with a managed [model_providers.weave] block and sets model_provider = "weave".
The provider preserves Codex's existing ChatGPT OAuth login while the router
key rides in an X-Weave-Router-Key HTTP header and the installer selects the
HMM strategy for the public hosted endpoint. --codex --local and custom
self-hosted URLs keep their router's configured default because the HMM
sidecar is optional. HMM and forced selections in the native Codex family
(gpt-5.6-sol, gpt-5.6-terra, gpt-5.6-luna) use that OAuth credential;
every other selected model uses its WorkWeave deployment or BYOK credential,
matching the Claude Code plugin's model-to-credential dispatch.
Codex does not load third-party slash-command files, so the installer ships the
router directives as native Codex skills: $force-model <model-id> (alias
$fm <model-id>), $unforce-model (alias $ufm), and
`$router-feedback
Files in the repo
- .claude
- .conductor
- .github
- bench
- cmd
- db
- docs
- frontend
- install
- internal
- scripts
- sidecars
- smoke
- specs
- .dockerignore
- .env.example
- .gitattributes
- .gitignore
- .golangci.yml
- AGENTS.md
- CLAUDE.md
- CONTRIBUTING.md
- docker-compose.yml
- Dockerfile
- go.mod
- go.sum
- LICENSE
- Makefile
- README.md
- ruff.toml
Discussion (0)
Ask about usage, or say what you built with itSign in to join the discussion.
No comments yet. Be the first to say what this is good for.
More tools
The best-benchmarked open-source AI memory system. And it's free.
Orca is the ADE for working with a fleet of parallel agents. Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io
Never stop coding. Free MIT AI gateway: one endpoint, 352 providers (150+ free), 1200+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 550+ contributors
Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.