A plugin for Claude Code
Model Router
Keeps each subagent's model and effort within the limits you set.
The plugin tells the main session to hand work to agents. Claude names the model and effort on each Agent call, from a note the plugin adds at session start. The plugin keeps what Claude names within your cap and floor and the models usable here, fills in the effort when only a model is named, and runs a call marked as a redo with more effort or on a stronger model. An independent project, not made or endorsed by Anthropic.
/plugin install model-router --marketplace crisnahine/claude-code-model-router
What does Model Router do?
Model Router (model-router) is an open-source plugin for Claude Code by Cris Nahine. Through its mod it sees every subagent, agent-team teammate and workflow stage as it starts, from any plugin, skill or agent. It changes only a call's model and effort, never which agent runs, and it leaves forks alone.
Holds the cap and floor
A model from the call, a rule, the agent or its tools is held to max_tier, min_tier, your availableModels and deniedModels, and model health. One ruled out moves to the next stronger usable model, else the strongest one left.
Guides the pick
The session note asks Claude for Haiku at medium for finding and reading, Haiku at high for writing and fixing work to a brief that settles the approach, and Opus at high for work with an open approach or no check to run, such as a design, a review or a rewrite. It has no row for Sonnet or Fable. A call that names no model runs on its agent's own model, else on CLAUDE_CODE_SUBAGENT_MODEL when it is set, else at lookup when the agent can only read, else at standard. With delegation at strict, the default, or on, the note also tells the main session that agents do the work and that an agent's report is a claim, so work no check ran on gets a review by a second agent before it counts. The mod then reminds Claude, or under strict refuses its work calls, once the session has moved a lot of text itself.
Climbs on a redo
A call whose description starts with "Redo:" runs one effort step higher on the same model while the run it redoes was below high, else on the next stronger model, started one effort level below that run and never below medium. A redo that names a stronger model, or more effort on the same one, runs as named. Workflow stages are never redone.
Keeps your settings
The model that CLAUDE_CODE_SUBAGENT_MODEL_FORCE or CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL sets stays, and so does CLAUDE_CODE_SUBAGENT_MODEL's outside a redo. A rule in model-router.json sets an agent's model or raises its level, and a project's file can only raise.
Asks for a check
When Claude or an agent changed a project file with Edit, Write or NotebookEdit, or an agent's shell changed one, and no check ran since, Claude is asked once, before the turn ends, for the work's own check, such as tests for code. For an agent's work with no check to run, such as a document or an analysis, it is asked for a review by model-router:reviewer. A file Claude writes through a shell heredoc or a PowerShell here-string counts too. When an agent's shell changed a project file, Claude is told which files, beside the agent's report.
Shows what ran
/model-router:usage lists agents, levels, models and redos. Where the plugin's mod runs, it adds each subagent's tokens and Claude Code's cost estimate, and a line under the prompt shows this session's calls.
Workflow stages: a model the script names is held to your cap and floor like any call's, and CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL sets the model of a stage that names none; without it, such a stage runs on its agent's own model, else on CLAUDE_CODE_SUBAGENT_MODEL when that is set, else at the level its agent's tools put it. The effort Model Router sets on a stage only ever raises the one it runs at, and on the session's own model it is never below the session's (guide).
How does Model Router set a subagent's model?
Claude names the model on each call, and each model stands for the lowest of five levels it runs. The router doesn't read the brief to pick a model: it holds the model to your cap, your floor and your settings, and sets the level's effort when a model is named without one (architecture).
CLAUDE_CODE_EFFORT_LEVEL, CLAUDE_CODE_SUBAGENT_EFFORT or maxEffortLevel holds the effort, it goes to the next stronger model, and under CLAUDE_CODE_SUBAGENT_MODEL_FORCE only the effort climbs.CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL comes right after the force variable, for a workflow stage whose call names no model. A call left on CLAUDE_CODE_SUBAGENT_MODEL, or on the parent's model through an agent's model: inherit, gets no effort from the router./model-router and runs the session check. Where it doesn't load, the PreToolUse hook routes each Agent call.Built on the Claude Code docs
Model Router is built from the extension points Claude Code documents: the plugin manifest, hooks, the mods API, skills and subagents.
- It switches the main conversation's model or effort only for a setup you pick when a session starts, through Claude Code's own
/modeland/effort. - Its hooks fail open: an error in the plugin never blocks a tool call, a spawn or a session.
- It never approves a tool call, so your permission rules still review every spawn.
Built on the docs lists each documented rule it follows with its test, and where the plugin goes past the docs.
What does the benchmark measure?
The benchmark in bench/ runs fixed tasks headless with and without the plugin, and compares tasks solved and cost per solved task. In the judged round (2026-11-25, Model Router 0.2.0), on an Opus session, Model Router solved 80 of 80 runs at $0.183 per solved task, Claude Code's defaults 80 of 80 at $0.361, and every subagent forced onto Haiku 78 of 80 at $0.139. Against the defaults that is a win by the benchmark's rule, and a cost result: these tasks can't tell a cheap model from a strong one, so it says nothing about quality. That build ran its complex level on Sonnet at high, and the shipped build runs it on Opus, so the costs above are for 0.2.0 and the shipped build costs more where that level runs. Every prompt tells the session to delegate, so the defaults were told to delegate too, and Model Router was slower: on Opus a run took 129 s of wall time on average, against 81 s for the defaults. Against all-Haiku the plugin costs more beyond noise ($0.020 to $0.079 more per solved task), and the pass-rate interval is too wide for the rule to call that a loss, so the rule's label for this comparison is "no difference shown". 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). BENCHMARKS.md holds every table, the method and the limits.
How do I install Model Router?
Run this in a Claude Code session, then pick a scope. The six options in /config start at their defaults, so nothing needs setting first.
/plugin install model-router --marketplace crisnahine/claude-code-model-router
Or add the marketplace first:
/plugin marketplace add crisnahine/claude-code-model-router
/plugin install model-router@claude-code-model-router
Requirements: Claude Code 2.1.329 or later, sh, and Python 3.9 or later as python3 or python on your PATH. Without Python its hooks do nothing and its commands say why, and the mod only holds a model a call names to max_tier and min_tier. Then try /model-router:route <task> to see which model a task would get and why.
Which options can I set?
Every option is in /config under the plugin. Rules for single agents and extra models go in ~/.claude/model-router.json or a project's .claude/model-router.json. A project's file only raises: a cloned repository can make its subagents cost more, never run weaker, and it can't get a model past your max_tier or leave one below your min_tier.
| Option | Default | What it does |
|---|---|---|
routing_mode | auto | auto keeps every agent's model within your limits and fills in the effort when only a model is named. off leaves every call as it is, with no session note, no check before a turn ends and no session check. |
max_tier | none | The strongest model subagents may run on. A stronger model from the call, a rule, the agent's definition or a parent model the router can see is lowered to it. A model set by CLAUDE_CODE_SUBAGENT_MODEL, CLAUDE_CODE_SUBAGENT_MODEL_FORCE or CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL isn't, and neither is a fork or a model ID the registry can't place in a family. |
min_tier | none | The weakest model subagents may run on: sonnet, opus or fable. A weaker model from the call, a rule, the agent's definition, a redo or the level table is raised to it, at the same level and effort. A model set by CLAUDE_CODE_SUBAGENT_MODEL, CLAUDE_CODE_SUBAGENT_MODEL_FORCE or CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL isn't, and neither is a fork or a model ID the registry can't place in a family. A max_tier weaker than min_tier wins. |
verify_gate | on | Asks once, before a turn ends, for the work's own check when Claude or an agent edited a project file with Edit, Write or NotebookEdit, or an agent's shell changed one, and no check ran after it. For an agent's work with no check to run, it asks for a review by model-router:reviewer. Only while routing_mode is auto, and not while background work runs. An ask costs one more turn. false turns it off, and with it the lines about unchecked work and about files an agent's shell changed. |
session_check | ask | When a new interactive session starts below the recommended main-session setups (Opus or Fable at medium effort or higher, Sonnet at high or higher), asks once which model and effort to switch to. A pick runs Claude Code's /model and /effort, which also keep it as the default for new sessions. off never asks. Only where the plugin's mod runs. |
delegation | strict | strict (the default) opens the session note with a paragraph that tells Claude this session coordinates and agents do the work, and where the mod runs, reminds Claude to hand work to an agent when the main conversation's own calls have moved 8,000 characters or more since an agent last started. It then refuses the next work call, until an agent starts, an Agent call fails or 5 rounds of refusals pass. on keeps the paragraph and the reminder and refuses nothing. off makes the note the routing table alone: no delegation paragraph, no count of the session's own tool calls, no reminder and no refusal. An unset, empty or unknown value counts as strict. On five quick tasks with an Opus session and a brief sent as it is, a stock session cost 34% less per solved task than the plugin at strict with its reviews on Sonnet (26% less per run at the median); set off for small jobs done in the main session. With delegation off, the plugin cost 13% more per run at the median than a stock session on the same tasks (20 runs). Only while routing_mode is auto, and not under CLAUDE_CODE_SUBAGENT_MODEL_FORCE. |
Questions about Model Router
The same answers as docs/FAQ.md.
What is Model Router?
Model Router is an open-source Claude Code plugin that tells the main session to hand work to agents and keeps the model and effort Claude names for each subagent, teammate and workflow agent within your limits. It fills in a missing effort, gives a call that names no model a level from what its agent can do, raises a call to a rule's level, routes around a failing model, and runs a call Claude marks as a redo one step higher. It is an independent Apache-2.0 project by Cris Nahine, not made or endorsed by Anthropic, and needs Claude Code 2.1.329 or later and Python 3.9 or later.
Does it pick the model, or does Claude?
Claude does, from a table the plugin gives it at session start: 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, and Opus at high for a judgment call with an open approach or no check to run, such as a design, a review or a rewrite. Sonnet and Fable have no row; a subagent runs on one when a redo climbs there, a rule sets its level or the call names it. The review task is why the third row is Opus: in a round of 24 runs on a review with 10 seeded defects, the complex level on Sonnet at high solved 0 of 6 and on Opus at high 4 of 6 (one-sided Fisher p 0.030), and Opus costs more per run ($0.65 against $0.28 at the mean, with delegation at strict). A call that names no model runs on its agent's own model, else CLAUDE_CODE_SUBAGENT_MODEL, else at the level its tools put it, and the plugin never reads the brief (guide).
Does it make Claude use subagents?
It tells Claude to, and where the mod runs it checks. With delegation at strict (the default) or on, the session-start 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 the same text to the Agent tool's description. 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, one call counting for 4,000 at most. When the total passes 8,000, and again at each further 8,000, Claude gets a reminder with that call's result. An agent starting, or a new turn, sets the total back to 0; a fork or the web-fetch agent does not count as an agent starting. Under strict, the next work call is refused once the total is 8,000 or more, until an agent starts. An Agent call that comes back refused or failed with no agent started also ends the refusals until an agent starts or a new turn begins, and so do 5 rounds of refusals with no agent started. Claude is told with the next result of its own work call or of the failed Agent call, unless an agent starts or a new turn begins first. With on, Claude gets the paragraph and the reminder, and nothing is refused. Nothing is reminded or refused while the session can't start an agent, with routing off, or without the mod, and off removes the paragraph, the reminder and the refusal, leaving the session-start note as the table alone (guide). The price of strict shows on small jobs. In a round of 50 runs on 5 quick tasks with an Opus session and a plain prompt, every setup solved 10 of 10, and a session without the plugin cost 34% less per solved task than the plugin under strict with its reviews on Sonnet (26% less per run at the median), since each quick task paid for a brief and a report on top of the work. With delegation off the plugin started no agent in 10 runs and cost 13% more per run at the median than a stock session on the same tasks (20 runs). No round here measured a long coordinating session or the correctness of its output, which is what strict is for. Set delegation to off for small jobs done in the main session, or to on to keep the paragraph and the reminder without the refusal (the rounds).
What happens when a subagent gets it wrong?
Claude marks a redo by starting the call's description with "Redo:". The redo runs above the run it redoes: one effort step up while that run was below high, else on the next stronger model, which starts one effort level below the run it redoes and never below medium, inside your cap and floor. A workflow stage is never redone (guide).
Can I trust work a cheaper model did?
Haiku at high writes only work whose brief settles the approach, and Haiku at medium finds, reads and lists. The session note asks Claude to send work with an open approach, such as a rewrite or a design, and work with no check to run, such as a review, to Opus at high. A failed check or a gap in a report is redone one step up: more effort first, then the next model (Haiku at high, then Sonnet, Opus, Fable). Before a turn ends, the Stop check asks Claude once for the check of work an agent changed that nothing checked: the tests, a type check or a linter, or a recompute for figures. For work with no check to run (a document, an analysis, code no test covers) it asks for a review by model-router:reviewer, which reads the files themselves, and what it finds wrong goes back to the writer as a redo. With min_tier set to sonnet in /config, no subagent the router routes runs on Haiku, except one an environment variable pins. TESTING.md has the measured results.
Does it cost anything?
The plugin is free and makes no model call of its own; the models it runs bill to your plan or API account as usual. The check before a turn ends costs one more turn when it asks. Each hook starts Python, 53 to 56 ms on Python 3.13 and 69 to 72 ms on Apple's Python 3.9.6 at the median (PERFORMANCE.md), and BENCHMARKS.md holds the cost and quality results. On five quick tasks with an Opus session and a brief sent as it is, a stock session cost 34% less per solved task than the plugin at strict, the default, with its reviews on Sonnet (26% less per run at the median), and with delegation off the plugin cost 13% more per run at the median than a stock session (the rounds).
What does it add to the context?
A session-start note of 1,622 characters with no option set (strict), holding a paragraph on delegation and the table above (1,489 with on, 687 with delegation off). The mod also adds it to the Agent tool's description, with a form of 523 characters in the Workflow tool's, plus the descriptions of its route skill and five agents. Claude also gets one line when your prompt names a model, when a check is due before a turn ends, after a model error, a mid-run model swap or a redo with nothing stronger left, and, without the mod, on each call it rewrites. It adds nothing to a subagent's brief, and claude plugin details model-router shows what it adds to every session.
Does anything leave my machine?
The plugin sends nothing anywhere: it opens no connection and makes no network call. What it adds to Claude's context, such as the session note and its reminders, goes to your model provider with the conversation, as do the briefs Claude writes for agents. Its own state stays in its data folder, and its ledger keeps model names, levels, tokens and cost estimates, never a prompt or description (SECURITY.md).
Which models does it use?
The aliases haiku, sonnet, opus and fable, which Claude Code resolves for your provider, or, where the mod runs and your provider's alias runs an older model, the family's newest full ID, except on Amazon Bedrock's Mantle endpoint, where the alias is sent as it is. max_tier caps the strongest one and min_tier sets the weakest, though neither moves a model CLAUDE_CODE_SUBAGENT_MODEL, CLAUDE_CODE_SUBAGENT_MODEL_FORCE or CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL pins. /model-router:models shows which are usable here and which are capped, below your floor, blocked or routed around (guide).
What happens without Python, or on an older Claude Code?
Without Python 3.9 or later on PATH, its hooks do nothing and its commands print one line saying why. Claude Code still runs the role agents on the models their definitions name, and the mod still holds a model a call names to max_tier and min_tier. Claude Code 2.1.323 to 2.1.328 refuse to load the plugin, 2.1.271 to 2.1.322 don't check the version it needs, and older versions can't load it, so update Claude Code first.
How do I turn it off?
Set routing_mode to off in /config: it changes no call and adds no session note or check, but still keeps its records, and /model-router off leaves calls as they are for this session only, where the mod runs. Set verify_gate to false to drop only the check before a turn ends and the lines about unchecked work and files an agent's shell changed, delegation to off to drop only the delegation text, reminder and refusal, or give one agent "route": false in your own ~/.claude/model-router.json. To unload it, run claude plugin disable model-router@claude-code-model-router (guide).
How do I see what it did?
Where the mod runs, a line under the prompt shows the mode, the cap and floor, this session's calls and how many the router changed or ran as redos, and /model-router prints it with no model turn. /model-router:usage shows the calls per agent, how many the router changed, their levels, the models they ran on and, where the mod runs, Claude Code's cost estimate, and /model-router:models shows each model's state. /model-router:route <task> says what a call would run on and why (guide).
Does it change the main conversation's model?
Only when you pick a setup. When a new session starts below the setups Model Router recommends for the session that plans and delegates (Opus or Fable at medium effort or higher, or Sonnet at high or higher), the mod asks once, before your first prompt, and a pick runs Claude Code's /model and /effort, which also make it your default for new sessions. It never switches by itself, since a switch re-reads the whole conversation uncached. Don't ask again, /model-router check off or session_check set to off in /config stops the question (guide).