perf: add matcher groups to PreToolUse/PostToolUse hooks#176
Merged
Conversation
Split PreToolUse from 1 group (10 hooks) into 7 matcher-filtered groups and PostToolUse from 1 group (13 hooks) into 7 groups. This prevents process spawning for non-matching tools — a Read/Grep/Glob call now spawns 0 PreToolUse hooks instead of 10. Matcher groups: Bash, Bash|Edit, Bash|Write|Edit, Write|Edit, Write, Edit, Agent, Read, Skill|Agent, and an unfiltered group for hooks that need all tool events. Remove dead tool_name self-filter code from 18 Python hooks — the matcher in settings.json now handles filtering before the process spawns. Dead constants (TARGET_TOOLS, TRACKED_TOOLS) also removed.
Tests that verified tool_name self-filtering now document that filtering is handled by the matcher field in settings.json. Hooks still exit 0 for any input (non-blocking), so tests verify that contract instead. Fix ruff I001 import sorting in record-activation.py.
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
TARGET_TOOLS,TRACKED_TOOLS)Performance impact
Why
matchernotifThe new
iffield uses glob patterns anchored to command start. Our hard gates use substring matching to catch compound commands (cd dir && git commit). Usingifon safety gates would miss edge cases — a correctness regression. Thematcherfield provides the biggest win without safety tradeoffs.Test plan