diff --git a/plugins/hookify/README.md b/plugins/hookify/README.md index 1aca6cdfb7..dbb90e3628 100644 --- a/plugins/hookify/README.md +++ b/plugins/hookify/README.md @@ -123,6 +123,7 @@ Ensure credentials are not hardcoded and file is in .gitignore. - **`bash`**: Triggers on Bash tool commands - **`file`**: Triggers on Edit, Write, MultiEdit tools +- **`read`**: Triggers on Read, Glob, Grep, LS tools (file reads, not modifications) - **`stop`**: Triggers when Claude wants to stop (for completion checks) - **`prompt`**: Triggers on user prompt submission - **`all`**: Triggers on all events diff --git a/plugins/hookify/hooks/posttooluse.py b/plugins/hookify/hooks/posttooluse.py index a9e12cc797..ba67ddfa6f 100755 --- a/plugins/hookify/hooks/posttooluse.py +++ b/plugins/hookify/hooks/posttooluse.py @@ -33,13 +33,19 @@ def main(): # Read input from stdin input_data = json.load(sys.stdin) - # Determine event type based on tool + # Map tools to event types for rule filtering: + # - 'bash': Bash commands + # - 'file': File modifications (Edit, Write, MultiEdit) + # - 'read': File reads (Read, Glob, Grep, LS) - should NOT trigger file rules + # - None: Other tools - only 'all' rules fire tool_name = input_data.get('tool_name', '') event = None if tool_name == 'Bash': event = 'bash' elif tool_name in ['Edit', 'Write', 'MultiEdit']: event = 'file' + elif tool_name in ['Read', 'Glob', 'Grep', 'LS']: + event = 'read' # Load rules rules = load_rules(event=event) diff --git a/plugins/hookify/hooks/pretooluse.py b/plugins/hookify/hooks/pretooluse.py index f265c277e3..72ec65547e 100755 --- a/plugins/hookify/hooks/pretooluse.py +++ b/plugins/hookify/hooks/pretooluse.py @@ -42,11 +42,18 @@ def main(): # For PreToolUse, we use tool_name to determine "bash" vs "file" event tool_name = input_data.get('tool_name', '') + # Map tools to event types for rule filtering: + # - 'bash': Bash commands + # - 'file': File modifications (Edit, Write, MultiEdit) + # - 'read': File reads (Read, Glob, Grep, LS) - should NOT trigger file rules + # - None: Other tools - only 'all' rules fire event = None if tool_name == 'Bash': event = 'bash' elif tool_name in ['Edit', 'Write', 'MultiEdit']: event = 'file' + elif tool_name in ['Read', 'Glob', 'Grep', 'LS']: + event = 'read' # Load rules rules = load_rules(event=event) diff --git a/plugins/hookify/skills/writing-rules/SKILL.md b/plugins/hookify/skills/writing-rules/SKILL.md index 008168a4c9..d5624a859e 100644 --- a/plugins/hookify/skills/writing-rules/SKILL.md +++ b/plugins/hookify/skills/writing-rules/SKILL.md @@ -41,6 +41,7 @@ Can include markdown formatting, warnings, suggestions, etc. **event** (required): Which hook event to trigger on - `bash`: Bash tool commands - `file`: Edit, Write, MultiEdit tools +- `read`: Read, Glob, Grep, LS tools (file reads, not modifications) - `stop`: When agent wants to stop - `prompt`: When user submits a prompt - `all`: All events @@ -361,6 +362,7 @@ Warning message **Event types:** - `bash` - Bash commands - `file` - File edits +- `read` - File reads (Read, Glob, Grep, LS) - `stop` - Completion checks - `prompt` - User input - `all` - All events