A band above the prompt with each running subagent's type, model, effort, steps, context, advisor calls and estimated cost; a /fleet pane, /steer…

A Claude Code plugin marketplace from Darling Data.
/plugin marketplace add erikdarlingdata/claude-plugins
sqlserver-query-plansTeaches Claude to read a SQL Server execution plan and say what is actually slow, and why.
/plugin install sqlserver-query-plans@erikdarling
Point Claude at a .sqlplan file and ask. The skill is model-invoked — you do not need to call it explicitly.
The hard part of plan analysis is not spotting operators. It is knowing which numbers mean what they appear to mean. This plugin is built mostly out of the conclusions that sound authoritative and are wrong:
ActualElapsedms ranks them by depth and always crowns the root node. Batch mode reports standalone times. Exchange operators report times that are close to meaningless.EstimateRows is per-execution; ActualRows is a total. Without dividing by ActualExecutions, the inner side of every nested loop looks catastrophically underestimated when it may have estimated perfectly.Impact figure is a percentage of an estimated cost.It also ships scripts/extract.py, which flattens a .sqlplan into a compact digest. This is not a convenience:
.sqlplan files are UTF-16, so grep silently matches nothing and reports no error. A negative result from grep on a plan file is worthless.encoding="utf-16", because they were opened and re-saved. Strict XML parsers reject them.The extractor handles the encoding, computes correct self-time attribution (subtracting children in row mode, within a thread rather than across threads in parallel plans, and not at all in batch mode), normalizes cardinality per execution, and recognizes the optimizer's default-guess selectivity fingerprints. --node N drills into a single operator; --sql recovers full statement text.
Requires Python 3 (standard library only). Without it, the skill degrades to a documented grep-based fallback and says plainly what it cannot determine.
This plugin also works in GitHub Copilot CLI, which reads the same SKILL.md and plugin.json format.
copilot plugin marketplace add erikdarlingdata/claude-plugins
copilot plugin install sqlserver-query-plans@erikdarling
Or add just the skill, without the marketplace:
/skills add ./plugins/sqlserver-query-plans/skills/query-plan-analysis
As in Claude Code, the skill is model-invoked: point Copilot at a .sqlplan and ask.
Small hook modules for people who run several agents at once. Each one is a plugin of its own. Install only the ones you want, and set their options in /config (or under pluginConfigs in settings.json). They need a Claude Code version that loads plugin hook modules.
subagent-fenceStops the mistakes an unattended agent makes that cannot be taken back.
/plugin install subagent-fence@erikdarling
For the main session and every subagent it refuses four things. A force-push. A push to a protected branch. A git command that skips the repository's hooks. Killing processes by name (pkill, killall, taskkill /IM, Stop-Process -Name), because a name match can kill another session's processes.
Three more guards are off until you set them. One bans folders: nothing reads, writes or enters them. One keeps a subagent from editing a plain git checkout, or running a changing git command there, so it works in its own worktree. One stops a subagent reading a big text file whole instead of by offset and limit.
| Option | Default | What it does | | :- | :- | :- | | guard_force_push | on | Refuse --force, --force-with-lease, -f and +refspec pushes | | guard_protected_branches | on | Refuse a push that targets a protected branch | | protected_branches | main, master, dev | The branch names a push cannot target | | guard_no_verify | on | Refuse the git flag that skips hooks | | guard_kill_by_name | on | Refuse killing processes by name | | banned_paths | none | Folders that nothing reads, writes or enters | | guard_shared_checkout | off | Keep subagents out of plain git checkouts | | shared_checkout_root | empty | Limit that guard to checkouts under this folder. Empty detects a plain checkout anywhere: a folder whose .git is a directory, where a linked worktree has a .git file | | read_limit_bytes | 0 (off) | Refuse a subagent's Read of a text file over this size when it gives no limit |
model-allowlistChecks the model a subagent is spawned with.
/plugin install model-allowlist@erikdarling
A pinned model id goes stale: a dated or versioned name keeps pointing at an old model after the tier moves on. This refuses a spawn that names one and asks for a tier alias (opus, sonnet, haiku) instead. A spawn with no model is always allowed, because the agent file or the parent decides then.
You can add rules of your own. One example: the lane agent runs Sonnet, and Opus only when the brief says design, security or hard debugging. With no rules, every alias is allowed.
| Option | Default | What it does | | :- | :- | :- | | refuse_pinned_ids | on | Refuse any model that is not an allowed alias | | allowed_aliases | opus, sonnet, haiku, fable, inherit | The names that count as aliases. A trailing [1m]-style suffix is ignored | | rules | none | One rule per entry, written agent type pattern => model => brief pattern => message |
A rule applies when the spawn's agent type matches the first pattern and it names that model (* for any model). The brief must then match the brief pattern, or the spawn is refused. Leave the brief pattern empty to refuse the pairing outright. The message is optional and can use {type} and {model}. Patterns are case-insensitive regular expressions. A rule that does not parse is skipped. For example:
^(lane|worker-.*)$ => opus => \b(design|security|hard[- ]debug) => {type} runs sonnet; name the reason in the brief to use opus.
seat-resumeBrings interrupted sessions back after a crash, a reboot or a closed terminal.
/plugin install seat-resume@erikdarling
The plugin writes one small file per interactive session: its id, name, folder, permission mode and last activity. It marks the file when the session ends. /resume-sessions lists the sessions that died or were interrupted in the last 72 hours, with the command that reopens each. The script's -Launch switch reopens all of them in terminal tabs. Sessions you left with /exit, Ctrl+C or /clear stay closed. The plugin name still says "seat", but everything you see says "session".
This one is Windows only. The bundled script (scripts/resume-sessions.ps1) is PowerShell. It compares Windows process start times to tell a live session from a reused process id. It reopens tabs in WezTerm or Windows Terminal. Nobody has tried the plugin on macOS or Linux.
| Option | Default | What it does | | :- | :- | :- | | registry_dir | empty: session-registry in your Claude config folder | Where the per-session files go | | sessions_dir | empty: sessions in your Claude config folder | Where Claude Code records its running sessions | | resume_script | empty: the bundled script | The PowerShell script /resume-sessions runs | | powershell | pwsh | The program that runs it (powershell for Windows PowerShell 5.1) | | terminal | wezterm | wezterm or windows-terminal: where -Launch reopens sessions |
The Claude config folder is CLAUDE_CONFIG_DIR when that is set, otherwise .claude in your home folder.
open-asksKeeps the questions Claude asks you from scrolling away. Every time a reply asks you something or leaves a decision to you, Claude records it. The question stays in a band above your prompt, with Claude's recommended answer, until you answer, decline or drop it. Claude gets ask_add, ask_resolve and ask_list tools. You get /asks (done <ids>, clear, hide, show). Open asks are saved per session, so a resumed session still has them.
/plugin install open-asks@erikdarling
| Option | Default | What it does |
|---|---|---|
maxBandAsks | 6 | Most asks the band draws. The rest stay in /asks. |
maxQuestionChars | 400 | Longest question or recommendation shown before it is cut. |
keepDays | 30 | Saved asks from other sessions are removed after this many days. 0 keeps them. |
subagent-bandA live view of your subagents. The band above the prompt has one row per running subagent: type, model, effort, steps, context size, advisor calls and estimated cost. /fleet opens a pane with every subagent of the session, finished ones included. /subagent-cost totals the estimated cost by agent type and by issue number in the description, with the main session's own cost. /steer <id> <text> sends a running subagent a message. Claude gets a cheap subagent_vitals tool, so it does not have to read output files to check progress. Costs are list-price estimates, not your bill.
/plugin install subagent-band@erikdarling
| Option | Default | What it does |
|---|---|---|
priceTable | opus:4:20, sonnet:2:10, haiku-5-5:0.1:0.5, haiku:1:5, fable:10:50 | Input and output USD per million tokens for each model family. A model id is matched by containing the family name, first entry first. Haiku 5.5 requests with a prompt over 100,000 tokens (cache reads and writes included) are priced at 5x for the whole request, as Anthropic bills them. |
cacheWriteMultiplier | 1.25 | Cache write price as a multiple of the input price. |
cacheReadMultiplier | 0.1 | Cache read price as a multiple of the input price. |
usage-budgetWatches the account's 5-hour and 7-day usage windows. A toast tells you each time a window crosses a percent. Past a higher percent, Claude also gets a one-time note so it can stop starting optional work and write its handoff. Past the last one, new subagents are refused until the window resets.
It also checks pace. When the 7-day usage runs 10 or more points ahead of the share of the week that has passed (70% used with 60% of the week gone), you get a toast and Claude gets a note, once per window and again each time the gap grows by another margin. New subagents are refused too. The message gives the usage, the elapsed share, and the UTC time the refusal lifts if usage stays flat: the moment the week catches up to within the margin. Waiting until then lifts it, and so does setting paceMargin to 0, which turns the check off. Without a reset time for the window, the check is skipped.
The status line shows the percents, but a session cannot read its own status line. So the plugin also writes the figures to <config>/usage-budget/latest.json each time they come in. <config> is CLAUDE_CONFIG_DIR, or else the .claude folder in your home folder. A session reads that file when it needs the numbers, for example to log a usage check:
{
"at": "2026-10-14T04:48:00.000Z",
"rateLimits": [
{ "kind": "five_hour", "percentUsed": 41, "resetsAt": "2026-10-14T08:00:00Z" },
{ "kind": "seven_day", "percentUsed": 75, "resetsAt": "2026-10-17T00:00:00Z" }
],
"pace": { "used": 75, "elapsed": 60, "ahead": 15, "until": "2026-10-14 13:12Z" }
}
at is the UTC time of the write. resetsAt is null when the window has no reset time. pace is null unless 7-day usage runs at least paceMargin points ahead of the week. Then it holds the figures the pace warning gives (elapsed and ahead to a tenth of a point), and until is the UTC minute the refusal lifts if usage stays flat. Each write replaces the file, so it holds only the latest figures. The write is not atomic, so a reader that gets JSON it cannot parse should read again. A failed write never stops the plugin. The first one in a session raises a toast with the path and the reason, so the file does not go stale without a word. If the reason is a missing folder, create the folder once.
/plugin install usage-budget@erikdarling
| Option | Default | What it does |
|---|---|---|
warnPercents | 70, 85, 95 | Percents that raise a toast, once each per window. |
tellModelAtPercent | 85 | From here the model is told as well. 0 never tells it. |
spawnGatePercent | 95 | A new subagent is refused when either window is at or past this. 0 turns the refusal off. |
paceMargin | 10 | Points the 7-day usage may run ahead of the share of the week passed before the warning and the refusal. 0 turns the pace check off. |
usage_file | <config>/usage-budget/latest.json | Where the latest figures are written. A leading <config> stands for the Claude config folder. An empty value turns the file off. |
subagent-wallA wall-clock limit for subagents. After a warning time, a subagent is told to finish up. After the limit, it can only run git and gh commands and write .md or .txt files. It commits, reports and ends instead of running on. It also nudges a code-changing subagent that has a lot of context but no edited file to stop exploring and make the change. The main session is never limited.
/plugin install subagent-wall@erikdarling
| Option | Default | What it does |
|---|---|---|
warnMinutes | 45 | Minutes before a subagent is told to finish up. 0 turns the warning off. |
limitMinutes | 60 | Minutes before it is held to git, gh and note writes. 0 turns the limit off. |
noEditNudgeK | 100 | Thousands of context tokens before the no-edit nudge. 0 turns it off. |
codeAgentTypes | general-purpose | Comma-separated subagent types that get the no-edit nudge. |
This repository is also a pi package: the root package.json declares every plugins/*/skills and plugins/*/extensions directory, and pi reads the same SKILL.md format the other two harnesses do. Install straight from git — no marketplace step:
pi install git:github.com/erikdarlingdata/claude-plugins
As everywhere else, the skill is model-invoked: point pi at a .sqlplan and ask.
pi-session-resume (pi only)Your machine restarts for updates with a dozen pi sessions open; this brings them all back with one command, as terminal tabs, in their original directories, with full history:
pi-resume-sessions
An extension (auto-loaded by the install above) records every open interactive session; the pi-resume-sessions script reopens the interrupted ones — Ghostty tabs on macOS, tmux anywhere. Sessions you quit deliberately (Ctrl+D, /quit) stay closed; sessions killed by a reboot, a closed window, or a crash come back. Idle-time filters keep abandoned sessions from resurrecting.
The script needs a one-time symlink onto your PATH, and macOS needs a one-time Automation permission — see plugins/pi-session-resume/README.md for both, plus the design notes. This one is pi-only: Claude Code and Copilot CLI don't load pi extensions.
pi-subagent-watchdog (pi only)Background subagents only report back when they finish — nothing wakes the orchestrator while one wedges on a giant grep or balloons from 200k to 2M tokens. This extension (auto-loaded by the install above) polls every running subagent's live vitals — tokens, cost, context %, tool uses, turns, wall clock, compactions — and batches nearby threshold crossings into one compact orchestrator check-in. Full structured records persist outside LLM context; per-agent and fleet-wide rate limits keep the watchdog from becoming its own token amplifier. Two orchestrator postures: guide (assess with judgment) and strict (thresholds are budgets — wrap up by default, one evidence-cited extension max). Optional automatic hard stop handles the truly wedged, with the outcome reported from the RPC reply rather than assumed. An optional exact model invariant hard-stops any top-level child that bypasses the manager's pre-spawn model policy. Optional per-agent cost signal and hard stop, plus session and daily USD budget warnings. The CLI surfaces also identify each child's effective model and thinking level.
Humans get a /watchdog panel (vitals, manual check-ins, steering, hard stop) plus /watchdog help | status | config | reload — config edits apply live, no session restart. See plugins/pi-subagent-watchdog/README.md for signals, modes, and design notes. Requires the pi-subagents extension; pi-only for the same reason as above.
pi-subagent-guardrails (pi only)Token-budget guardrails for multi-agent setups, built after an overnight orchestration burned through its usage limit (95% of the spend came at more than 150k context). It has three pieces:
guardrails.md: the written rules for fan-out caps, model tiers, context discipline, session length and ranking.lane agent type for code-editing lanes: Sonnet, its own worktree, draft PRs, no fan-out tools.The wall is deliberately not auto-loaded, because it would wall off your interactive session too. See plugins/pi-subagent-guardrails/README.md for install and the recommended watchdog and pi-subagents settings.
pi-setup-guide.md — a distilled ~15-minute setup for pi written for Claude Code ex-pats: install, model/thinking defaults, the trust model, a Claude-to-pi habit translation table, a tested-together extension stack, full source for a few small quality-of-life extensions (refusal fallback, tab-title status, ! command wake-ups + autocomplete), how to point pi at years of accumulated Claude Code memory instead of migrating it, and a troubleshooting section of the gotchas that actually happened. The plugins in this repo (§11–§13 of the guide) slot into that stack.
Built by Erik Darling at Darling Data. SQL Server consulting, training, and free tools: <https://erikdarling.com>
MIT
hooks/register.tsx 288 lines1import { atom, read, update } from 'claude-code'
2import type { Register, TurnUsage } from 'claude-code'
3
4import type { Row } from '../types'
5
6const rows = atom({ plugin: 'subagent-band', key: 'rows' } as const, {} as Record<string, Row>)
7const isHidden = atom({ plugin: 'subagent-band', key: 'isHidden' } as const, false)
8const mainCost = atom({ plugin: 'subagent-band', key: 'mainCost' } as const, 0)
9
10const blank = (): Row => ({
11 type: '?', description: '', model: '?', effort: '?', steps: 0, context: 0, advisor: 0, cost: 0, isDone: false,
12 startedAt: 0, endedAt: 0, tools: 0, lastTool: '', outcome: '', steered: 0,
13})
14
15const FLEET = 'subagent-fleet'
16const VITALS_TOOL = 'subagent_vitals'
17const shortId = (id: string) => id.replace(/^a/, '').slice(0, 6)
18const mins = (row: Row, now: number) => Math.max(0, Math.round(((row.endedAt || now) - row.startedAt) / 60000))
19
20// One line per subagent: running ones first, then finished ones, newest first.
21const fleetLines = (all: Record<string, Row>, now: number, includeFinished: boolean) => {
22 const entries = Object.entries(all)
23 .filter(([, row]) => includeFinished || !row.isDone)
24 .sort(([, a], [, b]) => Number(a.isDone) - Number(b.isDone) || b.startedAt - a.startedAt)
25
26 return entries.map(([id, row]) =>
27 `${row.isDone ? `done(${row.outcome || '?'})` : 'running'} ${shortId(id)} ${row.type} ${row.model} ${row.effort} ` +
28 `${mins(row, now)}m step ${row.steps} tools ${row.tools}${row.lastTool && !row.isDone ? ` (last ${row.lastTool})` : ''} ` +
29 `ctx ${kilo(row.context)} ${usd(row.cost)}${row.advisor ? ` advisor ${row.advisor}` : ''}` +
30 `${row.steered ? ` steered ${row.steered}` : ''} | ${row.description}`)
31}
32
33// claude-sonnet-5-5-20261001 -> sonnet-5-5
34const shortModel = (id: string) => id.replace(/^claude-/, '').replace(/-\d{8}$/, '')
35const kilo = (n: number) => (n >= 1000 ? `${Math.round(n / 1000)}k` : String(n))
36const pad = (s: string, n: number) => (s.length >= n ? s.slice(0, n) : s + ' '.repeat(n - s.length))
37const usd = (n: number) => `$${n.toFixed(2)}`
38
39// Prices per million tokens (input, output), by model family: "opus:4:20, sonnet:2:10" -> [['opus', 4, 20], ['sonnet', 2, 10]].
40// A model whose id names none of the families is priced as the first one. Estimates, not the bill.
41type Prices = { table: [string, number, number][]; cacheWrite: number; cacheRead: number }
42// Order matters: the first family the model id contains prices it, so haiku-5-5 must come before haiku.
43const DEFAULT_PRICES = 'opus:4:20, sonnet:2:10, haiku-5-5:0.1:0.5, haiku:1:5, fable:10:50'
44
45function parsePrices(value: unknown, cacheWrite: unknown, cacheRead: unknown): Prices {
46 const parse = (text: string) =>
47 text
48 .split(',')
49 .map(part => part.trim().split(':'))
50 .flatMap(([family = '', input, output]): [string, number, number][] =>
51 family.trim() && Number.isFinite(Number(input)) && Number.isFinite(Number(output)) && input !== undefined && output !== undefined
52 ? [[family.trim().toLowerCase(), Number(input), Number(output)]]
53 : [])
54 const table = parse(String(value ?? '')).length > 0 ? parse(String(value)) : parse(DEFAULT_PRICES)
55
56 return { table, cacheWrite: Number(cacheWrite ?? 1.25), cacheRead: Number(cacheRead ?? 0.1) }
57}
58
59// Haiku 5.5 prices the whole request at 5x (input, cache and output alike) when its prompt, counting cache reads and
60// writes, is over 100,000 tokens (platform.claude.com/docs/en/about-claude/pricing, "Long context pricing"). The 5x
61// applies to a user's haiku-5-5 priceTable entry too, and the cache multipliers apply on top, as for every model.
62const LONG_PROMPT_TOKENS = 100_000
63const LONG_PROMPT_MULTIPLIER = 5
64
65const stepCost = (u: TurnUsage, prices: Prices) => {
66 const [family, input, output] = prices.table.find(([family]) => u.model.toLowerCase().includes(family)) ?? prices.table[0]
67 const prompt = u.input_tokens + u.cache_creation_input_tokens + u.cache_read_input_tokens
68 const tier = family === 'haiku-5-5' && prompt > LONG_PROMPT_TOKENS ? LONG_PROMPT_MULTIPLIER : 1
69
70 return tier * (u.input_tokens * input + u.cache_creation_input_tokens * prices.cacheWrite * input +
71 u.cache_read_input_tokens * prices.cacheRead * input + u.output_tokens * output) / 1e6
72}
73
74// The /subagent-cost report: this session's subagents by type, by issue number in the description, and the main session.
75const report = (all: Record<string, Row>, main: number) => {
76 const byType = new Map<string, { n: number; cost: number }>()
77 const byIssue = new Map<string, number>()
78 let total = 0
79 for (const row of Object.values(all)) {
80 const t = byType.get(row.type) ?? { n: 0, cost: 0 }
81 byType.set(row.type, { n: t.n + 1, cost: t.cost + row.cost })
82 for (const issue of new Set(row.description.match(/#\d+/g) ?? [])) {
83 byIssue.set(issue, (byIssue.get(issue) ?? 0) + row.cost)
84 }
85 total += row.cost
86 }
87 const lines = [`Estimated list-price cost this session: subagents ${usd(total)} (${Object.keys(all).length}), main session ${usd(main)}`]
88 for (const [type, t] of [...byType].sort((a, b) => b[1].cost - a[1].cost)) {
89 lines.push(` ${pad(type, 18)} ${pad(String(t.n), 4)} ${usd(t.cost)}`)
90 }
91 if (byIssue.size > 0) {
92 lines.push('By issue number in the agent description:')
93 for (const [issue, cost] of [...byIssue].sort((a, b) => b[1] - a[1]).slice(0, 15)) {
94 lines.push(` ${pad(issue, 8)} ${usd(cost)}`)
95 }
96 }
97
98 return lines.join('\n')
99}
100
101export const register: Register = (on, options) => {
102 const prices = parsePrices(options.priceTable ?? DEFAULT_PRICES, options.cacheWriteMultiplier, options.cacheReadMultiplier)
103
104 on('session.start', async ($, e, next) => {
105 await $.command.register({
106 name: 'subagent-band',
107 description: 'Show or hide the band of running subagents (type, model, effort, cost)',
108 })
109 await $.command.register({
110 name: 'subagent-cost',
111 description: "This session's estimated subagent cost by agent type and issue number, and the main session's own",
112 })
113 await $.command.register({ name: 'fleet', description: 'Open a pane with every subagent of this session, running and finished' })
114 await $.command.register({ name: 'steer', description: 'Send a running subagent a message: /steer <id from /fleet> <text>' })
115 await $.tool.register({
116 name: VITALS_TOOL,
117 description:
118 "This session's subagents now: id, type, model, effort, minutes, steps, tool calls, last tool, context, " +
119 'estimated cost, and how finished ones ended. Cheap: use it instead of reading a subagent\'s output file ' +
120 'to check progress. Never call it in a polling loop.',
121 inputSchema: {
122 type: 'object',
123 properties: { includeFinished: { type: 'boolean', description: 'Also list finished subagents (default false).' } },
124 },
125 })
126
127 return next(e)
128 })
129
130 on('command.run', { command: 'fleet' }, async $ => {
131 await $.ui.open({ id: FLEET, title: 'Subagent fleet' })
132
133 return { text: 'Subagent fleet pane opened.' }
134 })
135
136 on('command.run', { command: 'steer' }, async ($, e) => {
137 const [prefix = '', ...words] = e.args.trim().split(/\s+/)
138 const text = words.join(' ').trim()
139 if (!prefix || !text) {
140 return { text: 'Usage: /steer <id from /fleet> <message>' }
141 }
142 const matches = Object.entries(await read($, rows)).filter(([id, row]) => !row.isDone && shortId(id).startsWith(prefix))
143 if (matches.length !== 1) {
144 return { text: matches.length === 0 ? `No running subagent with id ${prefix}.` : `${prefix} matches ${matches.length} subagents; give more of the id.` }
145 }
146 const [id, row] = matches[0]
147 await $.session.send({ to: { agentId: id }, text })
148 await update($, rows, all => ({ ...all, [id]: { ...all[id], steered: all[id].steered + 1 } }))
149
150 return { text: `Sent to ${row.type} ${shortId(id)}${row.steered >= 1 ? ` (follow-up ${row.steered + 1})` : ''}.` }
151 })
152
153 on('tool.call', { tool: 'mcp__subagent-band__subagent_vitals' }, async ($, e) => {
154 const input = e as unknown as { includeFinished?: boolean }
155 const lines = fleetLines(await read($, rows), await $.clock.now(), input.includeFinished === true)
156 const text = lines.length > 0 ? lines.join('\n') : 'No subagents are running.'
157
158 return { result: text } as never
159 })
160
161 // A subagent's tool calls: how many, and the latest.
162 on('tool.call', async ($, e, next) => {
163 const id = e.agentId
164 if (id) {
165 await update($, rows, all => (all[id] ? { ...all, [id]: { ...all[id], tools: all[id].tools + 1, lastTool: e.tool } } : all))
166 }
167
168 return next(e)
169 }).catch(($, e, next) => next(e))
170
171 on('command.run', { command: 'subagent-band' }, async $ => {
172 const hidden = await update($, isHidden, h => !h)
173
174 return { text: hidden ? 'Subagent band hidden.' : 'Subagent band shown.' }
175 })
176
177 on('command.run', { command: 'subagent-cost' }, async $ => ({ text: report(await read($, rows), await read($, mainCost)) }))
178
179 on('agent.spawn', async ($, e, next) => {
180 const spawned = await next(e)
181 const id = spawned.agentId
182 if (id) {
183 const startedAt = await $.clock.now()
184 await update($, rows, all => ({
185 ...all,
186 [id]: { ...blank(), type: e.subagentType, description: e.description, model: shortModel(spawned.model), startedAt },
187 }))
188 }
189
190 return spawned
191 }).catch(($, e, next) => next(e)) // an observer: if this hook fails, the spawn goes ahead (replayed, never run twice)
192
193 // Every model request a subagent makes: the model and effort it actually ran at.
194 on('turn.step', async function* ($, e, next) {
195 const response = yield* next(e)
196 const id = e.agentId
197 if (!id && response.usage) {
198 const cost = stepCost(response.usage, prices)
199 await update($, mainCost, total => total + cost)
200 }
201 if (id) {
202 const usage = response.usage
203 const advisor = (response.serverToolUses ?? []).filter(use => use.name === 'advisor').length
204 await update($, rows, all => {
205 const row = all[id] ?? blank()
206
207 return {
208 ...all,
209 [id]: {
210 ...row,
211 model: shortModel(usage?.model ?? e.model),
212 effort: e.effort === undefined ? 'none' : String(e.effort),
213 steps: row.steps + 1,
214 context: usage
215 ? usage.input_tokens + usage.cache_read_input_tokens + usage.cache_creation_input_tokens
216 : row.context,
217 advisor: row.advisor + advisor,
218 cost: row.cost + (usage ? stepCost(usage, prices) : 0),
219 },
220 }
221 })
222 }
223
224 return response
225 })
226
227 on('turn.complete', async ($, e, next) => {
228 const id = e.agentId
229 if (id) {
230 const endedAt = await $.clock.now()
231 const outcome = e.reason
232 await update($, rows, all => (all[id] ? { ...all, [id]: { ...all[id], isDone: true, endedAt, outcome } } : all))
233 }
234
235 return next(e)
236 })
237
238 on('ui.render', { component: 'Pane', requestId: FLEET }, async ($, e) => {
239 const { Box, Text } = $.ui.resolve(e)
240 const all = await read($, rows)
241 const lines = fleetLines(all, await $.clock.now(), true)
242 const { rateLimits } = await $.session.usage()
243 const usage = rateLimits.map(w => `${w.kind === 'five_hour' ? '5h' : w.kind === 'seven_day' ? '7d' : w.kind} ${Math.round(w.percentUsed)}%`).join(' · ')
244 const room = Math.max(1, (e.viewport?.rows ?? 24) - 4)
245
246 return (
247 <Box flexDirection="column">
248 <Text key="head" bold>
249 {`${Object.values(all).filter(row => !row.isDone).length} running · subagents ${usd(Object.values(all).reduce((sum, row) => sum + row.cost, 0))} · main session ${usd(await read($, mainCost))} (est.)${usage ? ` · usage ${usage}` : ''}`}
250 </Text>
251 {lines.length === 0 && <Text key="none" dimColor>No subagents yet.</Text>}
252 {lines.slice(0, room).map((line, i) => (
253 <Text key={`l${i}`} dimColor={line.startsWith('done')}>{line}</Text>
254 ))}
255 <Text key="help" dimColor>{'/steer <id> <message> sends a running subagent a message.'}</Text>
256 </Box>
257 )
258 })
259
260 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
261 if (e.props.hasSurvey || (await read($, isHidden))) {
262 return next(e)
263 }
264
265 const all = await read($, rows)
266 const live = Object.entries(all).filter(([, row]) => !row.isDone)
267 if (live.length === 0) {
268 return next(e)
269 }
270
271 const { Box, Text } = $.ui.resolve(e)
272
273 return (
274 <Box flexDirection="column">
275 {live.map(([id, row]) => (
276 <Text key={id} dimColor>
277 {pad(row.type, 14)} {pad(row.model, 12)} {pad(row.effort, 6)} step {row.steps} · ctx {kilo(row.context)}
278 {row.advisor ? ` · advisor ${row.advisor}` : ''} · {usd(row.cost)} · {row.description}
279 </Text>
280 ))}
281 <Text key="total" dimColor>
282 {`subagents this session ${usd(Object.values(all).reduce((sum, row) => sum + row.cost, 0))} · main session ${usd(await read($, mainCost))} (est.)`}
283 </Text>
284 </Box>
285 )
286 })
287}
288types/index.d.ts 28 lines1export type Row = {
2 type: string
3 description: string
4 model: string
5 effort: string
6 steps: number
7 context: number
8 advisor: number
9 /** Estimated list-price cost so far, in USD. */
10 cost: number
11 isDone: boolean
12 /** Clock times in ms; endedAt is 0 while it runs. */
13 startedAt: number
14 endedAt: number
15 tools: number
16 lastTool: string
17 /** How its run ended (answer, aborted, error, refusal); '' while it runs. */
18 outcome: string
19 /** How many /steer messages the person sent it. */
20 steered: number
21}
22
23declare module 'claude-code' {
24 interface PluginState {
25 'subagent-band': { rows: Record<string, Row>; isHidden: boolean; mainCost: number }
26 }
27}
28