explain-modelmux
Skill2 starsChanged 4 months agoMITView on GitHub
Use when someone wants to understand how modelmux works — why a proxy is needed, what signals it routes on, and how the cascade keeps the orchestrator on Claude while diverting chosen subagents.
In this repository11 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- debriefSkill
- distill-lessonsSkill
- flushSkill
- getting-startedSkill
- handoffSkill
- kit-doctorSkill
- kit-upgradeSkill
- orientSkill
- sitrepSkill
- switch-modelsSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 55
All four work types (background, longContext, think, webSearch) are implemented in route.ts, but only background is enabled in the shipped …
- Very specific: line 74
Every decision is appended to decisions.jsonl with isSubagent, matchedRule, upstream, and resolvedModel — the ground truth for "did this …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
How modelmux works
Explain the mental model, adapting depth to the audience. The whole system is small and readable — point people at the actual files.
The constraint
Claude Code picks its upstream from one global environment variable,
ANTHROPIC_BASE_URL. There's no per-subagent model setting on the client side.
So if you want some agents on Claude and others on a different model, the
decision has to happen outside the client — in a proxy that every request
flows through.
The proxy
src/server.ts is a Bun.serve reverse proxy. For each request it:
- Extracts routing signals (
src/signals.ts). - Picks a target via a first-match cascade (
src/route.ts+routes.toml). - Rewrites auth for the chosen upstream (
src/upstreams.ts) and forwards it. SSE streams pass straight through.
Two upstreams: Anthropic (api.anthropic.com, "passthrough" = keep the
model Claude Code asked for) and OpenRouter (its Anthropic-compatible
endpoint, so no request translation is needed).
The signals (why it routes by header, not model name)
From each request (src/signals.ts):
x-claude-code-agent-id— present only on subagent requests, so it marksisSubagent. This is the key signal, and routing on it sidesteps a Claude Code bug where a subagent's requested model can silently fall back to the parent's.x-app—clifor foreground,cli-bgfor background work.<<route:alias>>— an explicit tag placed in an agent's system prompt.- Work-type signals derived from the request:
background(x-app: cli-bg),longContext(estimated tokens >longContextThreshold),think(an extended-thinking block),webSearch(a web-search tool).
The cascade
route() walks routes.toml's routes top-to-bottom, first match wins:
- Tag rules —
<<route:flagship|max|reasoner|review|claude-review>>→ that model.<<route:control>>→orchestrator(stays on Claude). workType: background→ thecheapmodel.anySubagent→ theflagshipmodel (any untagged subagent).- Default →
orchestrator(Anthropic passthrough).
All four work types (background, longContext, think, webSearch) are
implemented in route.ts, but only background is enabled in the shipped
routes.toml — the others are commented-out examples an operator can turn on
(e.g. send big-context requests to a roomier model). That's what
longContextThreshold configures; it does nothing until a longContext rule
exists.
The main loop has no x-claude-code-agent-id, so it never matches a subagent
rule — it falls to the default and stays on Claude. That's the core promise:
smart orchestrator on Claude, chosen subagents on cheaper/other models.
The menu
routes.toml maps friendly aliases (flagship, cheap, …) to
<upstream>:<slug>. Swap a model in one place, or override at runtime with
MUX_MODEL_<ALIAS>. See the switch-models skill for day-to-day changes.
Verifying it
Every decision is appended to decisions.jsonl with isSubagent, matchedRule,
upstream, and resolvedModel — the ground truth for "did this actually route
where I think?"
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

