Model Router · Documentation · Previous: Performance · Next: Benchmarks
# Built on the Claude Code docs Each row is a rule from the Claude Code or Claude platform docs or Claude Code's types, where the plugin follows it, and the test that holds it. Python names are in `plugins/model-router/scripts/modelrouter/`, and Node tests in `tests/mod/router.test.ts`. | The docs say | Where the plugin follows it | Test | | :- | :- | :- | | A subagent's model comes from the call's `model`, the agent's `model` (`inherit` included), `CLAUDE_CODE_SUBAGENT_MODEL`, then the conversation's, and a mod's `agent.spawn` model takes the call's place; the variable alone doesn't change the built-in Explore and Plan ([sub-agents](https://code.claude.com/docs/en/sub-agents.md#choose-a-model)) | `router.decide` keeps that order and moves a model only for the cap, the floor, an unusable model, a rule, a teammate or a redo, and in place of the conversation's names the level the agent's tools put it at, for Explore and Plan under the variable too | `test_the_users_environment_settings_win`, `test_a_call_that_names_no_model_runs_at_the_level_its_agents_tools_put_it`, `test_rules_in_override_files`, `InheritingAgents.test_an_agent_that_inherits_runs_on_the_parents_model_and_gets_no_pick` | | The Agent tool sets `effort` "ONLY when the user, or instructions such as CLAUDE.md or a skill, explicitly ask" (the Agent tool's type in `claude-code-tools/index.d.ts`; [sub-agents](https://code.claude.com/docs/en/sub-agents.md#choose-an-effort-level)) | `hooks._rules` and the `route` skill give a model and an effort for each kind of work and ask every call to name both | `test_session_start_explains_automatic_routing`, `test_each_eval_case_routes_as_expected` | | An agent's `tools` is a comma list or YAML list and inherits every tool when omitted; `disallowedTools` removes tools from it, and an entry with a specifier removes the whole tool. Explore and Plan have read-only tools ([frontmatter](https://code.claude.com/docs/en/sub-agents.md#frontmatter-reference), [built-in subagents](https://code.claude.com/docs/en/sub-agents.md#built-in-subagents)) | `agents.parse` reads both lists in each form YAML gives them (comments, a flow list over several lines, `- item` lines at any indent), and `agents.read_only` counts an agent as read-only when Edit, Write, NotebookEdit, Bash, PowerShell and Monitor are all out of reach. A list it can't read with confidence counts as every tool | `AgentTools.test_the_tool_lists_are_read_in_every_frontmatter_form`, `AgentTools.test_a_tool_list_that_cant_be_read_with_confidence_counts_as_every_tool`, `AgentTools.test_an_agent_reads_only_when_it_can_edit_write_or_run_nothing` | | Project subagents are found walking up from the working directory to the repository root, the closest winning, they outrank `~/.claude/agents`, and each folder is scanned recursively ([subagent scope](https://code.claude.com/docs/en/sub-agents.md#choose-the-subagent-scope)) | `agents.find` searches `config.project_folders`, nearest first, then the user's folder, each walk at most 10 folders deep and 20,000 entries | `ProjectFromASubfolder.test_inside_a_submodule_its_agent_comes_before_the_users_as_claude_code_takes_it`, `AgentFoldersARepositoryControls.test_the_walk_stops_at_its_depth_and_its_entry_count` | | An agent's `model` takes an alias or a full ID ([frontmatter](https://code.claude.com/docs/en/sub-agents.md#frontmatter-reference)) | `agents.parse` reads it and keeps an explicit `inherit` apart from a missing field, reads `model: null` and `model: ~` as no model, reads a file with CRLF line ends as one with LF, and `router.decide` keeps it within the cap and the floor and never swaps an ID the agent names | `test_agents_that_name_a_model_keep_it_within_the_cap`, `NewestOnProviders.test_a_version_the_caller_or_the_agent_names_is_left_alone`, `AgentFilesThatAreRead.test_the_line_ends_of_a_file_make_no_difference_to_its_model` | | Teammates and workflow agents take their model in the subagent order, with a mod's `agent.spawn` model first ([agent teams](https://code.claude.com/docs/en/agent-teams.md#specify-teammates-and-models), [workflows](https://code.claude.com/docs/en/workflows.md#cost)) | `mod.spawn` routes both like subagents, and `spawn.facts` never redoes a workflow stage | `Mod.test_workflow_stages_and_teammate_roles_without_a_file_are_routed`, `Mod.test_a_workflow_stage_is_never_redone` | | A subagent or teammate on the main conversation's model with no other level runs at the session's level ([model configuration](https://code.claude.com/docs/en/model-config.md#effort-level-of-subagents-and-teammates)) | `router._session_floor` never sets less there. The mod reads the level from the main loop's `turn.step`, the fallback from `effort.level` (`spawn.facts`) | `test_an_agent_on_the_sessions_own_model_runs_at_least_at_the_sessions_effort`, `test_the_sessions_effort_counts_only_for_a_call_from_the_main_conversation`, Node "the main loop's effort reaches mod-spawn, and the agent steps at the effort the CLI decided" | | `CLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL` runs every workflow agent on one model. Only the changelog lists it, in the notes for 2.1.296 ([changelog](https://code.claude.com/docs/en/changelog.md)); the environment variables page doesn't | `router.decide` sets only the effort of a workflow agent whose script names no model | `MachineReadable.test_a_workflow_model_pin_keeps_its_model_and_the_router_sets_only_effort` | | Claude Code skips a project or user agent file with no `name`, with a `name` that starts with `-`, contains `:` or is longer than 256 characters, or with no `description`, and a plugin agent with no `name` loads under its filename ([subagent files Claude Code skips](https://code.claude.com/docs/en/sub-agents.md#subagent-files-claude-code-skips)). An empty `description`, or a `name` or `description` that YAML reads as no text, such as `5` or `true`, counts as none, observed on Claude Code 2.1.329 and 2.1.332 | `agents.parse` reads no agent from such a file, so `agents.find` goes on to the next source | `SkippedAgentFiles.test_a_project_file_with_no_name_is_skipped_so_a_user_agent_of_its_stem_is_found`, `SkippedAgentFiles.test_a_file_whose_name_claude_code_refuses_or_that_has_no_description_is_skipped` | | A fork has its parent's model and history ([forks](https://code.claude.com/docs/en/sub-agents.md#fork-the-current-conversation)) | `router.decide` keeps a fork, and the mod passes forks and resumed runs through | `test_fork_is_never_touched`, Node "forks and resumed runs pass through with no CLI call" | | An agent's `effort` overrides the session's, and a call can pass its own ([effort level](https://code.claude.com/docs/en/sub-agents.md#choose-an-effort-level)) | `router._effort_decided`: an effort is set only when the call, the agent, `CLAUDE_CODE_EFFORT_LEVEL` and `CLAUDE_CODE_SUBAGENT_EFFORT` set none. A "Redo:" call climbs past the agent's own (`router._redo`) | `test_an_agents_own_effort_and_a_callers_effort_are_kept`, `test_a_redo_of_the_architect_climbs_past_its_own_model_unless_the_call_names_one` | | `CLAUDE_CODE_SUBAGENT_EFFORT` doesn't apply to forks, forked skills or teammates ([environment variables](https://code.claude.com/docs/en/env-vars.md#variables)) | `router._env_effort` skips it for a teammate | `test_the_subagent_effort_variable_does_not_reach_a_teammate` | | A `maxEffortLevel` cap still applies under `CLAUDE_CODE_EFFORT_LEVEL` ([environment variables](https://code.claude.com/docs/en/env-vars.md#variables)) | `router.capped` holds each effort it sets to the lowest cap of any settings source (`allowlist.Allowlist.effort_cap`) | `Mod.test_a_max_effort_level_holds_every_effort_the_router_sets`, `Allowlist.test_max_effort_level_caps_each_family_at_the_lowest_source` | | Start Haiku 5.5 at `medium` for most work, agentic coding included, Sonnet 5.5 at `medium` for well-specified agentic coding and `high` for harder or longer work, and Fable 5.2 at `high` ([effort](https://platform.claude.com/docs/en/build-with-claude/effort)) | `ladder.effort_on` gives a named model with no effort its lowest level's: `medium` on Haiku and `high` on Sonnet, Opus and Fable | `test_the_shipped_ladder`, `test_a_model_named_on_the_call_is_kept_and_gets_its_rungs_effort` | | When quality falls short, restore lowered effort, else try the next tier up at its default effort ([cost and intelligence](https://platform.claude.com/docs/en/about-claude/models/optimizing-for-cost-and-intelligence#start-here)), and start the next model up at a lower effort level than the smaller one ran at ([which model to build with](https://claude.dev/blog/which-claude-model-should-you-build-with)) | `router._redo`: one effort step while the run it redoes was below `high`, else the next stronger usable model one effort level below that run's and at least `medium`, else one more step | `test_a_redo_raises_effort_below_high_and_moves_model_from_high`, `Router.test_a_redos_stronger_model_starts_one_effort_level_below_the_run_and_never_below_medium` | | Switching the conversation's model makes the next request read the whole history uncached ([prompt caching](https://code.claude.com/docs/en/prompt-caching.md#switching-models)) | No hook changes the conversation's model, and the mod's `turn.step` changes effort only for a subagent. The session check runs `/model` only for a setup the person picks, once per session, and only while the conversation has no prompt in it | Node "a main-loop turn's start in the session the layers went to asks the runtime nothing, and its effort is left alone", Node "a first turn that starts before the question is on screen keeps it away for the session", `SessionCheck.test_it_asks_once_per_session` | | `updatedInput` replaces the whole tool input ([PreToolUse](https://code.claude.com/docs/en/hooks.md#pretooluse-decision-control)) | `fallback._rewritten_input` keeps every field and changes only `model` and `effort`, and `hooks.pre_agent` rewrites no call whose input didn't parse | `test_a_rewrite_changes_two_fields_and_approves_nothing`, `test_an_agent_call_whose_input_does_not_parse_is_left_alone` | | Exit code 2 blocks, and any other failure lets the action go ahead unless the hook sets `onFailure: "block"`, which these hooks don't. On Windows without Git Bash a failing shell-form `PreToolUse` hook can block instead. These hooks are exec form, `command` plus `args` ([exit codes](https://code.claude.com/docs/en/hooks.md#exit-code-output)) | `scripts/model-router.sh` ends a hook with 0, or 1 on an error, never 2, and 0 when no Python runs; `cli.main` exits 1 on an exception a handler raised, so Claude Code shows a hook error notice | `Launcher.test_a_hook_command_never_exits_2`, `NoPython.test_every_hook_exits_0_and_a_command_explains`, `test_hooks_never_break_on_garbage`, `SpawnAnswer.test_a_handler_that_raises_exits_1_naming_only_its_type_and_place`, `Shipped.test_hooks_call_existing_commands` | | The Stop input's `background_tasks` lists tasks in flight, unknown types included ([Stop input](https://code.claude.com/docs/en/hooks.md#stop-input)) | `gates.still_running` holds the check while any task is listed | `test_background_work_still_running_holds_the_check_and_keeps_the_ask`, `test_the_check_waits_for_any_background_task` | | A Stop hook gives guidance through `additionalContext` ([Stop decision control](https://code.claude.com/docs/en/hooks.md#stop-decision-control)) and can enforce a check ([best practices](https://code.claude.com/docs/en/best-practices.md#give-claude-a-check-to-run)) | `hooks.stop` returns the ask as `additionalContext`, once per batch of project edits no check followed (`gates.before_stop`). It runs nothing itself | `test_the_ask_is_guidance_for_any_kind_of_work_and_names_no_reviewer`, `Gates.test_asks_once_when_work_changed_and_nothing_checked_it` | | Internal agents fire `SubagentStop` with an empty `agent_type` unless the session runs as an agent (`--agent` or the `agent` setting), and a matcher that can't match "" skips them ([SubagentStop](https://code.claude.com/docs/en/hooks.md#subagentstop)) | `hooks/hooks.json` matches `.` | `Shipped.test_agent_hooks_match_the_agent_tool_and_skip_internal_agents` | | A `SubagentStop` hook's output goes to the subagent, and context for the parent session after a subagent returns comes from a `PostToolUse` hook on the `Agent` tool ([SubagentStop](https://code.claude.com/docs/en/hooks.md#subagentstop)). A `UserPromptSubmit` hook's `additionalContext` is wrapped in a system reminder and inserted where the hook fired ([add context for Claude](https://code.claude.com/docs/en/hooks.md#add-context-for-claude)), and that hook fires for a background agent's notification (measured on 2.1.332) | `hooks.agent_stopped` blocks nothing. It keeps a line about the project files the subagent's shell changed, and the main conversation gets it from `hooks.post_agent`, `hooks.user_prompt` or `hooks.stop`, whichever runs first. The line that no check has run on an agent's work goes the same two ways | `SubagentChecks.test_the_main_conversation_is_told_once_about_a_file_an_agents_shell_changed`, `SubagentChecks.test_a_note_waits_for_whichever_hook_of_the_main_conversation_comes_first`, `SubagentChecks.test_an_agents_work_comes_back_with_a_line_that_no_check_has_run_on_it` | | In auto mode a subagent delivers its report through `SubagentHandback` before it stops, and a `PreToolUse` hook matched on that tool gets the call ([SubagentStop](https://code.claude.com/docs/en/hooks.md#subagentstop)) | `hooks.handing_back` keeps the line at that call and lets the call through, and `hooks.agent_stopped` adds nothing once a report is back | `SubagentChecks.test_an_agent_that_hands_its_report_back_is_noted_at_the_hand_back` | | `agent_type` is present on the main thread of a session started with `--agent` ([common input fields](https://code.claude.com/docs/en/hooks.md#common-input-fields)), and a teammate in a terminal pane of its own is such a session (measured on 2.1.332: its `SessionStart` input carries its agent type) | `hooks._delegating` leaves delegation out of that session, and `mod.check` asks it nothing | `Notes.test_a_session_that_runs_as_an_agent_is_not_told_to_hand_its_work_out`, Node "a session that runs as an agent says so to the runtime at its start and at the session check" | | An Agent result reports `resolvedModel`, and `modelsUsed` when the model was swapped ([hooks](https://code.claude.com/docs/en/hooks.md)) | `hooks.post_agent` records the model that ran (`health.ran`), and a swapped run counts as no evidence (`calls.models_used`) | `test_results_teach_the_registry_which_models_really_run`, `Health.test_a_swapped_run_is_no_evidence` | | The type files Claude Code writes for your build are the ones to trust ([types](https://code.claude.com/docs/en/plugins/mods/create.md#get-type-definitions-for-your-version)) | Each event and field `hooks/router.ts` reads outside `tool.call` is checked against those types, and in CI against Claude Code's published ones (`tests/mod/typecheck.sh`) | `ModApiTypes.test_router_ts_uses_only_events_and_fields_the_types_declare`, `Workflows.test_the_type_check_also_runs_the_mod_field_check_on_the_types_it_downloads` | | `agent.spawn` takes a model through `next` ([subagent starts](https://code.claude.com/docs/en/plugins/mods/reference.md#subagent-starts)), and `turn.step` takes a model ([follow a turn](https://code.claude.com/docs/en/plugins/mods/events.md#follow-a-turn)) and an effort (mod API types `TurnStepInput`) | `hooks/router.ts` sets a spawn's model in `agent.spawn` and its effort in `turn.step` | Node "a spawn passes the pick model to next" and "a routed agent steps at the pick effort" | | Plugins' `PreToolUse` hooks run after the last mod calls `next` ([order](https://code.claude.com/docs/en/plugins/mods/events.md#where-settings-hooks-run-in-the-order)) | The mod's `tool.call` hook marks each `Agent` call it will route, and the fallback stands down only for a marked call (`mod.routes`) | `Mod.test_the_settings_hook_stands_down_only_for_a_call_the_mod_marked`, Node "an Agent call is marked for the fallback only while the runtime answers" | | `$.agent.list()` gives each subagent's tokens per model and a client-side cost estimate, and lists no workflow agent (mod API types `AgentInfo`, `SessionCost`; [mods reference](https://code.claude.com/docs/en/plugins/mods/reference.md)) | `agentUsage` in `hooks/router.ts` sends those figures at a subagent's turn end, and `/model-router:usage` labels the dollars an estimate | Node "a subagent's turn end sends Claude Code's own figures for it, and the main loop's sends nothing", `Reports.test_usage_report` | | A `tool.call` hook answers a call with `{ deny: reason }` and no `next`, and Claude reads the reason as the tool's result; it fires for a subagent's calls too ([guard or change a tool call](https://code.claude.com/docs/en/plugins/mods/events.md#guard-or-change-a-tool-call)) | Under `delegation: strict`, the mod's second `tool.call` hook refuses a main-conversation work call once the total reaches the threshold, and skips every call with an `agentId`, so a subagent's own calls are never counted or refused | Node "strict: the first call after the total reaches after is refused without running, until an agent starts" | | Where a session uses the built-in `web-fetch` subagent, Claude reads a web page with an `Agent` call for it and the main conversation has no `WebFetch` tool of its own. The subagent runs on Haiku, or on the conversation's model where `availableModels` leaves Haiku out, and other subagents still call `WebFetch` themselves ([the web-fetch subagent](https://code.claude.com/docs/en/tools-reference.md#which-model-the-web-fetch-subagent-runs-on), [sub-agents](https://code.claude.com/docs/en/sub-agents.md#built-in-subagents)) | The mod counts an `Agent` call for `web-fetch` as a work call, and its start sets no total back, so a page read is no hand-off. Under `strict` a refused one is told to give the page to another agent. The router finds no definition for it and leaves its model alone | Node "the built-in web-fetch agent reads a page for the conversation: its call is work, and its start resets nothing", `ModStartRules.test_mod_start_answers_the_delegation_the_mod_enforces`, `Router.test_the_built_in_web_fetch_agent_is_left_on_claude_codes_own_model` | | `engines`, `network` and `userConfig` are manifest fields ([manifest](https://code.claude.com/docs/en/plugins/manifest-reference.md#fields)) | `plugin.json` requires Claude Code 2.1.329 or later, declares no `network` hosts and offers six options | `Shipped.test_the_claude_code_floor_is_the_version_the_manifest_and_teammate_effort_need`, `SecurityClaims.test_nothing_shipped_opens_a_connection`, `Shipped.test_the_cli_takes_every_option_plugin_json_declares` | | Options reach hooks as `CLAUDE_PLUGIN_OPTION_