Skip to content

Fix PreToolUse hook matcher so pre-commit validation actually fires - #484

Draft
michael-webster wants to merge 1 commit into
mainfrom
fix-pretooluse-hook-matcher
Draft

Fix PreToolUse hook matcher so pre-commit validation actually fires#484
michael-webster wants to merge 1 commit into
mainfrom
fix-pretooluse-hook-matcher

Conversation

@michael-webster

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: "Bash(git commit*)" as the matcher on a PreToolUse hook group was silently broken. Claude Code evaluates matcher against the tool name using exact string comparison or JS regex — not command content. That string is treated as a regex requiring characters after "Bash", so it never matched the tool name "Bash" and the pre-commit hook never fired.
  • Fix: set matcher: "Bash" on the hook group (exact tool-name match) and move the git-commit filter to if: "Bash(git commit*)" on each individual hook entry, which is where command-content filtering belongs per the hook spec.
  • Migration: mergeHooks now recognises the legacy "Bash(git commit*)" group matcher in existing settings.json files and replaces it in-place, so re-running chunk init upgrades existing projects without leaving a duplicate group.

Test plan

  • go test ./internal/settings/ -race — all existing + new tests pass
  • go test ./... -race — full suite green
  • go tool golangci-lint run ./internal/settings/ — 0 issues
  • New TestBuildHookMatcherIsToolName asserts generated matcher is "Bash" and entries carry if: "Bash(git commit*)"
  • New TestMergeHooksMigratesLegacyMatcher asserts existing files with old matcher are upgraded to new format with no duplicate groups

🤖 Generated with Claude Code

Claude Code evaluates the `matcher` field against the tool name using exact
string comparison or JS regex — not command content. The old value
`"Bash(git commit*)"` was treated as a regex that requires characters after
"Bash", so it never matched the tool name `"Bash"` and the pre-commit hook
silently never ran.

Fix: set `matcher: "Bash"` on the hook group (exact tool-name match) and
move the git-commit filter to an `if: "Bash(git commit*)"` field on each
individual hook entry, which is the correct place for command-content
filtering per the hook spec.

Migration: `mergeHooks` now recognises the legacy `"Bash(git commit*)"` group
matcher in existing settings files and replaces it with the new format,
so re-running `chunk init` on an existing project upgrades in place without
leaving a duplicate group behind.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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