Repository navigation
fix(hook): review Claude's plan file, not its stale inline snapshot - #1667
Merged
backnotprop merged 3 commits intoOct 2, 2026
Merged
Conversation
Claude Code fills ExitPlanMode's plan from the plan file when it records the assistant message. When the model edits the plan file and calls ExitPlanMode in the same message, that snapshot predates the edit, so the review showed the plan the user had just rejected. Read planFilePath at hook time instead, and carry the reviewed plan in updatedInput on approval. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: workflow <w0rkflow@pm.me>
A batched plan edit and ExitPlanMode must review the edited file, and every missing or unreadable source must fall back to the inline plan. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: workflow <w0rkflow@pm.me>
Only read planFilePath when it is an absolute .md path naming a regular file within MAX_ANNOTATABLE_FILE_BYTES; otherwise fall back to the inline plan. Reading a FIFO there blocked the hook forever, and an unbounded file was read whole into memory. Tests cover the gate and that a file-sourced plan passes readPlanFile's trust check for /api/doc.
Owner
|
Thanks @workflow, this is a real catch with a great write-up. Merged. I added one commit on top that only reads the plan file when it is an absolute |
1 task
workflow
added a commit
to workflow/dotfiles
that referenced
this pull request
Oct 24, 2026
numtide/llm-agents.nix builds plannotator from source and updates daily; the plugin, skills, commands and opencode plugin pin follow its src and version. 0.28 reviews the plan file itself (backnotprop/plannotator#1667), so the fresh-plan hook wrapper goes. Trust cache.numtide.com for it. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: workflow <w0rkflow@pm.me>
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.
In Claude Code, plan review sometimes opened the previous version of a plan, typically the one just denied. This happens when the model edits the plan file and calls
ExitPlanModein the same assistant message, which recent models do often after a deny.Cause
Claude Code fills
ExitPlanMode'stool_input.planfrom the plan file when it records the assistant message, before any of that message's tools run. When the same message also contains theWrite/Editof the plan file, the capturedplanpredates the edit. The hook renderedtool_input.plan, so it showed the stale text, and history and the approval recorded it too.From a real session (Claude Code 2.1.280):
Writeto~/.claude/plans/<slug>.mdwith the revised plan.ExitPlanModerecorded, withplanbyte-identical to the denied version (5508 bytes).Writeresult arrives.Write/Edit+ExitPlanModeI could find in my transcripts had a staleplan.tool_input.planFilePathis sent alongside, and by the time thePermissionRequesthook fires the file holds the edited plan. This is the Claude Code counterpart of the Pi race fixed in #1622.What changed
apps/hook/server/claude-plan.ts(new):resolveClaudePlanreadsplanFilePathwhen it is sent and readable and non-empty. Otherwise it falls back to the inlineplan, which keeps other hosts on thePermissionRequestpath unchanged.apps/hook/server/index.ts:resolveClaudePlan.updatedInputcarries the reviewed plan ({ ...event.tool_input, plan }), so the plan Claude Code proceeds with is the version the user approved, not the stale snapshot.Testing
bun test apps/hook/server/claude-plan.test.ts: 5 pass. With the resolver returning the inlineplan(the behaviour onmain), the stale-snapshot test fails.bun test apps/hook/server: 350 pass, 0 fail.PermissionRequestevent from a session throughbun apps/hook/server/index.tswith the built UI./api/planserved the edited plan file (2538 bytes), not the stale inline snapshot (2352 bytes).tool_input.planfromplanFilePath. I forced the batched case in Claude Code: deny, then edit +ExitPlanModein one message. The transcript still recorded the staleplan, while the review andhistory/…/002.mdshowed the edited file.Notes
Write/Editbefore theExitPlanModepermission hook, which matches the timings above. If Claude Code ever ran them concurrently, the read could still race, and the fix would belong in Claude Code (fillingplanwhen the tool runs, not when the message is recorded).