Model Router  ·  Documentation  ·  Previous: Security  ·  Next: Built on the docs

# Performance Times and sizes come from `python3 bench/overhead.py` (`--json` for JSON), which makes no paid call and works in throwaway folders. Measured on 2026-12-01 with Model Router 0.2.4 at `4e73f385`, on an Apple M3 Pro (11 cores), macOS 27.2.1, Node 22.22.3 and Claude Code 2.1.333, with `delegation` at `off`, and other work light (load average 1.2 to 3.1, read between passes of the first two runs). Each figure in the tables is the mean of the medians of 3 runs of the script, made in turn with Apple's Python 3.9.6 as `python3` and again with Homebrew's Python 3.13.14. Over the 3 runs a row's median moved by at most 1.10 times, and the bare launcher's by at most 1.13 times. `strict` is the default. The timing tables are for `off`, apart from the rows that say `strict`. Version 0.2.3, run twice in turn with 0.2.4 the same day, at `off` and at `strict` (the default of both versions), shows no difference beyond that noise: on 3.9.6 the medians of 0.2.4 are 0.99 to 1.03 times those of 0.2.3 (2 runs each; single runs 0.94 to 1.04) and on 3.13 1.00 to 1.01. The token and dollar figures under Context were measured with Model Router 0.2.2 and `delegation` at `strict`. The Stop check's and the scan's in-process times were measured the same day at the same commit, with 3.9.6 and 3.13. ## Hook time Warm p50 milliseconds per call (30 calls a run, mean of 3 runs), each through `sh scripts/model-router.sh`: | Command | 3.9.6 | 3.13 | | :- | -: | -: | | Each of the ten settings hooks in `hooks.json` | 69 to 72 | 53 to 56 | | `mod-start`, at the mod's `session.start` and the first main-loop turn after `/clear`, `/resume` or `/branch` | 69 | 54 | | `mod-spawn`, at `agent.spawn` | 71 | 55 | | `mod-usage`, at each subagent turn's `turn.complete` | 69 | 54 | | `mod-delegate`, at a delegation reminder or refusal (only with `delegation` at `on` or `strict`; timed at `strict`, the default, 2 runs) | 70 to 71 | 54 | In single runs, p95 ran 68 to 79 ms on 3.9.6 and 53 to 86 ms on 3.13. The launcher's loop with no router code after it (`sh` and one `python3 -c pass`) takes 20.1 and 20.9 ms. The tables above are for `off`. With `delegation` at `strict`, the default, the ten hooks, `mod-start`, `mod-spawn` and `mod-usage` take the same time as at `off` (0.97 to 1.02 times on 3.9.6, 1.00 on 3.13; 2 runs), within the run-to-run noise: `strict` adds the delegation text to the session note and the `delegate` fields to the mod's start answer, which adds less than the run-to-run noise. Apple's 3.9.6 writes no bytecode under the launcher's `-I` and ships none for its standard library, so the launcher gives it a private cache in `~/.cache/model-router/pycache`. Once a day a session start drops the bytecode kept for a plugin folder that is gone, so the cache holds one tree for each copy of the plugin still on disk. Without the cache, a hook took about 2.6 times as long in a side-by-side run (162 to 168 ms against 62 to 65 ms, calling `python3 -I model-router.py` directly). The routing decision itself (`config.load`, `spawn.facts`, `router.decide`) takes about 1.1 ms in process on 3.9.6 and 1.0 ms on 3.13, and the mod's `agent.spawn` handler about 0.05 ms in Node. So nearly all of each figure is starting Python and loading the plugin. After an agent ran a shell command, `agent-stopped` also scans the project's files for ones the shell changed (`gates._changed_on_disk`), and where the report goes back through `SubagentHandback`, `handing-back` makes that scan in its place. An agent is scanned once: a later hook for it scans again only after another shell command, or while one runs in the background. The scan took 30 ms on this repository's 1,702 tracked files with its 10 `.gitignore` rules (macOS, Python 3.9; 24 ms on 3.13). It tests each folder, and each file that changed, against every rule, and it stops after 20,000 files and folders or 3 seconds. The Stop check (`gates.unverified_edit`) reads the last 1 MiB of the transcript. It runs once per turn and only while an edit has no check after it, and it asks once for each batch of edits. Its in-process time depends on how many calls in that 1 MiB came after the edit and how many paths each holds. On Python 3.9.6, with 3.13 after the slash: about 47 ms / 39 ms for 2,655 Bash and PowerShell calls of 100 to 600 characters (`cd` chains, git, heredoc writes, background jobs), 2,011 of them after the edit and none a check; about 11 ms (3.9.6 only) when every call is older than the edit; and about 254 ms / 177 ms for 2,804 calls of 100 to 250 characters with several paths each, every one after the edit and none a check. The last is a stress case, not a usual turn: it needs about 2,800 shell calls after one edit with no test among them, and each path in a command adds work. Not timed: the mod's settings reads, which wait at most 2 s (`SETTINGS_MS` in `hooks/router.ts`). No hook runs async, and the mod waits for each answer it routes by. In a session with a person at the prompt, the mod also runs `mod-status` (the status line) after each spawn and each main-loop turn, `ps` and `mod-check` once at the start, and `mod-end` at a `/clear`, and `/model-router` waits on one `mod-status`. Each starts a process like the commands above, and they weren't timed. With `delegation` at `on` or `strict`, a reminder, a refusal or the end of the refusals runs `mod-delegate` the same way, and no tool call waits on it. At `off`, none of that runs: the session gets the routing table only. The status refresh and the session check run after the hook that asks for them has returned, so no spawn or turn waits on them, and a spawn during a refresh adds one more refresh, not one each. An agent whose report goes back through `SubagentHandback` adds one `handing-back` to its call. Summed at p50: | What | Commands | 3.9.6 | 3.13 | | :- | :- | -: | -: | | A prompt | `user-prompt`, `stop` | 143 | 110 | | An `Agent` call through the mod, one subagent turn | `pre-agent`, `mod-spawn`, `post-agent`, `agent-stopped`, `mod-usage` | 350 | 274 | | An `Agent` call with no mod | `pre-agent`, `post-agent`, `agent-stopped` | 209 | 164 | | An edit | `post-edit` | 69 | 53 | ## State on disk After 1,000 routed calls through the real hook functions, half the sessions on each path (the first 3.9.6 run; the other runs, on either Python, are within 50 bytes per file, and `ledger.jsonl` is identical): | File | Bytes | Bounded by | | :- | -: | :- | | `ledger.jsonl` | 799,632 | 30 days, trimmed once a day; past 4 MiB, replaced usage rows go, then the older half (about 5,200 calls) | | `routes.json`, `done.json`, `launched.json` | 185,188, 96,612, 1,600 | 200 sessions, a day idle, 100 records each | | `allowlist.json`, `edits.json`, `sessions.json` | 5,510, 4,757, 2,902 | 200 sessions. In `edits.json` a session keeps at most 100 file-tool writes, 100 noted agents, 20 scanned agents and 6,000 characters of lines not yet given, 2,338,601 bytes with all 200 sessions full | | `pending.json` | 800 | 200 sessions, 100 calls each | | `state.json` | 383 | one entry per model or failed full ID, in a table per provider | The script also lowers the caps and runs past them twice. Every file stayed bounded, and `OverheadBench.test_the_overhead_bench_reports_every_hook_and_state_file` holds `ledger.jsonl` and `state.json` to it. A spawn takes one lock per file it writes: 2 through the mod, 3 without it (`SpawnPaths.test_a_spawn_takes_one_lock_per_state_file_it_writes`). ## Context Characters of plugin text Claude gets, then tokens as measured once with Claude Code 2.1.332 on a subscription login, in an Opus 5.5 session through `claude -p` with a one-word reply and no CLAUDE.md or memory files, in folders never used before. The token and dollar figures are for Model Router 0.2.2 with `delegation` at `strict`, and a figure says where another setting was measured: - With no plugin, the first request reads 11,837 tokens from the prompt cache and writes 6,226 ($0.052). - With Model Router 0.2.2 loaded at `strict`, the first request after the account's cache for it has gone cold reads 0 and writes 19,731 ($0.158). The next session, in another new folder, reads 14,248 and writes 5,483 ($0.047). So the plugin gives the session its own cached prompt prefix, and at `strict` its first request after a cold cache costs about $0.10 more on Opus 5.5. Each `delegation` setting has its own prefix, since the note is part of the Agent tool's description, so the cold-cache cost at `off` is not measured here. - The whole cached prompt of that one-word session is 19,731 tokens with the plugin at `strict` and 18,063 without, 1,668 more. It was 19,654 with `delegation` at `on` and 19,175 at `off`, both with 0.2.2. Its token cost at `off` is not measured with this version, since the session note and the model tables differ from 0.2.2's (the note is 687 characters at `off` in 0.2.4 and 689 in 0.2.2). | Text | When | Characters | Test budget | | :- | :- | -: | -: | | Session-start note (`hooks._rules`) | each start, resume, clear, compact and fork | 1,622 with no option set (`delegation` is `strict`, the default), 1,489 with `on`, 687 with `off`; 24 more with `min_tier` set (1,646 strict, 1,513 on, 711 off); over 64 option mixes, 206 to 714 off, up to 1,516 on and up to 1,649 strict | 720 for the table, plus 900 for the delegation paragraph, 1,000 with `strict` | | The same note, after two newlines, in the Agent tool's description (mod only) | all session | 1,624 with no option set (`strict`, the default), 1,491 with `on`, 689 with `off`, at most 1,651 | the note's | | The table for a script's stages (`hooks._workflow_rules`), after two newlines, in the Workflow tool's description (mod only) | all session | 523 with no option set, 528 under a floor | 540 | | The fallback's note on a call it rewrites (`fallback._note`) | with that call's result, no mod | 84 to 181 | none | | A redo with no step left (`spawn.redo_note`) | after that call's result | 106 to 118 | none | | The five agents' descriptions | all session | 871 | 930 | | The `route` skill's description | all session | 199 | 200 | | A note that the prompt names a model (`hooks.user_prompt`) | on such a prompt | 135 to 139 | none | | The Stop ask (`gates.unverified_edit`) | once per batch of unchecked edits | 862 for an agent's edits, 516 otherwise | none | | The line about what an agent's shell changed (`gates._unnamed`) | once, to the main conversation, beside the report of an agent whose shell changed a project file | 281, and the agent's ID and each file's name twice with the number of its command, 8 files at most, 3,101 at the longest | none | | The line that no check has run on an agent's work (`gates.unchecked_at_return`) | once per batch of an agent's unchecked edits, beside its result | 273 | none | | The `route` skill's text and its policy output | when it runs | about 5,900 and 1,562 | none | With the mod, the model table appears three times: in the session context, in the Agent tool's description and in the Workflow tool's, so a session with `delegation` off and no other option set carries 1,899 characters of it (687, 689 and 523), and 3,769 with the default `strict` (1,622 + 1,624 + 523). The delegation paragraph, 801 characters (934 with the `strict` sentence), is in the session context and the Agent tool's description, not the Workflow tool's. `Notes.test_every_note_stays_within_budget` walks the mixes of `max_tier`, `CLAUDE_CODE_SUBAGENT_MODEL`, its FORCE switch and the two effort variables. `MinTier.test_every_note_with_a_floor_stays_within_the_budget` holds the notes under a floor. `Hooks.test_the_text_in_context_every_session_stays_within_budget` holds the descriptions. `models` and `usage` set `disable-model-invocation`, so their descriptions stay out ([skills](https://code.claude.com/docs/en/skills.md#control-who-invokes-a-skill)). With `routing_mode` off there is no note and no Stop ask.