Files
ai-agent/docs/clarifier.md
gabrielvidalandClaude Opus 5.5 fef899477a refactor(forms): retire the hub's own frm_ form engine (Stage 6)
Approvals, New project and Plans now build on the ask-form live plugin, so
nothing creates frm_ forms any more. Per Gabriel's call ("retire
completely", no read-only viewer):

- backend: delete forms/ (routes, service, store, secrets), schemas/forms,
  the /api/forms* routes and their authz lines, the worker outbox's `form`
  kind, the frm_ scan in tree.py and the pending-forms check in auto-archive
- cli: drop notify wait frm_ / cancel / secret (ask-form secret replaces it)
- frontend: delete FormWidget, FormModal, FormPager, FormFields, formDraft,
  formGroups, the Forms page (/forms now redirects to the ask-form plugin's
  Forms page) and the generated form models; the dock keeps ask-form frames
  only; SandboxedHtml stays
- merge fix-ups: a conflict marker left in cli/notify.py's docstring, the
  BottomBar test's Files sub-links, an unused French string, and the
  FormDock test now warms the lazy AskFormFrame chunk (its cold import
  outlasted waitFor once FormModal stopped importing it statically)
- docs: CLAUDE.md and docs/clarifier.md no longer describe frm_ forms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 22:05:43 +01:00

23 KiB
Raw Permalink Blame History

The clarifier subagent — what a form costs, and asking it from a subagent

Analysis and experiment of 2026-10-21; Gabriel's calls in form frm_b59205b0ac08 (ship it by default, Haiku configurable in Settings, the clarifier waits, every run, plan questions unchanged). Code: backend/runs/clarifier.py, backend/runs/extras.py, conversations/tree.py (forms on a subagent ref), SubagentWidget.tsx, Settings → Extras → Clarifier (per person since 2026-11-23, the operator's value as the default).

The question

A form (ask-form / notify form) is usually asked early in a conversation: the agent explores, then asks Gabriel what it can't decide alone. Everything the form put in the main context — the field spec, its mockups, the tools and skill loaded to send and wait for it — then rides along every later API call as a cache read, and again as a cache write whenever the prefix is rewritten (TTL expiry, model switch). Would a subagent that builds, sends and waits for the form, then reports a digest, be cheaper?

History: every form in the hub (256, Aug 9 → Oct 21 2026)

Script: each form in /data/forms.json → its creating Bash call in the transcript (archive or live), its --fields-file Write if any, then every later call of that chain until a compaction. Token sizes calibrated on calls whose only output was the tool call (≈ 2.35 chars/token for these JSON+HTML specs).

median p90
spec (fields JSON + mockups) 1.3k tokens 3.2k
asked at call # (of the conversation's) 18 (of 109) 80
later calls carrying it 74 187
answer latency 3.9 min 17 min

What stays in context is more than the spec:

  • the Monitor tool schema, loaded through ToolSearch to wait — 3.1k tokens, in 96 % of forms;
  • the ask-form skill text, when the Skill tool loaded it — 2.4k tokens, in 23 % of forms;
  • the wait's events and the answers.

Carried overhead per form: 4.5k tokens median, 6.8k p90. Priced per later call at the model that made it (cache read, or cache write when the call re-wrote the prefix — 357 such rewrites over the 256 forms):

list price plan meter*
all 256 forms $58 $107
per form $0.23 $0.42

* the subscription limits meter a model at its predecessor's price (Opus 5.5 as Opus 5: cache read $0.50 vs $0.20) — see docs/usage-calibration.md.

Experiment: the same form three ways

One dummy task (a "Watering schedule" screen for a fictional plant app): ten questions covering every field type plus two HTML mockups, then 12 follow-up calls standing in for the rest of the conversation. Main thread Opus 5.5, launched like a sidecar run (cwd ~/homelab, --agents, AskUserQuestion disabled); the forms went through a proxy that turned the push off and answered them after 25 s.

A — inline B — clarifier, Sonnet 5.5 C — clarifier, Haiku 5.5
main thread, form phase $0.164 $0.015 (the brief) $0.015
subagent — $0.125 $0.010
context left in the main thread +8.5k tokens +1.4k +1.4k
each later call (Opus 5.5) $0.0185 $0.0171 $0.0173
form + 74 later calls + 1.4 rewrites $0.35 $0.14 $0.03
same, plan meter $0.64 $0.14 $0.12

A's 8.5k: the skill (2.4k), the spec (1.9k out + result), ToolSearch for Monitor (3.1k), the Monitor call and its event. The clarifier's subagent context is ~31k tokens (system prompt + tools + its own prompt) written once at the 5-minute TTL — subagents don't get the main thread's 1-hour TTL, which is why its wait polls every 270 s: a poll inside the TTL is a cache read (≈ $0.0001 on Haiku), one past it re-writes the whole context.

