Spawn state: when Downshift works and when it switches
Downshift by Tiago Vilas Boas. Updated . Source on GitHub
Downshift by Tiago Vilas Boas https://github.com/tiagovilasboas/downshift-ai
Every subagent spawn the hook sees gets exactly one state, computed once in internal/telemetry/spawn_state.go from the decision event. Every harness gets it through the shared runner (runHookAdapter); no adapter holds any of it.
| State | Meaning |
|---|---|
switched |
Downshift changed the spawn's model or effort |
held |
A change was considered; a guardrail (HELD_*), the credit gate or a guessed baseline kept the spawn as it was. The proposed change is not applied |
observed |
Downshift looked and had nothing to change |
paused |
downshift session --pause: classified and logged, never changed |
unrouted |
A baseline line that is not a pause. Only older versions wrote one (their control group or no-route switch). Classified, never changed. No current version leaves a spawn in this state |
blocked |
A policy-mode harness (KiroCrew) denied the spawn for a respawn |
Held wins over switched: a hold means the change was not applied.
Where it shows
| Surface | What you see | Harnesses |
|---|---|---|
| stderr, one line per spawn | downshift: spawn switched opus → haiku, effort high → low · TRIVIAL, spawn held on opus (would be haiku) [HELD_UNCONFIDENT_DOWNSHIFT], spawn observed, spawn unchanged on opus |
all (whether the harness UI shows hook stderr is harness-dependent; see the matrix) |
downshift watch |
first line: ● downshift active · last spawn 12s ago: ... or ○ downshift idle · ... (idle after 5 min without a spawn); then the tree |
all |
downshift session / --json |
header N switched, M held; each row's reason starts switched from <model>; JSON rows carry state, from_model, reason_codes, and the view switched, held |
all |
| statusline | ◆ downshift · 3 subagents · 2 switched · 1 held · ... |
harnesses with a statusline bridge |
live.json |
the record below, for a panel | all |
Idle means no recent spawn. The hook only runs when a subagent is spawned, so it cannot show a heartbeat between spawns.
live.json (for panels and mods)
Written atomically next to the event log (~/.downshift/live.json, or beside DOWNSHIFT_EVENT_LOG) on every spawn. Best effort and fail-open: a write failure never delays or blocks a spawn. No prompt, task text, file path, raw session or agent id is stored; session is the first 8 hex of the hashed id.
{
"updated": "2026-10-19T12:00:00.123Z",
"session": "a1b2c3d4",
"counts": {"switched": 2, "held": 1, "observed": 4},
"last": {
"state": "switched",
"harness": "claude-code",
"session": "a1b2c3d4",
"time": "2026-10-19T12:00:00.123Z",
"from_model": "claude-opus-5-5",
"to_model": "claude-haiku-5-5",
"from_effort": "high",
"to_effort": "low",
"recommended_model": "",
"complexity": "TRIVIAL",
"reason_codes": ["CLASSIFIER_CONFIDENT"]
}
}
counts reset when the session changes. A reader treats updated older than 5 minutes as idle. For held, to_model is what the child runs on and recommended_model is what Downshift would have chosen.
downshift session --panel (what the agents panel reads)
Prompt-free JSON for the selected session (latest, or --session), built in telemetry.BuildPanel. Ready-made labels, so a panel only draws:
{"session":"a1b2c3d4","summary":"Downshift · 2 model · 1 held","switched":2,"model_switched":2,"held":1,"observed":4,
"tokens":{"children":4,"saved_children":2,"work_tokens":5200,"work_saved":3200,
"cache_tokens":180000,"cache_saved":104000},
"tokens_line":"62% of work · 58% of cache on a lower tier",
"by_agent_type":[{"agent_type":"general-purpose","tokens":{...},
"line":"general-purpose: work 70% · cache 64% (2 of 3 agents)"}],
"spawns":[{"tool_use":"<sha256 hex>","state":"switched",
"from_model":"claude-opus-5-5","to_model":"claude-sonnet-5-5",
"label":"opus → sonnet (mid)",
"tokens":{...},"tokens_label":"48k tokens · lower tier than opus",
"saved_total":58000,"saved_short":"58k"}]}
Labels: opus → sonnet (mid), held: original model kept, kept, unrouted (older log), paused (unrouted), blocked: respawn on another model. tool_use is telemetry.ToolUseKey(tool_use_id): sha256 of harness-downshift-session-v1: + the harness tool call id.
summary is the band's one line, composed in Go (telemetry.PanelSummary): Downshift · N model · M effort · K held, a zero count left out, "" when nothing was changed or held. A panel prints it verbatim and does no arithmetic.
saved_total is a spawn's work plus cache tokens saved from the requested model (telemetry.SpawnSaved), 0 while unknown; saved_short is the same figure in the CLI's token format (58k, 1.2M), "" when saved_total is 0.
Trimming the panel: --no-report and --brief
Both need --panel (alone they are a usage error). The default answer is the whole panel above and is unchanged.
--no-reportskips the 30-day report. The full logs are not read, only the tail, so the call stays flat as the log grows. The output has noreport,compactorortokens_saved_estimate; the session fields are the same.--briefprints only what the agents band draws:{session, summary, switched, model_switched, effort_changed, held, held_guardrail, observed, spawns[]}, where each spawn is{tool_use, state, from_model, to_model, observed_model, label, saved_total, saved_short}. It dropstokens,tokens_line,by_agent_typeand each spawn'stokensandtokens_label. Without--no-reportit addstokens_saved_estimate(the report's figure, a number) andtokens_saved_short(74k,1.2M,""when 0). With--no-reportneither appears.
observed_model is optional and per spawn (telemetry.PanelSpawn): the model the child was observed to run on, taken from its resolved record or else its usage record. It is set only when that model is known and differs from to_model; an equal, dated-equal, unknown or missing observation leaves the key out. It holds model ids only, never prompts.
Tokens, never dollars (owner decision 2026-10-19). "Saved" means a child's tokens ran on a lower tier than the one requested (telemetry.TokenSavings, the same buckets as stats --export tokens_rerouted); work (input+output) and cache (read+write) are counted apart. tokens_line and tokens_label are "" until a child's tokens are known; a reader then draws no figure. A child on a higher tier reads higher tier than <model> and adds to work_pricier / cache_pricier, never to the saved share. Unrouted, held, kept and refuted children count in the totals. Harnesses without a proven token source, including Cursor and Codex, show no token figure rather than zero. OpenCode 2.2.5 has a verified per-child token source; see the current harness matrix for its scope and limits. No dollars: downshift report is tokens only.
The same figures appear in downshift session (header, a tokens column per row, a by type line, shown only for types that saved something), the statusline (saved N% of work · M% of cache), downshift watch, dsmon, the child-end line (48k tokens (work 2.1k, cache 46k) · lower tier than opus) and the stats headline (downshift stats; stats --detail for more). downshift session has no tokens for one decision and says only where they would run: → small: opus → haiku · its tokens would run on a cheaper model than requested, or (not applied, tokens stay on opus) when the hook would leave the spawn alone.
Compactor in the panel JSON
session --panel adds an optional compactor block that totals the whole exec-events.jsonl (owner decision 2026-10-21): every session and every run, with or without a session hash. It does not depend on --session; the routing figures beside it stay per session. {scope, commands, compacted, raw_bytes, saved_bytes, estimated_tokens_saved, token_estimate}, where scope is "all". Bytes are measured; estimated_tokens_saved is saved_bytes / 4, an estimate. An empty or missing log means no block, never zeros.
The final figure: tokens_saved_estimate
One number, owner decision 2026-10-21, defined once in telemetry.TokensSavedEstimate: tokens_saved_estimate = Compactor saved_bytes / 4, in the scope of the view. Only the Compactor keeps tokens out of the context, so only it is counted. The tokens that ran on a lower tier than requested (work_saved + cache_saved) were spent; they are shown apart and are never added (before 2026-11-01 they were). The figure is an estimate and is labelled one everywhere (~ in the panel, Tokens saved (estimate) in downshift report). The parts stay in the JSON (tokens, compactor; in report --json tokens_saved, compactor_saved_bytes, compactor_tokens_estimate).
Each run still logs the hashed session when one is known (telemetry.HashSessionID, never the raw id): the hook puts it on the wrapped command (downshift compact --session=<hash> -- …), from the payload's session_id or, when absent, the uuid file name of transcript_path. A run with no flag (a direct downshift compact -- … by an agent or a script) carries no session; it does not fall back to a harness env var, so direct compactor calls are not attributed to a harness they did not originate from.
Each run also records two additive fields (absent in old rows, treated as "unknown" by callers): harness, the harness detected from the environment (or "unknown"), and entry, which is "hook" when --session= was set by a harness adapter and "direct" when the agent or user ran the compactor without it.
What a harness cannot honor
Computing the state is not conditional on the harness. What varies is only display: the child-end line and statusline need CanShowChildLine / a statusline bridge (see harness-matrix.md), and a harness may not show hook stderr in its UI. live.json, downshift watch and downshift session work for every harness that logs spawns.
More docs
- Install Downshift: Claude Code, Codex and Cursor hook setupGuide
- Downshift configuration: state directory and local settingsGuide
- Downshift and Claude Code subagents: when routing can actGuide
- Downshift session view: subagent tree, reasons and pauseGuide
- Downshift report: routed spawn tokens and reworkGuide
- Downshift evidence ladder: what each saving figure meansGuide
- Downshift companions: Headroom and Claude Code mods to pairGuide
- Downshift capability matrix: status and evidence per featureReference
- Downshift capability matrix, part 2: context and packagingReference
- Downshift harness matrix: Claude Code, Codex, Cursor statusReference
- Downshift value per harness: observed tokens per harnessReference
- Downshift offline simulation: routing without model callsGuide
- Downshift session models: which model IDs a hook may writeReference
- Downshift complexity weights: how a task becomes a modelReference
- Downshift architecture: deterministic hook and offline CLIDesign
- Downshift routed vs control: first Claude Code A/B resultsEvidence
- Downshift real usage: a Claude Code day and the last 30 daysEvidence