Configuration
Everything works with no setup. One optional file, config.json, controls the routing modes, the above-session notice, the bare-dispatch advice and the band. The band buttons write it for you. Pins are not an option - they stay in the agent files, see Overriding pins.
The file
config.json in the plugin's data directory, ${CLAUDE_PLUGIN_DATA} (see Data). The band buttons create it on the first press; you can also edit it by hand.
{
"mode": "balanced",
"autoSwitch": true,
"exempt": ["reviewer"],
"redirect": { "model-routing:implementer": "implementer" },
"fallback": ["codex:codex-rescue"]
}| Key | Values | Default | What it does |
|---|---|---|---|
isOn | true or false | true | The power switch. false turns every mode check and the bare-dispatch refusal off. The band on / off button sets it. |
mode | "economy", "balanced", "strict" or "quality" | "quality" | The active routing mode. The band mode buttons set it. |
manualMode | same as mode | the value of mode | The mode you picked yourself; autoSwitch never goes below it. |
autoSwitch | true or false | false | Tightens the mode to economy from 80% and strict from 90% of the weekly limit, see Auto-switch. The band auto button sets it. |
showStats | true or false | true | Show the Claude 5h and week figures in the band. |
aboveSession | "warn" or "off" | "warn" | "off" hides the above session part of the cost line and the above-session notice. |
bareDispatch | "warn", "deny" or "off" | "warn" | "warn" keeps the bare-dispatch advice. A general-purpose or Explore dispatch that passes no model while the session model is above sonnet (above haiku for Explore) is refused, judged as the call was written and before the automatic default applies, when the value is not "off" and either the routing mode is not quality or the value is "deny". In balanced, economy and strict the refusal also says opus needs an [opus: ...] tag; in quality only "deny" refuses. "off" silences the advice and the refusal. It is skipped when CLAUDE_CODE_SUBAGENT_MODEL_FORCE is set, when CLAUDE_CODE_SUBAGENT_MODEL names another model, and for exempt agents. |
exempt | list of agent type names | [] | Agents left out of the above-session notice, the cost line's above session part and the bare-dispatch advice and refusal. |
redirect | object, agent type to agent type | {} | Rewrites the agent type of a dispatch to the target, see Redirect. |
fallback | list of agent types | [] | Agents named in opus refusals as alternatives, see Fallback agents. |
An exempt or redirect entry without a colon matches the agent's name after the last colon, so reviewer matches reviewer and model-routing:reviewer. An entry with a colon matches only that exact agent type, so other-plugin:reviewer does not match model-routing:reviewer. With a non-empty exempt the cost line cannot always see an agent's type, so an agent it cannot name is not excluded.
A missing, unreadable or invalid file means the defaults. A key with a wrong value falls back to its own default and the other keys are still read. The mod reads the file on every dispatch and every time the band draws; the dispatch counter hook reads it on every dispatch. A change applies at the next dispatch. A band button press keeps keys it does not own, and leaves a file that is not valid JSON or not an object as it is, so fix such a file by hand.
What you get with no configuration
- A default model for bare dispatches.
general-purpose,Explore,claude,Planand your own agents that set nomodel(ormodel: inherit) run onsonnet, andExploreonhaiku, but only when the session model is strictly above that. It never raises a model. It is skipped when the call passesmodel, or whenCLAUDE_CODE_SUBAGENT_MODELorCLAUDE_CODE_SUBAGENT_MODEL_FORCEis set to any value (the plugin does not special-caseinheritor0). Your own agents here means those in<config>/agents; project.claude/agentsare not read. The definition Claude Code resolves for the name decides: a project or plugin agent that shadows one of these names is left alone, and so is your own agent named like a built-in when it sets amodel. It runs in the plugin's mod, so it needs Claude Code 2.1.287 or later (see Install); without the mod a bare dispatch inherits the session model and the dispatch counter prints the advice below instead. - The routing mode
quality, which checks nothing, and the band with its buttons, see Routing modes. - A dispatch log and
/model-routing:stats, see Dispatch counter.
The cost line
From the session's first subagent on, the mod draws one line above the prompt:
model-routing: 3 opus, 3 sonnet - API $4.58 vs $2.42 at parent, above session: 3 opus (+$2.16)It counts subagents by the model that answered, prices each response at API list prices and prices the same tokens on the main session's model at the moment the response arrived. The above session part names the subagents that ran on a higher tier than the session model and what that cost beyond the same tokens on the session model. It is printed with its own sign: a higher tier is not always the dearer one when cache reads dominate, so the amount can be negative. Nothing is printed when no subagent ran above the session model, or with aboveSession: "off". Above the line sit the routing buttons, and after it the Claude 5h and week figures once they arrive (hide them with showStats: false), see Routing modes. /clear resets the line.
The hook notices
After every Agent or Task dispatch the dispatch counter hook (PostToolUse) can print one of two lines. aboveSession: "off" silences the first and bareDispatch other than "warn" silences the second; exempt agents get neither. Both are emitted as JSON carrying the text in systemMessage and additionalContext.
model-routing: <agent> ran on <model>, above the session model <session model>. This may cost more than planned.This one appears when the model the dispatch will run on can be inferred and ranks above the session model. The hook infers the model from the model parameter, this plugin's agent pins, three curated foreign pins, the frontmatter of your own agents in <config>/agents (project .claude/agents are not read) and CLAUDE_CODE_SUBAGENT_MODEL. It cannot see the frontmatter pin of another plugin's agent or of a project's .claude/agents, so such an agent gets no notice.
model-routing: a <agent> dispatch with no model runs on <inherited model>. Pass model "<suggested>" for ordinary work, or "<family>" when the task needs that reasoning.This one appears when the dispatch had no model, the automatic default would have applied, and the mod left no record of the dispatch (usually because the mod is not running; it also shows if the mod ran but could not write its record). It does not appear when the default was applied and recorded, nor when the plugin cannot be sure which definition the agent name resolves to: a project agent of that name in .claude/agents of the dispatch's folder or any parent folder, or a dispatch with no known folder, keeps it silent.
Data
The dispatch log is dispatches.jsonl in ${CLAUDE_PLUGIN_DATA}, which is ~/.claude/plugins/data/<id>/ (<id> is the plugin identifier with every character other than a letter, digit, _ or - replaced by -). It is kept across plugin updates, pruned to 30 days, and Claude Code deletes the directory when you uninstall the plugin from its last install place (claude plugin uninstall --keep-data keeps it). Delete it, and dispatches-legacy.jsonl if present, any time to reset the stats.
config.json lives in the same directory and is deleted with it when you uninstall the plugin.
Earlier versions kept both in ~/.claude/model-routing. On the first session start after the update the plugin moves the old log to dispatches-legacy.jsonl beside the new one, moves the old config.json to the data directory when there is none there yet (an existing one is kept), removes the old directory once the move is done, and prints a one-line notice. The current dispatches.jsonl is never touched by the move. Stats and reports read both log files, the legacy one first; the 30-day prune applies to both and deletes the legacy file once it is empty. If an earlier move was interrupted, the next start adds only the lines not already in the legacy file. If ~/.claude/model-routing is a link, only the link is removed and the folder it points to is left as is. This runs in the mod, so on a Claude Code without mods the old files are not moved and stats start empty. The requireOpusReason setting from 0.21 no longer exists; the routing mode replaces it.