All three forms were usable. Haiku's mockups were the richest (three plants, a "water today" state, a full week); Sonnet's calendar had a misplaced chip; Haiku marked every question required and turned the dark-mode checkbox into a yes/no radio. One sample each — not a quality ranking.

Projected on the history

Counterfactual per form: the main thread writes a brief instead of the spec (≈ 36 % of the spec's tokens, from each form's labels/options/help text) and carries the brief + a digest instead of the spec + skill + Monitor + events; the subagent's cost is modelled on the measured runs (31k cold write, 1.3× the spec as output, ~2 polls).

clarifier model saved, list saved, plan meter
Sonnet 5.5 $24 (41 %) $73 (68 %)
Haiku 5.5 $56 (97 %) $90 (84 %)

At October's pace (~8 forms a day) Haiku saves ≈ $1.7/day list, $2.7/day plan. The other wins aren't in dollars: ~4–7k fewer tokens in the main context for the rest of the conversation, and the main thread doesn't spend a minute generating JSON/HTML — with the agent in the background it keeps working.

The projection didn't hold — see the next section.

Measured: eleven days on (Oct 21 → Nov 1)

Script: scripts/clarifier-gains.py (re-run it any time; --json dumps one row per form). It walks the transcript archive for every form a main thread asked, inline or through the clarifier, and measures it from the usage blocks rather than from character counts:

  • footprint — the tokens the form left in the main context. Each call's context growth (next prompt − this prompt) is split among the blocks that caused it, the call's own output at its output_tokens. Thinking counts: the context grows by output_tokens + the tool results on every call, so the thinking blocks stay in context and ride along like the rest.
  • ask — the main-thread calls that did nothing but the form (load the skill, ToolSearch for Monitor, write the spec, create, wait, a wake-up on a form event), each at its marginal price on a warm thread.
  • carry — every later call until a compaction, the footprint priced as a cache read, or a write where that call's cached prefix stopped short of it.
  • subagent — the clarifier's whole transcript.

