Repository navigation
feat: add opt-in lean Claude worker launches - #62
Merged
Merged
Conversation
--claude-lean records a per-task posture that sets the five-minute prompt cache and starts Claude without MCP servers or auto memory. Ordinary launches stay unchanged, and a relaunch keeps the recorded choice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Q2081 B (2026-11-13, "q2081 B"): try only idea 2 and idea 4 on the next 3 Claude code checks. No model change. Judge with measured numbers. The change must be reversible.
Idea 2 is a 5-minute prompt cache instead of a 1-hour cache for short Claude sessions. A session that reads, answers, and ends within minutes does not need its saved conversation kept for an hour. The 1-hour cache write costs $8 per million tokens and the 5-minute write costs $5. Use the 5-minute cache for the read-only plan and code-check stages, and for the next three Claude code checks, by setting FORCE_PROMPT_CACHING_5M=1 in those workers' launch environment. Do not apply it to the main chat, drivers, try copies, or the supervision session, which wait between calls and need the long cache. The model, the effort, and the prompt do not change. The risk is cost only: if a session pauses more than 5 minutes between calls, it writes the conversation again. Judge from the transcripts: the 5-minute and 1-hour token split, cache-create tokens per session, and dollars per call. The baseline is about $0.067 per call and about 121,000 cache-create tokens per code check; go back if the average passes about 190,000.
Idea 4 is a smaller start for Claude plan and check workers. Those workers should launch with only what the stage uses: no chat connectors (a document connector and artifact publishing tools a code check never uses) and no other MCP servers, and no main-chat auto-memory index (the main chat's MEMORY.md, about 23,287 bytes, written for the main chat). Keep hooks, project instructions, and the skills the brief needs. Leave stages that need design tools or the browser alone. Judge by the first transcript row. The measured baseline was 67,465 tokens at the first call, 42,229 written and 25,234 read. Keep the smaller start if the check finishes normally. Removing the switch returns the old start.
What Changed
--claude-leanto launch Claude workers with five-minute prompt caching, MCP tools disabled, and auto memory disabled while retaining hooks, project instructions, and skills.Risk Assessment
Testing
Targeted regression, adversarial plugin checks, five CLI refusals, and four real Claude worker launches passed. Saved transcripts, rendered terminal captures, and native cost measurements; cleaned up all labs. Small-fixture measurements demonstrate behavior, not production savings.
Evidence: Live terminal captures and review reports
Source: Live terminal captures and review reports
Evidence: Cache, token, cost, and runtime measurements
Source: Cache, token, cost, and runtime measurements
Evidence: Plugin MCP runtime results
Source: Plugin MCP runtime results
Evidence: Public CLI refusal evidence
Source: Public CLI refusal evidence
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:3282- The new lean refusals only run inside fm-spawn, and on a relaunch fm-spawn is called after fm-control has already stopped the running agent. This breaks a rule fm-control states at bin/fm-control.sh:1034-1039: a refusal must happen before the agent is stopped. Concrete sequence: a task is spawned with --claude-lean, so its record has claude_lean=1. The operator then runsbin/fm-control.sh <id> relaunch --harness codex --note ..., the documented way to move a task to another harness, for example after a Claude account hits a limit. resolve_relaunch_profile passes, and do_relaunch calls do_exit, which stops the Claude agent. Only then doesfm-spawn.sh --relaunch --harness codexrefuse with 'applies only to the claude harness'. relaunch_rollback in thestoppingphase reports 'no agent is running', so the task is left with no worker. The same happens when the record holds a bad value (claude_lean=maybe, fm-spawn.sh:3270) and when a secondmate's config/secondmate-harness now resolves to a non-claude harness (CONFIG_HARNESS path). The test test_relaunch_refuses_a_bad_record_and_a_harness_switch (tests/fm-spawn-claude-lean.test.sh) passes even though its stub pane has already received /exit, so the test hides this. Fix at the earliest shared boundary: in resolve_relaunch_profile in bin/fm-control.sh, read claude_lean from the record and refuse a bad value, or a TARGET_HARNESS other than claude, before do_exit, next to the existing fm_control_harness_supports_kind check. Alternatively, removing the sticky record (see the separate finding) removes this failure entirely.bin/fm-spawn.sh:6- The intent says: "Do not apply it to the main chat, drivers, try copies, or the supervision session, which wait between calls and need the long cache." It limits both ideas to "Claude plan and check workers". The change adds[--claude-lean]to the--secondmateusage line and the header says lean applies to a "ship, scout, secondmate, or relaunch" launch (fm-spawn.sh:499-501). It also adds a test that a lean secondmate succeeds (test_lean_secondmate). A secondmate is a persistent supervising Firstmate instance that waits between calls, which is exactly the long-lived session the intent excludes. Nothing the intent requires needs secondmate support. Suggested remedy: refuse --claude-lean when KIND=secondmate and remove test_lean_secondmate.bin/fm-spawn.sh:7332- The intent asks only for an opt-in per-launch switch and says "Removing the switch returns the old start." The change also writes a claude_lean=1 line to the task record (fm-spawn.sh:7332) and reads it back on relaunch (fm-spawn.sh:3266-3277). Omitting the flag then 'does not turn the posture off', and there is no flag or fm-control option to turn it off. So for a relaunched task, removing the switch does not return the old start: the only way back is hand-editing state/<id>.meta. Even after that edit, the reused pane shell still has FORCE_PROMPT_CACHING_5M=1 from the earlier pane export (fm-spawn.sh:7902-7904), and an adopted dead endpoint keeps that shell. With the allowlist off, the 'ordinary' replacement would still use the five-minute cache. fm-control relaunch also cannot pass --claude-lean, so turning lean on during a relaunch only works through a directfm-spawn --relaunchcall. Nothing the intent requires needs this persistent state for a trial on three short checks. Suggested remedy: drop the claude_lean record line, its relaunch read-back, the relaunch flag handling, and the related relaunch tests, so a relaunch is lean only when the flag is passed. The pre-stop refusal problem in the first finding lives inside this component, so removing it also fixes that.bin/fm-spawn.sh:7903- The lean launch sets FORCE_PROMPT_CACHING_5M=1 in three places: an export in the launch command (7814-7816), the env -i allowlist pin (7979-7981), and an extraexport FORCE_PROMPT_CACHING_5M=1sent to the pane shell (7902-7904). The test's 'launch command alone' run shows the launch-command export already reaches the claude process, and the allowlist pin covers env -i. The pane-shell export is not needed for anything the intent requires. Its only lasting effect is that later commands in that pane shell keep the five-minute cache flag after the worker exits, including a later relaunch into the same pane. Suggested remedy: remove the pane export so the setting lives only in the worker's launch environment, as the intent describes.🔧 Fix applied.
5 issues (1 error, 3 warnings, 1 info) still open:
bin/fm-spawn.sh:3282- The new lean refusals only run inside fm-spawn, and on a relaunch fm-spawn is called after fm-control has already stopped the running agent. This breaks a rule fm-control states at bin/fm-control.sh:1034-1039: a refusal must happen before the agent is stopped. Concrete sequence: a task is spawned with --claude-lean, so its record has claude_lean=1. The operator then runsbin/fm-control.sh <id> relaunch --harness codex --note ..., the documented way to move a task to another harness, for example after a Claude account hits a limit. resolve_relaunch_profile passes, and do_relaunch calls do_exit, which stops the Claude agent. Only then doesfm-spawn.sh --relaunch --harness codexrefuse with 'applies only to the claude harness'. relaunch_rollback in thestoppingphase reports 'no agent is running', so the task is left with no worker. The same happens when the record holds a bad value (claude_lean=maybe, fm-spawn.sh:3270) and when a secondmate's config/secondmate-harness now resolves to a non-claude harness (CONFIG_HARNESS path). The test test_relaunch_refuses_a_bad_record_and_a_harness_switch (tests/fm-spawn-claude-lean.test.sh) passes even though its stub pane has already received /exit, so the test hides this. Fix at the earliest shared boundary: in resolve_relaunch_profile in bin/fm-control.sh, read claude_lean from the record and refuse a bad value, or a TARGET_HARNESS other than claude, before do_exit, next to the existing fm_control_harness_supports_kind check. Alternatively, removing the sticky record (see the separate finding) removes this failure entirely.bin/fm-spawn.sh:6- The intent says: "Do not apply it to the main chat, drivers, try copies, or the supervision session, which wait between calls and need the long cache." It limits both ideas to "Claude plan and check workers". The change adds[--claude-lean]to the--secondmateusage line and the header says lean applies to a "ship, scout, secondmate, or relaunch" launch (fm-spawn.sh:499-501). It also adds a test that a lean secondmate succeeds (test_lean_secondmate). A secondmate is a persistent supervising Firstmate instance that waits between calls, which is exactly the long-lived session the intent excludes. Nothing the intent requires needs secondmate support. Suggested remedy: refuse --claude-lean when KIND=secondmate and remove test_lean_secondmate.bin/fm-spawn.sh:7332- The intent asks only for an opt-in per-launch switch and says "Removing the switch returns the old start." The change also writes a claude_lean=1 line to the task record (fm-spawn.sh:7332) and reads it back on relaunch (fm-spawn.sh:3266-3277). Omitting the flag then 'does not turn the posture off', and there is no flag or fm-control option to turn it off. So for a relaunched task, removing the switch does not return the old start: the only way back is hand-editing state/<id>.meta. Even after that edit, the reused pane shell still has FORCE_PROMPT_CACHING_5M=1 from the earlier pane export (fm-spawn.sh:7902-7904), and an adopted dead endpoint keeps that shell. With the allowlist off, the 'ordinary' replacement would still use the five-minute cache. fm-control relaunch also cannot pass --claude-lean, so turning lean on during a relaunch only works through a directfm-spawn --relaunchcall. Nothing the intent requires needs this persistent state for a trial on three short checks. Suggested remedy: drop the claude_lean record line, its relaunch read-back, the relaunch flag handling, and the related relaunch tests, so a relaunch is lean only when the flag is passed. The pre-stop refusal problem in the first finding lives inside this component, so removing it also fixes that.bin/fm-spawn.sh:7903- The lean launch sets FORCE_PROMPT_CACHING_5M=1 in three places: an export in the launch command (7814-7816), the env -i allowlist pin (7979-7981), and an extraexport FORCE_PROMPT_CACHING_5M=1sent to the pane shell (7902-7904). The test's 'launch command alone' run shows the launch-command export already reaches the claude process, and the allowlist pin covers env -i. The pane-shell export is not needed for anything the intent requires. Its only lasting effect is that later commands in that pane shell keep the five-minute cache flag after the worker exits, including a later relaunch into the same pane. Suggested remedy: remove the pane export so the setting lives only in the worker's launch environment, as the intent describes.bin/fm-spawn.sh:75- This is left over from round 1's fix. The round-1 instruction was to "Drop the claude_lean meta record, its relaunch read-back and relaunch flag handling and their tests". The fixer removed the record, the read-back, the pane export and the relaunch tests. It did not remove the flag on relaunch:fm-spawn.sh <id> --relaunch ... [--claude-lean]is still advertised in the usage line (bin/fm-spawn.sh:75) and still accepted, and a directfm-spawn --relaunch --claude-leanproduces a lean replacement. docs/configuration.md:1472 also says omitting the flag restores the ordinary start "including on relaunch", which treats lean-on-relaunch as supported. No test covers this path any more. fm-control's relaunch (bin/fm-control.sh:1267) never forwards the flag, so only a direct fm-spawn relaunch can reach it. The intent ("the next 3 Claude code checks") does not need it. The round-1 instruction's closing clause ("so a launch is lean only when the flag is passed on that launch") could be read as allowing a per-launch flag on relaunch, so ask which reading was meant. If relaunch support is not wanted, the remedy is to refuse --claude-lean when RELAUNCH=1, drop it from the usage line at bin/fm-spawn.sh:75, and drop "including on relaunch" from docs/configuration.md:1472. If it is wanted, keep it as is.🔧 **Test** - 2 issues found → auto-fixed ✅
bin/fm-spawn.sh:7512- The lean launch does not exclude all MCP tools. In two independent disposable labs using real Claude Code 2.1.323, the third lean worker registered mcp__easel__chart from cc-plugin-easel despite receiving --strict-mcp-config. The runtime transcript records both deferred_tools_delta and mcp_instructions_delta for easel, so this is not merely the model claiming a tool exists. Project-configured MCP was excluded successfully, but plugin registration bypassed this boundary. Extend the per-launch exclusion to plugin-provided MCP tools while preserving required hooks and skills, and verify it against the real Claude consumer.bash tests/fm-spawn-claude-lean.test.shclaude --versionandclaude auth statuspython3 ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/drive-lean.pypython3 ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/drive-refusals.pypython3 ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/drive-measured.pypython3 ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/summarize.pyVerified transcript totals against Claude's runtime cost ledger and normal Stop-hook records; removed disposable labs and checkedgit status --short.🔧 Fix applied.
✅ Re-checked - no issues remain.
bash ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/round2/run-focused.sh— targeted regression with FM_CLAUDE_LEAN_LIVE=1; repeated to preserve runtime transcriptspython3 ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/round2/drive-measured.py— three lean reviews and one ordinary control through real fm-spawn, Claude, and isolated 160×50 tmux panespython3 ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/round2/drive-refusals.py— five public CLI refusal casespython3 ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/round2/summarize.py— generated measurements and rendered terminal evidencepython3 ~/.no-mistakes/evidence/01M7A6XKEDE3MQDMAHTFHQPD5J/round2/verify-evidence.py— verified saved runtime behavior and cost recordsRemoved disposable labs and test caches;git status --shortwas clean.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.