Skip to content

chore(#645): reconcile .claude/hooks/ with templates/hooks/ - #649

Merged
admarble merged 1 commit into
mainfrom
feature/645-hook-reconcile
May 14, 2026
Merged

admarble merged 1 commit into
mainfrom
feature/645-hook-reconcile

Conversation

@admarble

Copy link
Copy Markdown
Contributor

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.sh only). This PR closes the underlying issue across the entire .claude/hooks/ directory.

What was diverged

File Template had Installed had
post-tool.sh CLAUDE_PLUGIN_DATA log dir, multi-PM test/build detection, cross-shell marker discovery TEST COVERAGE ANALYSIS block, POST-MERGE WORKTREE CLEANUP block
pre-tool.sh CLAUDE_PLUGIN_DATA, $HOOK_LOG variable, merge-commit hint, cross-shell marker discovery (nothing unique)
relay-check.sh (template-only) — (#646 installed it)

What this PR does

  • Port to template (templates/hooks/post-tool.sh): the two local-only blocks from .claude/hooks/post-tool.sh so the template is a strict superset.
  • Sync .claude/hooks/: replace both post-tool.sh and pre-tool.sh with byte-identical copies of the now-superset templates.
  • Widen drift guard (src/lib/relay/__tests__/hook-sync.test.ts): assert byte-equality for every file in templates/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.
  • Add 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 — clean
  • npm run sync:hooks — reports "hooks already in sync" after the commit
  • npx vitest run src/lib/relay — 6/6 passing
  • Adversarial: appending # drift to .claude/hooks/pre-tool.sh fails the byte-equality test; removing it passes
  • Smoke: invoking bash .claude/hooks/post-tool.sh and pre-tool.sh with sample JSON exits 0
  • Manual verification (post-merge): npx sequant doctor still reports clean

Why this is risky-but-low-risk

This commit touches the file that fires on every Claude Code tool call. Two protections:

  1. The merged post-tool.sh is a STRICT SUPERSET of both prior versions — no feature lost, only gained.
  2. The drift test enforces byte-equality going forward, so any future template edit must explicitly sync via npm run sync:hooks or CI fails.

Refs #645

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.
@admarble
admarble merged commit 0945dcb into main May 14, 2026
5 checks passed
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