Every main thread is re-priced as Opus 5.5 (the cohorts' model mix differs). Carry depends on how long the conversation goes on after the form, and the clarifier's conversations ran longer. The comparison therefore puts each cohort's footprint on the same conversation shapes, using the inline forms' carry per footprint token. The script's raw column keeps each cohort's own carry: $0.58 for the clarifier.

per form inline, Aug 9 → Oct 21 clarifier (Sonnet 5.5, as it ran) same tokens on Haiku 5.5
forms 266 137 (136 Sonnet, 1 Haiku) —
footprint, mean 5.0k tokens 5.0k 5.0k
main-thread calls 3.3 1.6 1.6
ask, list $0.225 $0.152 $0.152
carry, list $0.129 $0.128 $0.128
subagent, list — $0.256 $0.014
total, list $0.354 $0.536 (+51 %) $0.294 (−17 %)
total, plan units 0.68 0.79 (+16 %) 0.66 (−3 %)

The plan column is the one that counts on the Max plan, and there Haiku barely helps: the meter counts Haiku 5.5 at Haiku 4.5's price, so it halves the subagent's cost rather than dividing it by 20.

Why the projection missed:

  • The brief is not small. The projection had it at 36 % of the spec (≈ 0.5k). Measured: 3.3k tokens, 1.3k of them visible (≈ 4.5k chars, never any HTML) and the rest the thinking that wrote it. That is more than the spec + create it replaces (2.2k).
  • The report is not small either. The clarifier's own message is ~350 tokens (answers JSON + digest). In the main thread it arrives inside the launch result and a <task-notification> wrapper: 1.2k.
  • What it removes is real but no bigger: the skill text (2.5k, in 65 % of the inline forms), the Monitor schema (3k, loaded for the wait in 68 %), the wait and its events (0.7k). The footprints come out even, at 5.0k.
  • It ran on Sonnet, not the Haiku the projection priced. Settings → Clarifier has said sonnet since day one. On Sonnet it costs $0.26 a form: the cold 33k-token context write is 29 %, the spec and report output 26 %, and the wait 41 % (mean 6.8 polls of 270 s, each re-reading ~40k).

What held: 1.7 fewer main-thread calls a form (−$0.07). The skill text is gone from main threads (9 of 136 still loaded the stub).

What didn't change: answer rate (82 % vs 84 % submitted) and answer latency (4.3 vs 4.2 min median). The main thread still takes ~28 s per form, because writing the brief takes as long as writing the spec did. Clarifier forms carry mockups more often (60 % vs 24 %). Picture and mockup choices only landed on Oct 27, though, so that can't be credited to the clarifier. Volume rose: 11.8 forms a day vs October's 8.2.

Stakes: every clarifier form of the eleven days came to 112 plan units, about 2 % of one week on the Max 20× plan (≈ 56 units per 1 %). Sonnet's premium over inline was ≈ 14 units, about 0.26 % of a week. The choice between them is about form quality, not cost.

Bug found on the way: the prompt said ask-form wait <id> --timeout 270. The Go tool wants a duration, so it rejected the 270 in every run since Oct 28 (84 times) and the clarifier retried with 270s. Fixed (270s).

Not comparable: the 49 inline forms asked after Oct 21 (goal-keeper's validation forms, pi/opencode runs, terminal sessions) look cheapest: a 1.7k footprint, $0.25. They come from short, lean runs that carry the ask-form syntax in their prompt, so they say nothing about a long interactive thread.

Gabriel's calls (form clarifier-measured-gains-oct-21-nov-1_wbky89, Nov 1): keep the clarifier on, keep it on Sonnet, and cap the brief. He also asked how to stop the parent thread reading the mockups. It already doesn't: none of the 137 briefs held any HTML, and the report carries only answers. What stays in the parent is the brief and the thinking that wrote it. So the fix is to make the clarifier do more and the brief say less:

  • The brief is ~200 words: the decisions, the options, the recommendation, a few lines of context, and the paths/URLs to look at. The main thread doesn't draft the form, the mockups or the context block (_DESCRIPTION).
  • The clarifier does the legwork: it reads the files the brief names, looks at the code or page a mockup should resemble and screenshots a URL when the current state helps. That work happens in its own context, which nobody carries afterwards.
  • The report carries the answers object only, not the whole form record ask-form wait prints (createdAt, description, expiresAt, meta…). That saves ~100 tokens a form, for the rest of the conversation.

Re-run scripts/clarifier-gains.py after a week or two: the brief part of the clarifier's footprint (3.3k now) is the number to watch.

Nov 4: dropping CLAUDE.md (and a medium effort)

The question: on Sonnet, can a form through the clarifier cost less than one asked inline? Re-measured on the 63 forms since the Nov 1 brief cap (main threads priced as Opus 5.5, carry on the inline forms' conversation shapes, as above):

plan units per form inline (Aug 9 → Oct 21) clarifier Oct 21 → Nov 1 since the cap (Nov 1 → 4) + no CLAUDE.md (projected)
footprint, tokens 5 037 4 985 3 138 3 138
ask 0.408 0.256 0.178 0.178
carry 0.273 0.270 0.170 0.170
subagent — 0.257 0.269 0.173
total 0.681 0.783 0.617 (−9 %) 0.522 (−23 %)

The cap did its job on the main thread: the footprint went 5.0k → 3.1k (brief 3.3k → 1.8k, report 1.2k → 1.0k), one main-thread call a form instead of 1.6. That alone put a Sonnet form 9 % below an inline one.

The subagent's cold context was mostly CLAUDE.md. Every spawn wrote ~33k tokens at the 5-minute TTL before doing anything. 25k of them (63k chars) were the instructions attachment Claude Code gives every subagent: the user CLAUDE.md + RTK.md, the project CLAUDE.md (42k chars on the homelab) and the auto-memory index (17k chars). The clarifier needs none of it, because the brief and its own prompt hold everything. The second clarifier of a conversation didn't even share that prefix (5k read, 28k re-written four minutes later). Claude Code's agent definitions take omitClaudeMd: true ("for agents that take everything they need from the delegation prompt"; 2.1.300 and 2.1.317 both have it). A nested test agent went 29.0k → 3.2k cold. The clarifier with its real prompt went 33k → 7.0k. Re-pricing each of the 59 post-cap subagent transcripts without those tokens takes it from 0.269 to 0.173 plan units: −0.065 on the cold write, the rest on every later read of it.

What's left in the subagent is output. It writes 8.6k tokens a form (mean; median 3.7k), about half of them thinking. An agent definition can carry its own effort; without one it thinks at the run's level, often xhigh. On one test brief (5 decisions, 3 mockups) with no CLAUDE.md, high wrote 3.5k output tokens and medium 1.8k. Both produced the same form (8 fields, 4 HTML mockups). Gabriel picked medium as the default and asked for it as a setting.

What wasn't worth it:

  • Foreground instead of background: it would save the launch result (1.1k chars) and the notification wrapper, but 58 of 59 main threads made tool calls right after the launch (pulled, set up worktrees, launched other agents).
  • Dropping the ANSWERS line: ~100–150 tokens a form.
  • Dropping Glob/Grep: ~1k tokens of tool schema, a fraction of a cent a form.
  • The same for work-context: 8k tokens of Orus CLAUDE.md + memory a lookup on Haiku, ≈ 1.5 plan units a month. Gabriel's call: not now.

Shipped (form cheaper-clarifier_06hws4):

  • the clarifier runs with omitClaudeMd: true;
  • its effort is a setting, Settings → Extras → Clarifier → Effort (Inherit / Low / Medium / High, default Medium);
  • the brief rule became "at most 1,200 characters, one line per decision" (briefs averaged 2.3k chars against the ~200-word target).

The sidecar refuses a definition key it doesn't know: a 400, which fails the whole run. So a sidecar now lists the keys it takes in /health (agentKeys), and the hub strips omitClaudeMd/effort for one that doesn't list them (runs/extras.py). A worker that hasn't updated yet gets the clarifier as it was.

Re-measure with scripts/clarifier-gains.py: its --cut cohorts (· from 11-01, · from 11-04) split the clarifier rows at each change.

Measured: one week after the short brief (Nov 9)

Re-ran scripts/clarifier-gains.py on 2026-11-09 (858 transcripts, 685 forms). The script now prints a second table: the brief and report parts of the footprint, answer rate, median answer time, fields, mockups and the --timeout 270 retries. It also prints a · since 11-01 cohort (both changes together). Main threads are priced as Opus 5.5, and carry uses the inline forms' conversation shapes, as above.

per form inline, Aug 9 → Oct 21 clarifier, Oct 21 → Nov 1 short brief (Nov 1 → 4) + no CLAUDE.md, medium (Nov 4 → 9) all since Nov 1
forms 266 137 69 108 177
footprint, tokens 5 037 5 047 3 065 3 017 3 036
· brief (text + its thinking) — 3 296 1 741 1 542 1 619
· report (launch result + notification) — 1 265 982 1 109 1 059
main-thread calls 3.3 1.6 1.1 1.3 1.2
ask + carry, list $0.354 $0.282 $0.173 $0.173 $0.172
subagent, list — $0.259 $0.255 $0.081 $0.149
total, list $0.354 $0.541 $0.428 $0.253 (−29 %) $0.321
total, plan units 0.681 0.792 0.598 0.418 (−39 %) 0.488
answered 88 % 85 % 88 % 91 % 90 %
median answer time 4.2 min 4.3 min 4.1 min 2.4 min 3.0 min
--timeout 270 retries — 87 2 0 2

All on Sonnet 5.5, the setting since day one. Both cohorts since Nov 1 are large enough (69 and 108 forms) to trust. The answer times are noisy, because they depend on when Gabriel looks.

Verdict: improved. The short brief halved the brief, 3.3k → 1.6k tokens, and took the footprint from 5.0k to 3.0k (−40 %). The main thread now spends 1.2 calls a form instead of 1.6. Together with the Nov 4 change, a clarifier form costs 0.418 plan units against 0.681 inline (−39 %) and $0.25 against $0.35 list. It is no longer more expensive than inline. On Nov 4 the projection was 0.52. The real figure is lower because the subagent came in at 0.081, not the projected 0.173. It now reads a 7.3k cold context (median, against 33k before) in 5 calls (against 6).

  • The 270 retry is gone. The two after the cut (Nov 1 22:02 and 22:16) were runs launched before the deploy, which still carried the old agent definition. None since.
  • The report barely moved (1.27k → 1.1k). The answers-only change removed ~100 tokens, as expected. The rest is Claude Code's own text: the background-launch result (≈ 1,050 chars of boilerplate, the agent id and the output file) and the <task-notification> wrapper (≈ 900 chars). The clarifier's actual message (FORM_ID, ANSWERS, DIGEST) is ~650 chars of it.
  • What is left of the brief is mostly thinking. Of the 109 launches since Nov 4, the brief text has a median of 1,393 chars (≈ 0.35k tokens). 96 of them are over the 1,200-char rule, but only slightly. The launching call writes a median 1.6k output tokens, nearly all of it (redacted) thinking: the parent working out its decisions and recommendations. That work is the parent's own and would be done inline too. Five recent briefs (the raspy2 bench, the BFFR moderation and Settings changes, the BFFR widget, the raspy2 connection ceiling) all follow the rule. Each gives one line per decision with ★/rec, plus the paths to read: no pasted context, no drafted mockups.

Stakes. 108 forms in 4.8 days (≈ 22 a day) at 0.418 units ≈ 9 units a day, ≈ 0.17 % of a week a day. Against inline, the clarifier now saves ≈ 5.9 units a day.

Next lever (proposed, not applied). The main thread has little left to cut. The remaining footprint is ~1.1k tokens of the parent's own thinking, plus ~0.8k of CLI wrapper text the hub doesn't control. The one cheap trim is the report's DIGEST lines, which repeat the ANSWERS JSON. Dropping them (or keeping the digest and dropping the JSON) would save ~150 tokens a form (≈ 5 % of the footprint, ≈ 0.02 units). Medium effort on the subagent is already the default. A further step would be Haiku for the clarifier: the script's Haiku column puts it at 0.378 units (−10 % on 0.418). That is a form-quality question, not a cost one.

Design

  • Every claude run — lab, Macs, guests; spawn, resume and fork — gets the definition through claude --agents (runs/extras.py merges it with the work-context agent; the sidecar caps the payload — 16 000 chars then, 60 000 since the lab sync's portable agents joined it (agentsMax in /health) — the two together are ~7.4k). Settings → Extras → Clarifier switches it off, picks its model (Haiku by default; Sonnet, Opus) and its effort (Medium by default; Inherit, Low, High): ClarifierStore, /data/clarifier.json, GET/PUT /api/clarifier (owner only).
  • No CLAUDE.md (since Nov 4): omitClaudeMd: true. It gets neither the instruction files nor the memory index, only its prompt and the brief. runs/extras.py drops the key (and effort) for a sidecar whose /health has no agentKeys.
  • Its prompt carries the field reference, so neither thread needs the ask-form skill text; the homelab ask-form skill is a short "delegate to the clarifier" stub (~600 tokens when loaded, down from ~2.4k) and the notify skill keeps the full reference for direct use (no clarifier: a terminal session, the pi / opencode harnesses).
  • Plan questions are unchanged — the plan skill writes its field spec into the plan file, it isn't asked through the hub from the conversation.
  • It waits itself — foreground ask-form wait <id> --timeout 270s (a Go duration: a bare 270 is rejected), re-run on exit 4, gives up after ~1h45 (inside the sidecar's 2 h background-agent ceiling) and reports the form as pending.
  • A short brief, the legwork in the clarifier (since Nov 1): the main thread passes at most 1,200 characters (since Nov 4; ~200 words before), one line per decision with its options and recommendation, plus the paths/URLs to look at. The clarifier reads and screenshots what it needs itself. See "Measured" above for why.
  • Its report is the answers object verbatim (not the whole form record) plus one digest line per question ((recommended), (Other), (skipped) markers).
  • The form shows in the main thread: the backend scans each subagent transcript for the form's link (the legacy FORM_ID=frm_… no longer) — incrementally, a running agent's file only grows — and lists every form of an agent's subtree, with when it opened, as forms / formRefs on its SubagentRef. The root conversation hoists each into its own row where it opened (hoistAgentForms, via clarifier); the Agent card keeps a chip that jumps there, and a pending one also sits as a slim bar above the composer. The push, ?form= deep link and Waiting for feedback already worked — the form store keys on the session id, which a subagent shares with its parent.

Nov 11: a week on

Re-measured a week after the Nov 4 change (omitClaudeMd + medium effort + 1,200-char brief; ai-agent 5ce89d6) with scripts/clarifier-gains.py (760 forms since Aug 1). Means per form, main thread priced as Opus 5.5; plan units on the legacy meter.

cohort n footprint (tok) ask carry subagent total brief / report chars
inline, before 266 5037 0.408 0.273 — 0.681 —
clarifier from 11-01 69 3065 0.176 0.166 0.255 0.598 1741 / 982
clarifier from 11-04 171 2931 0.185 0.159 0.079 0.423 1543 / 1094

(List $ per form: inline $0.354, from 11-04 $0.248; with the sub on Haiku 0.383 plan units.) The projection was ~0.52; reality is 0.423 (−38 % vs inline), because the subagent fell from 0.255 to 0.079.

  • Cold context held: 131 post-Nov-4 clarifier transcripts, first call 6,990–7,634 tokens (median 7,345), none with the CLAUDE.md instructions block; the sidecar's /health agentKeys lists omitClaudeMd and effort.
  • Brief cap: mean brief 1,543 chars (from 3,296 on 10-21), so it is still a little over 1,200 on average, but it halved. Answered 91 %, median 2.7 min, no 270 retries.
  • Footprint is flat since Nov 9 (≈2.9k), the remaining cost is the main thread's ask + carry; the report's wrapper text and the digest lines are the last lever (Haiku would give 0.383).