Skip to content

feat(hooks): remind Claude to update the behaviour docs before a turn ends - #114

Merged
robrich82 merged 11 commits into
mainfrom
feat/hook-behaviour-docs-reminder
Dec 4, 2026
Merged

robrich82 merged 11 commits into
mainfrom
feat/hook-behaviour-docs-reminder

Conversation

@robrich82

Copy link
Copy Markdown
Owner

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 .py file, but not the docs CLAUDE.md says describe it: the root README.md, or the plugin's MANIFEST.toml. Each repo root (a folder holding tools/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:

  • the system/stop_hook_summary entry Claude Code writes after each Stop's hooks run;
  • a prompt: a typed one, a task-notification (these only arrive between turns; a mid-turn one is a queued_command attachment), or another agent's message (isMeta with origin.kind peer).

Other isMeta entries (system reminders, usage-limit auto-continuation, /loop wakeups), 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:

  • Edits whose tool result was an error (failed, denied) are dropped.
  • A compaction summary no longer resets the turn.
  • Task notifications and peer messages start a turn.
  • Reset at the Stop summary, so a notification turn doesn't re-block edits already judged.

Tests: python tools/run_tests.py --coverage (852 passed, 100%), mise run lint, mise run typecheck.

… 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.
@robrich82
robrich82 merged commit a682a1e into main Dec 4, 2026
5 checks passed
@robrich82
robrich82 deleted the feat/hook-behaviour-docs-reminder branch December 4, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant