Repository navigation
chore(#645): reconcile .claude/hooks/ with templates/hooks/ - #649
Merged
Merged
Conversation
Closes the broader hook-drift recurrence risk noted in #646. Before this commit, `.claude/hooks/post-tool.sh` carried two local-only features (test coverage analysis, post-merge worktree cleanup) that were not in `templates/hooks/post-tool.sh`, and `templates/hooks/` carried four improvements (CLAUDE_PLUGIN_DATA log dir, multi-PM test detection, cross-shell marker discovery, $HOOK_LOG variable) that were not in `.claude/hooks/`. PR #646 added a partial drift guard for relay-check.sh only; this commit closes the gap for the whole directory. Changes - templates/hooks/post-tool.sh: port the two local-only blocks (TEST COVERAGE ANALYSIS, POST-MERGE WORKTREE CLEANUP) into the template so it is a strict superset of every prior `.claude/hooks/` feature. - .claude/hooks/post-tool.sh, .claude/hooks/pre-tool.sh: replace with byte-identical copies of the now-superset templates. - src/lib/relay/__tests__/hook-sync.test.ts: widen drift guard from relay-check.sh-only to "every file in templates/hooks/ must be byte-identical in .claude/hooks/." Files local to .claude/hooks/ (e.g. capture-tokens.sh) are still permitted. - scripts/sync-hooks.sh + npm run sync:hooks: regenerate .claude/hooks/ from templates after editing a template hook. Adversarial verification: appending "# drift" to any hook file causes the test to fail; removing the line passes again. This removes the recurrence surface that originally caused #645.
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.
Summary
Closes the broader hook-drift recurrence risk that originally caused #645. PR #646 fixed the visible symptom (added the missing relay-sourcing block + a partial drift guard for
relay-check.shonly). This PR closes the underlying issue across the entire.claude/hooks/directory.What was diverged
post-tool.shCLAUDE_PLUGIN_DATAlog dir, multi-PM test/build detection, cross-shell marker discoverypre-tool.shCLAUDE_PLUGIN_DATA,$HOOK_LOGvariable, merge-commit hint, cross-shell marker discoveryrelay-check.sh#646installed it)What this PR does
templates/hooks/post-tool.sh): the two local-only blocks from.claude/hooks/post-tool.shso the template is a strict superset..claude/hooks/: replace bothpost-tool.shandpre-tool.shwith byte-identical copies of the now-superset templates.src/lib/relay/__tests__/hook-sync.test.ts): assert byte-equality for every file intemplates/hooks/against its.claude/hooks/counterpart, instead of relay-check.sh only. Local-only files in.claude/hooks/(e.g.capture-tokens.sh) are still permitted.npm run sync:hooks(scripts/sync-hooks.sh): regenerates.claude/hooks/from templates. Run this after editing any template hook.Test plan
npm run build— cleannpm run sync:hooks— reports "hooks already in sync" after the commitnpx vitest run src/lib/relay— 6/6 passing# driftto.claude/hooks/pre-tool.shfails the byte-equality test; removing it passesbash .claude/hooks/post-tool.shandpre-tool.shwith sample JSON exits 0npx sequant doctorstill reports cleanWhy this is risky-but-low-risk
This commit touches the file that fires on every Claude Code tool call. Two protections:
post-tool.shis a STRICT SUPERSET of both prior versions — no feature lost, only gained.npm run sync:hooksor CI fails.Refs #645