# Model Router > Model Router is an open-source plugin for Claude Code. Claude names the model and effort on each subagent, agent-team teammate and workflow stage from a short table the plugin gives it, and the plugin keeps them within the user's cap and floor, fills in a missing effort, raises a call to a rule's level, gives a call nothing names a model for a level from its agent's tools, routes around a model that fails, and runs a call marked as a redo with more effort or on a stronger model. It routes among Claude models only (Haiku, Sonnet, Opus, Fable) and is not a proxy. An independent project by Cris Nahine (https://github.com/crisnahine), not made or endorsed by Anthropic. Apache-2.0 license. Needs Claude Code 2.1.329 or later and Python 3.9 or later. Site: https://crisnahine.github.io/claude-code-model-router/ Facts, each with its source: - What Claude is told: a note at session start, which the mod also adds to the Agent tool's description, asks Claude to name `model` and `effort` on every Agent call, by the work: haiku at medium for finding, reading and listing; haiku at high for writing and fixing code, figures and documents to a brief that settles the approach; opus at high for a judgment call with an open approach or no check to run (a design, a review, a rewrite). A call that names neither runs on its agent's own model, else at the level its tools put it, and a redo keeps its description with "Redo:" in front. With delegation at strict (the default) or on (at off the note is the table alone), the note opens with a paragraph that says this session coordinates and agents do the work, and that an agent's report is a claim: work no check ran on gets a review by a second agent before it counts. The mod adds a form of the table to the Workflow tool's description. CLAUDE_CODE_SUBAGENT_MODEL_FORCE, CLAUDE_CODE_SUBAGENT_MODEL, CLAUDE_CODE_EFFORT_LEVEL and CLAUDE_CODE_SUBAGENT_EFFORT change the table to what still applies under them. Sonnet and Fable have no row: a subagent runs on one when the call or its agent names it, a rule sets it, a redo climbs there, or the models below are ruled out. The router never reads the brief to pick a model. Source: plugins/model-router/scripts/modelrouter/hooks.py. - Levels: lookup on Haiku at medium, standard on Haiku at high, complex on Opus at high, hardest on Opus at high, frontier on Fable at high. A model stands for its lowest level (Haiku named at high or above is standard, Opus named above high is hardest, and Sonnet, which no level picks, is standard), and one that nobody gave an effort runs at its level's effort, one step more when it is weaker than its level needs. Source: plugins/model-router/config/models.json and plugins/model-router/scripts/modelrouter/ladder.py. - Who decides the model, first that applies: CLAUDE_CODE_SUBAGENT_MODEL_FORCE (the router sets effort only), CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL for a workflow stage whose call names no model (effort only), the model named on the call, a per-agent rule in the user's ~/.claude/model-router.json, a project's rule only when it isn't weaker than what the call runs on without it, the agent's own model field (inherit means the parent's model, ahead of CLAUDE_CODE_SUBAGENT_MODEL), CLAUDE_CODE_SUBAGENT_MODEL (left alone; unforced, it doesn't move the built-in Explore and Plan), then the level the agent's tools put it at: lookup for an agent that can't edit, write or run commands (its tools or disallowedTools leave out Edit, Write, NotebookEdit, Bash, PowerShell and Monitor, as in Explore and Plan), standard for any other. A model from the call, a rule, the agent or its tools is held to max_tier, min_tier (a weaker model is raised to it at the same level and effort), availableModels, deniedModels and model health, moving to the next stronger usable model, else the strongest usable. A rule's level raises a call, and a teammate starts no lower than standard. After two model errors on a model, it is routed around for a day. Forks are left alone. Source: plugins/model-router/scripts/modelrouter/router.py and health.py. - Redo: a call whose description starts with "Redo:" climbs from the latest finished run of the same agent and description in the session's last 30 minutes, else from what it would run at unmarked: one effort step up on the same model while that run was below high, else the next stronger usable model, started one effort level below that run and never below medium, else one more effort step. A redo that names a stronger model, or more effort on the same one, runs as named. When CLAUDE_CODE_EFFORT_LEVEL, CLAUDE_CODE_SUBAGENT_EFFORT or maxEffortLevel holds the effort, it moves to the next model; under CLAUDE_CODE_SUBAGENT_MODEL_FORCE only the effort climbs. Workflow stages are never redone. Source: plugins/model-router/scripts/modelrouter/router.py, spawn.py and calls.py. - The check before a turn ends: with verify_gate on (the default) and routing_mode auto, when a project file changed through Edit, Write or NotebookEdit, or an agent's shell changed one, and no check command ran since, the Stop hook asks Claude once, as additionalContext, for the work's own check. When an agent made the change, the ask says its report is the only word on the work and, for work with no check to run, asks for a review by model-router:reviewer. An agent whose name says it reviews counts as a check when it read files after the edit. It runs nothing, and it stays quiet while background tasks run or when the transcript can't be read. Source: plugins/model-router/scripts/modelrouter/gates.py. - In a session with a person at the prompt (mod only): a status line under the prompt shows the mode, path, cap, floor, the session's calls and how many the router changed or ran as redos. /model-router prints it with no model turn, /model-router on or off switches routing for that session only, and /model-router check on or off sets session_check. When a new session starts below the recommended main-session setups (Opus or Fable at medium effort or higher, Sonnet at high or higher), or on an older model of its family, it asks once, before the first prompt, which model and effort to switch to. Only a pick runs Claude Code's /model and /effort, and Claude Code keeps it as the default for new sessions (max lasts one session). Nothing of this runs in claude -p or the Agent SDK. Source: plugins/model-router/hooks/router.ts, scripts/modelrouter/session.py and report.py. - Delegation: with delegation on or strict, routing_mode auto and no CLAUDE_CODE_SUBAGENT_MODEL_FORCE, the mod adds up the characters the main conversation's own Read, Grep, Glob, Edit, Write, NotebookEdit, Bash, PowerShell, WebFetch and WebSearch calls sent and got back. At 8,000 and at each further 8,000 Claude gets a reminder to hand the work to an agent, and under strict the next work call is refused once the total is 8,000 or more, until an agent starts, an Agent call fails or 5 rounds of refusals pass. An agent starting (not a fork or the web-fetch agent) or a new main-conversation turn sets the total back to 0. Nothing is reminded or refused while the session can't start an agent or without the mod. Source: plugins/model-router/hooks/router.ts and scripts/modelrouter/hooks.py. - Commands: /model-router:route says what a call would run on and why, and writes nothing; /model-router:models shows which models are usable here and which are capped, below the floor, blocked or routed around; /model-router:usage shows calls per agent, levels, models and redos, and with the mod each subagent's tokens and Claude Code's cost estimate. Source: plugins/model-router/skills/ and scripts/modelrouter/report.py. - Options and storage: six options, routing_mode (auto or off), max_tier (none, haiku, sonnet, opus or fable, the strongest model), min_tier (none, sonnet, opus or fable, the weakest model), verify_gate (true or false), session_check (ask or off) and delegation (strict by default, on or off). The ledger in the plugin's data folder keeps each call's agent, level, model, effort and reason, and each subagent's tokens and Claude Code's cost estimate, for 30 days, trimmed once a day, and up to 4 MB. No prompt, brief or description is stored, and the plugin makes no network call. Source: plugins/model-router/.claude-plugin/plugin.json, plugins/model-router/scripts/modelrouter/ledger.py and store.py. - Benchmark: bench/ runs fixed tasks through headless Claude Code under three configurations (the plugin, no plugin with subagents on the session model, no plugin with every subagent on Haiku at high) and compares tasks solved and cost per solved task. The judged round on an Opus session ran 16 tasks 5 times each: Model Router solved 80 of 80 at $0.183 per solved task, Claude Code's defaults 80 of 80 at $0.361, and all-Haiku 78 of 80 at $0.139. That is a cost win against the defaults and no difference shown against all-Haiku. On five quick tasks with an Opus session and a brief sent as it is (50 runs), every setup solved 10 of 10, and a stock session cost 34% less per solved task than the plugin at strict, the default (26% less per run at the median); with delegation off the plugin cost 13% more per run at the median than a stock session (20 runs). docs/BENCHMARKS.md holds the method and every table. Source: bench/configs.json, bench/run.py and bench/analyze.py. ## Docs - [README](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/README.md): what it does, install, options, who decides, redo, limits - [Questions](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/FAQ.md): short answers to common questions - [Guide](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/GUIDE.md): how to set it up and configure it - [Architecture](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/ARCHITECTURE.md): how it is built and how it decides - [Built on the Claude Code docs](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/CLAUDE_CODE_DOCS.md): each documented rule the plugin follows, with its test - [Glossary](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/GLOSSARY.md): the project's own words - [Security](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/SECURITY.md): what is stored and who can influence routing - [Performance](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/PERFORMANCE.md): hook time, state on disk and the context the plugin adds - [Benchmarks](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/BENCHMARKS.md): how the benchmark runs and judges, the judged tables and the exploratory rounds ## Optional - [Changelog](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/CHANGELOG.md) - [Roadmap](https://raw.githubusercontent.com/crisnahine/claude-code-model-router/main/docs/ROADMAP.md)