Model Router · Documentation · Previous: Documentation · Next: Questions
# Guide
How to install, use and configure Model Router 0.2.4.
## Install, update and uninstall
It needs Claude Code 2.1.329 or later, `sh`, and Python 3.9 or later as `python3` or `python` on your `PATH`.
- Install: `/plugin install model-router --marketplace crisnahine/claude-code-model-router`, then pick a scope. From a shell, `claude plugin install` takes the same arguments and `--scope`.
- Update: `claude plugin update model-router@claude-code-model-router`, or **Update now** on the plugin in `/plugin`. Auto-update is off by default; turn it on for the marketplace in the **Marketplaces** tab.
- Disable or uninstall: `claude plugin disable` or `uninstall`, with `model-router@claude-code-model-router`. Uninstalling the last install deletes the plugin's data folder unless you pass `--keep-data`.
## Commands
- `/model-router` prints the [status line](#the-status-line), the session's model and effort once known (an estimate before its first request), and how to switch. `/model-router off` and `on` [switch routing for this session](#switch-routing-for-this-session), and `/model-router check off` and `on` set `session_check`. It answers with no model turn, and its reply is for you only.
- `/model-router:route [task]` shows the mode, cap, floor, ladder and role agents, and Claude uses them to say which model and effort fit the task, or to delegate it.
- `/model-router:models [reset]` shows, per model, what it last ran as and whether it is working, unused, above your cap, below your floor, not permitted or routed around, and what your rules files had wrong or a project's file didn't get. `reset` clears the model health record first.
- `/model-router:usage [days]` shows, over `days` (default 7), calls per agent with how many the router changed, their levels and models, redos and model errors, and, where the mod runs, tokens per model and Claude Code's cost estimate, which isn't your bill.
`models` and `usage` take `--json`.
## Configuration
### Options
Set in `/config`:
- `routing_mode`: `auto` (default) or `off`. `off` changes no call and adds no session note, delegation text, Stop check or session check, but still keeps records and tells Claude of a model error or a mid-run model swap.
- `max_tier`: `none` (default), `haiku`, `sonnet`, `opus` or `fable`, the strongest model a subagent may run on. A stronger one is lowered, except an environment pin or a fork. A Mythos ID counts as Fable; a model ID the registry can't place in a family is left as it is.
- `min_tier`: `none` (default), `sonnet`, `opus` or `fable`, the weakest model a subagent may run on. A weaker one 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 lookup raised from Haiku to Sonnet still runs at `medium`), except an environment pin or a fork. Only while `routing_mode` is `auto`. A `max_tier` weaker than `min_tier` wins and the floor is ignored, and `/model-router:route` and `/model-router:models` say so. Set it to `sonnet` where the main session itself runs on Haiku, since that session picks the model for its agents: with the floor the agent ran on Sonnet in 10 of 10 runs of a Haiku session. Those runs ran on a build whose review level was Sonnet, so they say nothing about where the shipped Opus review runs. A call that names Haiku runs on Sonnet under the floor on any session ([TESTING.md](TESTING.md#latest-results)).
- `verify_gate`: `true` (default) or `false`, the [check before a turn ends](#the-check-before-a-turn-ends).
- `session_check`: `ask` (default) or `off`, the [session check](#the-session-check). `/model-router check off` and `check on` write it too, unless managed settings own it.
- `delegation`: `strict` (default), `on` or `off` (an unset, empty or unknown value counts as `strict`), how hard Model Router pushes the main session to [hand work to agents](#delegation). Only while `routing_mode` is `auto`.
Changing an option reloads Model Router, which drops the effort it set for agents still running, so where the mod runs, `/config` and `/model-router check` refuse a change while Claude is working or such an agent runs, and say why. Only an agent whose effort Model Router set holds a change, so a workflow agent it set no effort for does not. An idle teammate holds nothing: after a change its later turns run at its own effort.
### Rules files
Your `~/.claude/model-router.json` (in `$CLAUDE_CONFIG_DIR` when set) applies everywhere and is trusted in full. A project's `.claude/model-router.json`, the nearest one up to the repository root, can only raise, so a cloned repository can't make its subagents run weaker. A project file over 64 KiB is not read. Both are JSON, as in `{"agents": {"my-agent": {"model": "opus"}}}`.
Agents are keyed by the name a call uses, such as `model-router:scout`. Levels are in [the ladder](#the-ladder); efforts are `low`, `medium`, `high`, `xhigh` and `max`.
- `agents..model`: yours sets it. A project's applies only when it isn't weaker than what the call would run on without it.
- `agents..level`: a level floor, in either file. A call below it runs on the level's model unless the environment pins the model, and it raises the level a call that names no model gets from its agent's tools. Yours also raises an agent with `model: inherit`; a project's raises one only to a model stronger than the parent's.
- `agents..route`: `false` in yours leaves the agent alone, with no level from its tools either. A project's is ignored.
- `levels..needs` (the weakest model's strength) and `.effort`: yours sets them; a project's only raises them. A `needs` of 0 or below means any model will do, and a level never needs less than the level under it. A project's lower value is dropped.
- `models..strength` and `.cost`: yours adds or re-ranks a model, named by an alias the Agent tool accepts. A project's adds only new names, used only when a call, your rule or an agent's file names them, and never under `max_tier` or `min_tier`.
Where your rule sets an agent's `level` or `model`, a project's rule for it is ignored. `routing_mode` and values of the wrong type are dropped, and `/model-router:models` lists them with what a project's file asked for and didn't get; other keys are ignored. `max_tier` caps only the model and `min_tier` raises only the model; where the mod runs, `maxEffortLevel` in your settings caps effort.
## In a session
Where the mod runs and a person is at the prompt, Model Router adds the status line, the `/model-router` command and the session check. None of them runs under `claude -p` or the Agent SDK, and where Claude Code can't show one, it is absent and routing goes on.
### The status line
One line under the prompt, after the plugin's name:
| Part | Shows |
| :- | :- |
| `auto` or `off` | `routing_mode`, or this session's switch, marked `(this session)` while it overrides the saved option. With routing off the line is that alone |
| `mod` or `fallback` | The path that routed this session's latest call |
| `cap opus` | `max_tier`, when set |
| `floor sonnet` | `min_tier`, when set |
| `14 calls` | This session's subagent, teammate and workflow agent calls, from the ledger |
| `5 changed` | The ones whose model or effort the router set; shown once there is one |
| `2 redos` | The ones that ran as redos; shown once there is one |
It refreshes when the session starts, after each spawn, after each main-loop turn and after a switch.
### Switch routing for this session
`/model-router off` leaves every call as it is from the next spawn, on the mod and the fallback alike, and `/model-router on` turns routing back on, over a saved `off` too. The reply says whether it lasts, as "Routing is off for this session. To keep it off, set Routing mode in /config." The switch belongs to the session id: `/clear` drops it, and a restart that keeps the id keeps it until a write to the switches file drops an entry that is a day old. It never writes `routing_mode`. What Claude got at session start stays: after `off` the session note's table stays in its context and in the Agent tool's description, and after `on` over a saved `off` it has none.
### The session check
The recommended setups for the session that plans and delegates are in `config/models.json` under `session`, as each model's lowest effort: Opus at `medium`, Fable at `medium` and Sonnet at `high`, each up to `max`. A model left out, such as Haiku, is never recommended, and neither is an older version of a family: an older full ID, or an alias the provider runs an older model under, as `sonnet` on Bedrock. Picking that family again moves to its newest model. On Amazon Bedrock's Mantle endpoint, when it is the only provider on, the bare `sonnet` alias is the newest Sonnet it serves, so a session on it at `high` or higher is not asked, and an older full ID still counts as older.
When a new interactive session starts below these, with `routing_mode` at `auto` and `session_check` at `ask`, Model Router asks once, after the session has started. A session that runs as an agent is not asked, since whoever started it chose its model:
1. "Model Router works best with a strong session to plan and delegate. This session is on Sonnet at medium. Which model should it run on?" The options are each recommended model usable here, in the order Opus, Fable, Sonnet, then `Stay on Sonnet at medium`. The first carries `(Recommended)`, the strongest, when it isn't first, `(the strongest model)`, and Sonnet `(at high effort or higher)`. A model that `availableModels` or `deniedModels` blocks is left out, and so is one that `maxEffortLevel` or `CLAUDE_CODE_EFFORT_LEVEL` holds below its lowest recommended effort. `max_tier` caps subagents, not the session, so it leaves none out.
2. After a model: "Which effort for Opus? Claude Code keeps this model and effort as your default for new sessions." The efforts run from the lowest recommended one, marked `(Recommended)`, up to `max (this session only)`, held to `maxEffortLevel`, and `medium` says `Claude Code's default`. A model with one effort left, as under `CLAUDE_CODE_EFFORT_LEVEL`, which `/effort` can't override, is offered at that effort with no second step.
3. After Stay: "Ask about this again?", with `Ask again next session` and `Don't ask again (/model-router check on brings this back)`, which sets `session_check` to `off`. When managed settings own that option, there is no second step.
Picking a setup runs Claude Code's own `/model` when the model differs, then `/effort` when the effort differs, and one line says where the session is now, as "This session is now on Opus at medium." If Claude Code doesn't switch the model, for example under an allowlist, the line says the session stayed and no effort is set, since Claude Code saves effort per model. If it switches the model but doesn't run `/effort`, the line says so. A pick with no model change always runs `/effort`. When a pick has a model change, the mod reads the session's model before `/model` and after it, and if either read fails it does not run `/effort` and one line says it could not read the model. A failed read after the last command shows one line that the change could not be confirmed. A dismissal, text typed under the dialog's own rows, or Stay changes nothing.
It asks at most once per session, a plugin reload included, and never once the conversation has a prompt in it: a prompt given at launch, or typed before the question shows, keeps it away. Before the first request the session's effort is an estimate: `CLAUDE_CODE_EFFORT_LEVEL` (under `auto` or `unset`, the API's default for the model, `medium` on Opus and `high` on Sonnet and Fable, or `medium` lowered to `maxEffortLevel` where that sets a cap), then a `--effort` flag at launch (`ultracode` reads as `xhigh`), then the settings files as Claude Code reads them (a model's own level before a top-level `effortLevel`), then `medium`, held to `maxEffortLevel`. Where the session's command line can't be read, the estimate goes without the flag, and it never sees an organization's default effort. From the first request on, the main loop's own effort is read, and `/model-router` shows it, as `session: opus at medium` or `session: sonnet at medium (below the recommended setups)`.
## Delegation
With `delegation` at `strict` (the default) or `on`, the session-start note opens with a paragraph that tells Claude this session coordinates and agents do the work: hand to an agent whatever takes more than two tool calls, and keep the plan, the briefs and the answer here. It also says an agent's report is a claim: work no check ran on gets a review by a second agent before it counts ([the check before a turn ends](#the-check-before-a-turn-ends) asks for it). The mod puts the same text in the Agent tool's description. An unset, empty or unknown value counts as `strict`.
With `delegation` at `off`, the session-start note is the table of which model and effort fit which work, and nothing more: no delegation paragraph, no count of the session's own tool calls, no reminder and no refusal. The session hands work to an agent when it chooses to or you ask, and Model Router then routes that agent. The plugin reads `EVAL_MODEL_ROUTER_DELEGATION`, ahead of the option, only when its own files run from outside a plugin cache (a checkout, `--plugin-dir`, or `claude plugin eval `), which is how an eval case pins a mode. An installed plugin ignores it, so a project's `env` block can't change its `delegation`.
`strict` is the default because under it the session hands work to agents, keeps its own context small, and sends work no check ran on to a second agent for a review. No round here measured a long coordinating session or the correctness of its output, which is what `strict` is for. It costs more 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 of a second round on the same tasks and cost 13% more per run at the median than a stock session (20 runs, [the rounds](BENCHMARKS.md#decision-rounds)). 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.
Where the mod runs, it also adds up the characters the main conversation's own work calls moved: what each call sent plus the text that came back, for Read, Grep, Glob, Edit, Write, NotebookEdit, Bash, PowerShell, WebFetch and WebSearch. Where Claude reads a web page through Claude Code's built-in `web-fetch` agent, that call counts as one of them. One call counts for 4,000 at most, so reading one long file never reaches the line alone and the first two calls always run. When the total passes 8,000 characters, and again at each further 8,000, Claude gets a reminder with that call's result to hand the rest to an agent. A subagent's own calls never count, and neither does a call another mod makes. An agent the main conversation starts (a subagent, a teammate or a workflow agent, a resumed run too; not a fork, not the `web-fetch` agent, not one another plugin starts and not one an agent starts) or a new turn of the main conversation sets the total back to 0, but a start that is refused or fails does not. No work call is refused from the moment the main conversation's own Agent call begins until the first of two events: that call's own spawn begins, or that call settles. Nor is one refused while a spawn the main conversation made is under way, whatever started it. So a foreground agent's whole run does not hold the refusals off. The 8,000 comes from the eval runs on an Opus session: a session that handed the work to agents moved at most 4,419 characters itself between agents, a one-line fix done in the main conversation moved 631 to 1,177, the same fix in a file of 344 lines counted for about 4,900, and a seven-change release done there moved 35,000 or more.
`strict` adds one sentence to the note and turns the reminder into a refusal: once the total is 8,000 or more with no agent started (a fork or the `web-fetch` agent does not count as one), the next work call is refused with a message until an agent starts, an Agent call fails or 5 rounds of refusals pass. When your own prompt tells Claude to do the work in the main conversation, Claude stopped at the refusal and said the option blocks it, in 3 of 3 eval runs. Set `delegation` to `on` in `/config` to remove the refusal: `on` keeps the paragraph and the reminder and refuses nothing. Pick `off` when you want Claude to work in the main session, as it would without the plugin; it has no paragraph, no reminder and no refusal.
What `strict` cost, from the eval runs on an Opus session with `delegation` at `strict` ([testing](TESTING.md#latest-results)): on a job one session can do alone, handing the work to agents cost between 15% less and 59% more and took from 0.7 to 2.8 times as long. A page with nothing to test, which also got a review by a second agent, cost $0.28 a run against $0.20 and took 173 seconds against 27, with the review on Sonnet where the shipped reviewer runs on Opus. `on` and `strict` are for a long coordinating session whose own context should stay small, such as an audit of 90 modules. No run of that audit beside stock used the shipped Opus review level, so it shows no saving. A session without the plugin that is told to hand the work out runs its agents on its own Opus, and against that the same work cost 13% to 60% less, with the reviews on Sonnet. On the largest task measured, a feature written across a copy of this repository that 757 tests grade, a run with the plugin, on an earlier build that put the implementer on Sonnet in 3 of the 4 runs, cost $0.64 to $1.16 against $1.50 without it and took 1.3 to 1.6 times as long, and 4 of 4 runs passed.
A session that runs as an agent does that agent's job itself: one started with `--agent` or the `agent` setting, or a teammate in a terminal pane of its own, which is a Claude Code session of its own that loads the plugin again. Its note has the table and no delegation paragraph, nothing is reminded or refused, and the [session check](#the-session-check) asks it nothing. Its own Agent calls are routed as any other. The check before a turn ends runs there as in any session, so it covers that teammate's edits, and nothing asks it about files its own shell changed.
Neither the reminder nor the refusal happens while the session can't start an agent (no Agent tool in its pool, or a permission rule denies it), with routing off, or without the mod, since the settings hooks have no counter. When the session looks able to start an agent but can't (a hook blocks the Agent call, a rule denies its type, or a permission ask has nobody to answer under `claude -p`), then under `strict`, while the refusal stands, the first Agent call of the main conversation that comes back refused or errored with no agent started ends the refusals and reminders until an agent starts or a new turn begins. After 5 rounds of refusals with no agent started, the refusals and reminders stop until an agent starts or a new turn begins, so at most 40 calls are refused before the work runs here. A round is the refusals one request of the main conversation brings, at most 8 of them, so the refusals end even if no request is seen. When the refusals end either way, Claude is told with the next result of its own work call or of the failed Agent call, once, unless an agent starts or a new turn begins first, and the ledger gets one row. An agent the main conversation starts, other than a fork or the web-fetch agent, lifts the refusal. Under `CLAUDE_CODE_SUBAGENT_MODEL_FORCE` none of delegation applies. Each reminder, each refusal and the end of the refusals writes one ledger row.
## Who decides the model

1. `CLAUDE_CODE_SUBAGENT_MODEL_FORCE` runs every subagent on `CLAUDE_CODE_SUBAGENT_MODEL`, else the conversation's model. With only `CLAUDE_CODE_SUBAGENT_MODEL_FORCE` set, the built-in Explore subagent runs on the model listed for it. The router sets only effort, and none on a call that names a model.
2. A model named on the call, by Claude, a skill or a workflow script. When your prompt asks for one ("use opus"), Claude gets a note to pass it.
3. A per-agent rule: yours, or a project's when not weaker.
4. The agent's own `model` field. `inherit` there is the agent's choice of the parent's model, and it outranks 5.
5. `CLAUDE_CODE_SUBAGENT_MODEL`. The router leaves the call alone unless it is a redo. Unforced, the variable doesn't move the built-in Explore and Plan, so they go on to 6.
6. The agent's tools. An agent whose `tools` hold none of Edit, Write, NotebookEdit, Bash, PowerShell and Monitor, or whose `disallowedTools` remove them all, as the built-in Explore and Plan, runs at `lookup`; any other at `standard`. A tool list Model Router can't read with confidence counts as every tool. Only the agent's definition counts here, never the brief. A [teammate](#agent-teams) starts no lower than `standard`.
For a workflow agent whose script names no model, `CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL` ranks between 1 and 2, with only effort set. `max_tier` and `min_tier` don't move these environment pins, and a notice at session start names any that is set. Under 2, 3, 4 and 6, a rule's `level` first raises a weaker model. The model must then be inside `max_tier`, no weaker than `min_tier`, allowed by `availableModels` and `deniedModels`, and not routed around, else the next stronger usable model runs, or the strongest usable one.
Under `min_tier: sonnet`, a call that names Haiku runs on Sonnet, and so does one whose agent, rule or level names Haiku. The effort stays the one that call had. Where Sonnet and every stronger model are unusable (unhealthy, or closed by `availableModels` or `deniedModels`), the call runs on the strongest model left, and the decision's reason says the floor could not be held. When the floor moves a call, the reason says "raised to the floor the user set (sonnet)", which `/model-router:route` and the ledger show. The session note's table and the Workflow tool's show the models a call will run on: with `min_tier: sonnet` the rows read `sonnet at medium`, `sonnet at high` and `opus at high`, and the note says "within the user's limits" where it otherwise says "within the user's cap". Only models whose strength you vouch for count under a floor, as under a cap, so a model a project's file added isn't used.
Effort set by the call, the agent, `CLAUDE_CODE_EFFORT_LEVEL` or `CLAUDE_CODE_SUBAGENT_EFFORT` stays. Otherwise a model from 2, 3, 4 or 6 gets its level's effort, one step more on a model weaker than the level needs (at most `xhigh`). An `inherit` agent left on its parent's model gets none. On the session's own model, a call from the main conversation gets at least the session's effort.
## The ladder
Each model stands for its lowest level; Haiku named at `high` or above stands for `standard`, and Opus named above `high` stands for `hardest`. No shipped level picks Sonnet: a call that names Sonnet stands for `standard`, and Sonnet also runs as the redo of a Haiku run.
| Level | Model | Effort |
| :- | :- | :- |
| `lookup` | Haiku | `medium` |
| `standard` | Haiku | `high` |
| `complex` | Opus | `high` |
| `hardest` | Opus | `high` |
| `frontier` | Fable | `high` |
`complex` and `hardest` share a rung, Opus at `high`. `hardest` is reached by a rule that sets the level, by Opus named above `high`, or by a redo the cap holds on Opus. `complex` runs on Opus because, in a round of 24 runs on a review task 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). Opus costs more per run: $0.65 against $0.28 at the mean, with `delegation` at `strict`.
A document whose brief settles its shape goes to Haiku at `high` even when it gives advice, an open question with no check to run goes to Opus at `high`, and a model named on the call or a rule overrides either pick.
Under `max_tier: sonnet`, a judgment call that names a model and an effort is held to Sonnet at the named effort, and one that names no effort runs on Sonnet at `xhigh`.
To run a level on a stronger model, raise its `needs` to that model's strength (Haiku 1, Sonnet 2, Opus 3, Fable 4) in your `~/.claude/model-router.json`. This puts `standard`, and with it the session note's row for writing and fixing to a brief that settles the approach, on Sonnet:
```json
{"levels": {"standard": {"needs": 2}}}
```
`needs` moves the model a level picks, not one a call or an agent names, so a call that names Haiku stays on Haiku. For "never use a model weaker than X", set `min_tier` in `/config`.
## Redo
Claude marks a redo by starting the `description` with "Redo:" after a failed check or a gap in a report. It climbs from the latest run of the same agent and description (case and spacing aside) that finished in this session in the last 30 minutes, else from what the call would run at unmarked: one effort step while that run was below `high`, else the next stronger usable model, started one effort level below the run it redoes and never below `medium`, else one more effort step. From Haiku at `medium`: Haiku `high`, Sonnet `medium`, Sonnet `high`, Opus `medium`, Opus `high`, Fable `medium`, Fable `high`, `xhigh`, `max`. With no step left, it runs as that run did, and Claude reads that nothing stronger is usable.
A redo that names more than that run runs as named; one that names the same or less climbs anyway. It climbs past a rule's model, the agent's model and effort, and `CLAUDE_CODE_SUBAGENT_MODEL`, inside `max_tier` and never below `min_tier`. 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` it gets only the effort step, up to `max`. Where the mod runs, it climbs from the model and effort the run's requests carried, after any cap or floor. A redo climbs from the model a floor raised the run to: under `min_tier: sonnet`, a redo of a Haiku call at `high` runs on Opus at `medium`.
No redo applies to a workflow stage, an agent whose definition isn't found, a model outside the registry, or `route: false`. A redo changes only its own call.
## The check before a turn ends

When Claude or a subagent changed a project file with Edit, Write or NotebookEdit, or Claude wrote one through a shell heredoc (`cat > notes.md < notes.md <` inside quotes is no redirect; in Bash a relative one follows a `cd` on the same line as the heredoc, and `tee`, `1>`, `&>`, `>|` and `>&file` write as `>` does, but `2>` and `>&2` don't), or a project file that changed on disk while one of the agent's shell commands ran and that no file tool wrote, which is how a file written by a script the agent ran is seen. A command the agent left running in the background counts too: one started with `run_in_background` until Claude Code tells the agent it finished, and one the command itself sends to the background with `&` until the agent stops, unless the same command ends it with `kill`, `pkill` or `wait`, run as a command of its own (`echo wait` and `sudo kill %1` end nothing). A process started without an `&`, such as `nohup serve` or `docker run -d img`, is not seen. An `&` inside a comment or a string is no job. In PowerShell, `Start-Job`, `Start-ThreadJob`, `Invoke-Command` with `-AsJob` and `Start-Process` without `-Wait` (and their aliases `sajb`, `saps`, `start` and `icm`) leave a job running the same way, and `-AsJob` is seen only before the first `;`, `|`, `&` or line break of its statement (a line that ends in a backtick goes on). `Wait-Job`, `Stop-Job`, `Receive-Job -Wait`, `Stop-Process` and `Wait-Process` (and `wjb`, `spjb`, `rcjb`, `spps` and `$p.WaitForExit()` with no argument) end one as a command of their own, `Wait-Job` and `Wait-Process` also with `-Timeout`. `Wait-Job $a,$b` ends one job per item. For an agent whose transcript is longer than the megabyte the plugin reads, a file that changed before the first command in that part counts too. A file that changed while none of its commands ran is not its edit, such as one you saved in your editor. One you saved while a command ran, or that another session wrote then, counts as the shell's, since the plugin knows only this session's file-tool writes. A file that changed while one of the agent's check commands ran is that check's own output, such as a test log or a coverage report, and adds no edit. The disk scan runs only when the agent ran a shell command, and covers the project folder and, for an agent working in its own worktree, that worktree. It skips dot files and dot folders, the folders `node_modules`, `__pycache__`, `venv`, `target`, `dist`, `build` and `vendor`, and what the `.gitignore` at the top of the project leaves out (its first 1,000 lines, and no `.gitignore` in a folder below). On Windows and macOS it matches those folder names and rules without case, as git does there, and on Windows it stays out of a junction. It stops after 20,000 files and folders or 3 seconds, whichever comes first, never scans a home folder or a drive root, and ignores a file dated in the future. On this repository's 1,702 tracked files with its 10 `.gitignore` rules it took 30 ms (macOS, Python 3.9; 24 ms on 3.13).
The main session is told about those files as well, when the agent's report comes back. When a project file changed while one of the agent's shell commands ran, a check command included, and no Edit, Write or NotebookEdit wrote that change, the plugin adds a line beside the report: which files changed, and that the report may leave them out. The line names the agent by its ID and gives each file the number of the agent's shell command that was running when it changed, such as "during the 1st". A file gets no number when two commands were running at once, or when the agent's transcript is over a megabyte. The line comes whatever the report says, because a report can name a file and still call it untouched. It shows up to 8 file names, and only names made of ASCII letters, digits and `. / _ @ + - ( ) [ ]`. Each agent gets one line. A file a background job changes after the agent stopped isn't seen. The agent isn't kept running or asked anything, so the line costs no turn. It comes with whichever happens next: the prompt that carries a background agent's report, a foreground agent's result, or the end of the turn. Each line writes a `gate` row of kind `report`.
When an agent changed project files and nothing has checked them, the ask says so: the agent's report is the only word on them. It names the work's own check first (tests, a type check or linter, `model-router:verifier` for a check of more than one command, a recompute for figures). For work with no check to run (a document, an analysis, code no test covers) it asks for a review: `model-router:reviewer`, briefed with the request and the files, reads the work itself against its sources, and what it finds wrong goes back to the writer as a redo. The ask also says that a compare against the agent's report leaves the files unread, and that the review goes to an agent because the main conversation wrote the brief. When the main conversation itself made the edits, the ask is shorter and names no reviewer.
Claude hears it early as well. When an agent's work comes back, with a foreground agent's result or with the prompt that carries a background agent's report, and no check has run on what agents changed, one line tells Claude to run the tests, type check or linter that cover the work, or to start a review where none does, before the reply that ends the turn. It also says that Claude's own read of the work counts as neither. The line waits while another background agent still runs, and it comes once for a batch of edits. An agent that ran the check itself draws none. It costs no turn and writes a `gate` row of kind `verify-early`. If the turn still ends with the edits unchecked, the `Stop` hook asks as above.
A check is a test runner, linter or type checker run through Bash or PowerShell (`pytest`, `py -m pytest`, `pytest.exe`, `ruff.exe check`, `npm.cmd test`, `./gradlew.bat test`, `npm test`, `make check`, `Invoke-Pester`, or a script named for a check such as `sh run_checks.sh` or `./run_checks.ps1`), in the session or in a subagent, whose own transcript is read when it stops. `.\gradlew.bat test` counts in PowerShell, and a file named for a tool counts as that tool even outside the project (`/tmp/pytest -q`). `cmd /c`, `powershell -Command` and `pwsh -c` count when the command line they run does, down to 3 shells inside shells (`cmd /c cmd /c cmd /c pytest` counts, one more `cmd /c` doesn't), and so do `npm run -w web test`, `pnpm run --filter web test` and `npm exec -- vitest`. A check script outside the project doesn't count: an agent that writes `verify.py` beside the project and runs it, by its path or after a `cd` or `Set-Location` there, has graded its own work. When the command has a `cd` and also a `(` or `)` anywhere, or in Bash a backtick, even inside quotes, the reader can't follow the `cd`, so a script named by a relative path doesn't count, as in `(cd web; sh run_checks.sh)` or `cd web && sh scripts/test.sh 'a (b)'`; a named tool still does, as in `(cd web && npm test)`. In PowerShell the script can be named through `$env:NAME` or `${env:NAME}`, which is read from the hook's own environment with the name matched without case. A test file an agent writes inside the project is the work's own test and counts, and so does a script run inside a container with `docker`, `podman` or `kubectl`. An agent whose own name says it reviews (a word in the last part of its name starts with "review", such as `model-router:reviewer` or `code-reviewer`) counts too, when it started after the edit and read files. A build that only compiles, a tool only named (`pip install pytest`), a run that only prints or lists (`--version`, `--help`, `--collect-only`, `make -n test`, `tox -l`, `ctest -N`, `go test -list .`, `pytest --setup-plan`), a clean, a fix or a setup (`ruff clean`, `make lint-fix`, `npm run test:data`, `make test-setup`, `tox --notest`, `tox -e py --notest`, which only install), a shell that only reads its script (`bash -n run_checks.sh`, `set -n`), a formatter without its check flag (`black .`, where `prettier --check .` counts) and a refused command don't count. A flag's value is no task for `make`, `gmake`, `just`, `cargo` and `go`, so `make -C tests build` and `just -f tests build` run no check, and `make -C tests test` does. A tool after `--` is read as run, so `grep -rn -- pytest .` counts. Of the files the main conversation's own shell changed, only one a heredoc or a PowerShell here-string in the command writes is an edit, and not when its target has a variable or a command in it (`"$TMPDIR/body.md"`). A relative target follows an earlier `Set-Location`, `cd`, `Push-Location` or `pushd` in PowerShell, and in Bash a `cd` on the same line as the heredoc. A bare `cd`, `cd -`, or a move to a path held in a variable or to a command's output leaves it counted as a write to the project. So does a `~name` in the move, or as the target when no move comes before it, and in Bash a `~` beside a quote or a backslash on the heredoc's line, `pushd`, and a `cd` with a flag such as `cd -P /tmp`. A write target longer than 1,024 characters counts as a write to the project too. A command with more than 20,000 path names to resolve, such as 400 `cd x;` in a row, leaves the folder unknown, and so does a hook run past 100,000 path names over all the commands it reads: a script named by a path is no check, a named tool such as `pytest` still is one, and a heredoc write counts as a write to the project. A path costs its separators plus one, with 3 times the project folder's path added for a heredoc's write target. The text inside a PowerShell here-string is no check and no job. It asks once per batch of edits, and never while a background task runs or when the transcript can't be read.
## Workflows
Workflow agents are routed only where the mod runs. The Workflow tool's description carries the session note's table, which asks a script to name a model and effort for each stage. A model the script names is held to `max_tier` and `min_tier`, and a stage that names none, as in a saved script written without them, runs on its agent's own model, else on `CLAUDE_CODE_SUBAGENT_MODEL` when that is set, else at the level its tools put it. The router raises a stage's effort to its level's and never lowers it, since it can't see the one the script set, and never redoes a stage.
## Agent teams
A teammate keeps one model for all its tasks, so one that nothing names a model for starts no lower than the `standard` level's model, even when its agent can only read. Its effort is set even under `CLAUDE_CODE_SUBAGENT_EFFORT`, which doesn't reach teammates. Without the mod, a named call counts as a teammate only while `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` is on.
## Role agents
Five agents carry their own models, which hold with routing off: `model-router:scout` (search) and `verifier` (checks) on Haiku at `medium`, `implementer` (code to a plan) on Haiku at `high`, and `architect` (plans) and `reviewer` (work no check can test, and risky diffs) on Opus at `high`. Only the implementer has Edit and Write. None of the five can start an agent, so the work one of them is given stays with it.
## Compatibility
Agents from any plugin, the project or `~/.claude/agents` are routed, and Claude Code's built-ins. The router never changes which agent runs and never approves a tool call, so other plugins' hooks, your permission rules and auto mode still apply.
Without the mod, the router rewrites the Agent call's `model` and `effort` and tells Claude. If a rewritten call comes back unrun, its repeat passes through unchanged, or is refused with the model to use if it would run above `max_tier` or below `min_tier`. Where an organization sets `allowManagedModsOnly`, Claude Code refuses a mod a user installed, so the router runs on its settings hooks alone, as without the mod. Where it sets `allowManagedHooksOnly`, or `disableAllHooks` is on, the router's hooks stop too unless managed settings force-enable the plugin (its mod then runs only if it counts as your organization's), and a managed `disableAllHooks` stops them even then.
### Organization allowlists
The mod reads `availableModels`, `deniedModels` and `maxEffortLevel` from your settings, so the router never picks a blocked model or sets an effort past the cap. If the lists leave no registry model open, the call runs as it is. Without the mod, only Claude Code enforces them.
### Third-party providers
Where a provider's alias runs an older model (the providers and families under `older_aliases` in `config/models.json`, such as `sonnet` and `haiku` on Bedrock), the mod sends the family's newest ID, `claude-sonnet-5-5` or `claude-haiku-5-5`. The table was measured on the Claude Code 2.1.332 binary and matches the alias table on the docs' model configuration page for 2.1.333. The 2.1.333 binary was not measured. Amazon Bedrock's Mantle endpoint, when it is the only provider on, is the exception: `sonnet` there is Sonnet 5 and `haiku` is Haiku 4.5, the router sends the alias as it is, never an ID, and moves no pick up a family, since Mantle serves only some versions, and the session check leaves out a model it would have to name by an ID and counts a session on the bare alias as current. On 2.1.329 to 2.1.331, `sonnet` on Google Cloud's Agent Platform and `opus` and `sonnet` on Microsoft Foundry run an older model too, and the router sends them as the alias. It sends the alias instead when `ANTHROPIC_DEFAULT__MODEL` is set, when `availableModels`, `deniedModels` or `modelOverrides` rule the ID out, and for a day after the provider refuses it. Where no newest ID goes out, as on the fallback path, the router's own pick moves one family up from a lagging alias, unless that variable is set. None of these has had a live run.
### The advisor tool, fast mode and `opusplan`
Three Claude Code features change what a session costs or how fast it runs, and Model Router sets none of them.
The advisor tool lets Claude consult a second model at key moments. It is experimental, and offered on the Anthropic API, Claude Platform on AWS and Claude Models on Google Cloud (Anthropic managed), not on Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry. You set it with `/advisor`, `advisorModel` or `--advisor`. A subagent inherits it, and its own model has to fit the pairing: an advisor that ranks below the subagent's model isn't attached. Each advisor call uses tokens at the advisor model's rates, on top of the main model's usage. Model Router never reads or sets the advisor.
Fast mode (`/fast`) makes a supported model up to 2.5x faster at a higher cost per token. Sonnet and Haiku don't offer it. Model Router never reads or sets it: it sets a subagent's `model` and `effort`, and the session's own only when you pick a setup in the [session check](#the-session-check).
`opusplan` is a `model` setting that uses `opus` in plan mode and switches to `sonnet` for execution. Model Router doesn't change the session's model on its own. It routes against the model the session is on when a call starts: the mod's spawn event names it, and without the mod it is the newer of the last main-thread reply and a model switch recorded since. An `opusplan` entry in `availableModels` permits `opus` for the router, and `availableModelsMatch: exact` ignores it, as Claude Code does.
## What it stores
Its state is in `~/.claude/plugins/data/model-router-claude-code-model-router/`, readable only by you on macOS and Linux, and holds no prompt, brief or description. `ledger.jsonl` has a row per spawn, result, model error, Stop-check ask, line that an agent's work is unchecked, line about what an agent's shell changed, delegation reminder, refusal or end of the refusals and subagent turn (agent, level, model, effort, reason, tokens, cost estimate), kept 30 days and at most 4 MiB. `state.json` holds model health until `reset`. The other files hold each session's routes, finished runs, edits, settings, switch and session check for the newest 200 sessions. A write to a file drops the routes, runs and switches in it that are a day old (a read does not check age), and edits go after 30 days. `locks.json` counts lock waits. Delete the folder to remove it all. On a Python that writes no bytecode under the launcher, as the macOS system Python does, compiled code is cached in `~/.cache/model-router/pycache`, which you can delete at any time and which uninstalling leaves behind.
## What it can't do
- It never changes the main conversation's model or effort by itself, since a switch re-reads the conversation uncached. Only a setup you pick in the [session check](#the-session-check) runs `/model` and `/effort`; otherwise run them yourself.
- It leaves forks and resumed agents alone, and an agent whose definition it can't find unless the call or your rule names a model. It finds a plugin's agent through Claude Code's install record, so a plugin with no record, such as one loaded with `--plugin-dir`, isn't found.
- It doesn't retry a failed call; set `fallbackModel` for that. After a model error it tells Claude a usable model to re-issue the call on (not under the force variable), and after two errors, or two runs on another model, it routes around that model for a day. Where the mod runs, a run that another mod moved to another model doesn't count.
- Where Fable bills to usage credits, a subagent or teammate on Fable can meet Claude Code's consent prompt: with nobody to answer, as in a background session or a teammate's session, the turn ends at the prompt's deadline, and `claude -p` bills without asking. `max_tier` at `opus` keeps subagents off Fable.
- Without the mod it has no dollar figures, workflow routing, reading of `availableModels`, `deniedModels` or `maxEffortLevel`, newest IDs, table in the Agent and Workflow tools' descriptions, status line, `/model-router` or session check. Its state is then in `/config`, `/model-router:models` and `/model-router:usage`.
- Under `claude --bare` Claude Code runs no plugin hooks or mods, so no call is routed.