Repository navigation
feat(hooks): remind Claude to update the behaviour docs before a turn ends - #114
Merged
Merged
Conversation
… ends CLAUDE.md asks for README.md's tables and MANIFEST.toml's long_description to change with the behaviour they describe, but only memory enforced it. A Stop hook reads the turn's Edit, Write and MultiEdit calls from the transcript and, for each worktree they touched, blocks the stop once when a tagger script or a plugin file changed but neither doc did. stop_hook_active lets the next stop through, so Claude can say the behaviour didn't change.
…tifications, and skip failed edits A compaction summary or a background task's notification is a user entry Claude Code adds mid-task; only a typed prompt (origin kind human, or no origin on older transcripts) starts a turn now. An Edit/Write whose tool_result is an error changed nothing, so it no longer counts. Also: a non-dict message is skipped rather than crashing, the NUL-path comment names the Pythons that raise, and the docstring says subagent edits aren't seen.
Each background task's notification is answered in a turn of its own, which ends in a Stop with stop_hook_active false, so carrying the earlier turn's edits past it re-raised a reminder Claude had already answered, once per notification. Mid-turn notifications are queued attachments, never user entries. Only compaction summaries stay excluded. Also pins an error result that matches no edit.
A subagent's hand-back is a user entry marked isMeta with origin kind peer, and Claude answers it in a turn of its own, so it re-raised the earlier turn's reminder just as task notifications did. The message resuming a turn a usage limit cut off (auto-continuation) still carries the turn, and that is pinned. Docstrings now say what starts a turn; a test assertion that couldn't fail is gone.
Claude Code writes a stop_hook_summary entry after each Stop's hooks run, so resetting there too means a /loop wakeup (an isMeta prompt) or an auto-continuation after a graceful stop no longer re-raises edits an earlier Stop judged. Prompt resets stay as the fallback. A turn that ends with no Stop (interrupt, API error) still loses its edits; the docstring says so. Tests: the odd-entries case no longer resets its own garbage, and invalid UTF-8 and a non-string tool_use_id are pinned.
…correct its docstring The edit now sits right after the prompt-like entry, so the garbage after it must leave it in place. The docstring says a resumed turn carries a cut-off turn's edits on, and is rewrapped.
… edits, not only a prompt
…ocs-reminder # Conflicts: # CLAUDE.md
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.
A Stop hook that blocks the end of a turn once when the turn's Edit/Write/MultiEdit calls changed a tagger script (
tagger-scripts/*.ptsp) or a plugin.pyfile, but not the docs CLAUDE.md says describe it: the rootREADME.md, or the plugin'sMANIFEST.toml. Each repo root (a folder holdingtools/run_tests.py) is judged on its own, so worktrees don't mix. When Claude continues because of the block (stop_hook_active), the next stop goes through, so "the behaviour didn't change" is a valid answer.What counts as the turn. The hook reads the transcript and resets its edit set at:
system/stop_hook_summaryentry Claude Code writes after each Stop's hooks run;task-notification(these only arrive between turns; a mid-turn one is aqueued_commandattachment), or another agent's message (isMetawithorigin.kindpeer).Other
isMetaentries (system reminders, usage-limit auto-continuation,/loopwakeups), compaction summaries and tool results don't reset it. Prompts stay as a fallback because every summary seen locally came from a turn whose Stop hooks printed something; whether one is written when they're all silent is unverified. Edits from shell commands and subagents aren't seen, and nor are those of a turn that ended with no Stop (interrupt, API error) once a prompt or message starts the next one.Replaying the 2,430 real Stops in my local transcripts through it gives no false re-blocks.
Fixes from review:
Tests:
python tools/run_tests.py --coverage(852 passed, 100%),mise run lint,mise run typecheck.