Fix PreToolUse hook matcher so pre-commit validation actually fires - #484
Draft
michael-webster wants to merge 1 commit into
Draft
Fix PreToolUse hook matcher so pre-commit validation actually fires#484michael-webster wants to merge 1 commit into
michael-webster wants to merge 1 commit into
Conversation
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>
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
"Bash(git commit*)"as thematcheron aPreToolUsehook group was silently broken. Claude Code evaluatesmatcheragainst 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.matcher: "Bash"on the hook group (exact tool-name match) and move the git-commit filter toif: "Bash(git commit*)"on each individual hook entry, which is where command-content filtering belongs per the hook spec.mergeHooksnow recognises the legacy"Bash(git commit*)"group matcher in existingsettings.jsonfiles and replaces it in-place, so re-runningchunk initupgrades existing projects without leaving a duplicate group.Test plan
go test ./internal/settings/ -race— all existing + new tests passgo test ./... -race— full suite greengo tool golangci-lint run ./internal/settings/— 0 issuesTestBuildHookMatcherIsToolNameasserts generated matcher is"Bash"and entries carryif: "Bash(git commit*)"TestMergeHooksMigratesLegacyMatcherasserts existing files with old matcher are upgraded to new format with no duplicate groups🤖 Generated with Claude Code