fix(hookify): pretooluse.py leaks stop-event rules into PreToolUse evaluation#1355
Closed
adgdei wants to merge 1 commit intoanthropics:mainfrom
Closed
fix(hookify): pretooluse.py leaks stop-event rules into PreToolUse evaluation#1355adgdei wants to merge 1 commit intoanthropics:mainfrom
adgdei wants to merge 1 commit intoanthropics:mainfrom
Conversation
…aluation
pretooluse.py defaults event=None for any tool other than Bash, Edit,
Write, or MultiEdit, then calls load_rules(event=None). The filter in
core/config_loader.py is:
if event:
if rule.event != 'all' and rule.event != event:
continue
When event is None, the 'if event:' guard short-circuits and no
filtering happens. Every rule from every ~/.claude/hookify.*.local.md
file is loaded into the PreToolUse evaluation, including rules declared
with event: stop, event: bash, or event: file.
A stop-event rule whose conditions can match the PreToolUse input
(e.g. a transcript-scanning regex condition) will fire on every
PreToolUse call for tools other than Bash/Edit/Write/MultiEdit. If
the rule's action is block, this denies tools like ToolSearch,
WebFetch, Glob, Grep, Read, etc. — which can create unrecoverable
deadlocks if the user's only path to satisfying the stop rule
requires one of those tools.
Fix: default event to a sentinel string 'pretooluse' so the filter
in load_rules runs as intended:
- rule.event == 'bash' -> skipped
- rule.event == 'file' -> skipped
- rule.event == 'stop' -> skipped (the bug fix)
- rule.event == 'all' -> kept (preserved by 'rule.event != all')
Existing event: all catch-all behavior is preserved. Bash/Edit/Write/
MultiEdit filtering is unchanged.
|
Thanks for your interest! This repo only accepts contributions from Anthropic team members. If you'd like to submit a plugin to the marketplace, please submit your plugin here. |
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.
PR title
fix(hookify): pretooluse.py leaks stop-event rules into PreToolUse evaluationBranch suggestion
fix/hookify-pretooluse-event-filterPR body
Bug
plugins/hookify/hooks/pretooluse.pydefaultsevent = Nonefor any tool other thanBash,Edit,Write, orMultiEdit. It then callsload_rules(event=None).In
plugins/hookify/core/config_loader.py, the filter logic is:When
eventisNone, theif event:guard short-circuits — no filtering happens. Every rule from every~/.claude/hookify.*.local.mdfile is loaded into the PreToolUse evaluation, including rules declared withevent: stop,event: bash, orevent: file.Impact
A
stop-event rule whose conditions can match the PreToolUse input (e.g. a transcript-scanning regex condition) will fire on every PreToolUse call for any tool other than Bash/Edit/Write/MultiEdit. If the rule's action isblock, this denies tools likeToolSearch,WebFetch,Glob,Grep,Read, etc. — which can create unrecoverable deadlocks if the user's only path to satisfying the stop rule requires one of those tools (e.g. a stop rule that requires a specific WebFetch to occur).Fix
Default
eventto a sentinel string'pretooluse'. The filter inload_rulesthen runs as intended:rule.event == 'bash'→ skippedrule.event == 'file'→ skippedrule.event == 'stop'→ skipped (the bug fix)rule.event == 'all'→ kept (preserved by the existingrule.event != 'all'short-circuit)Existing
event: allcatch-all behavior is preserved. Bash/Edit/Write/MultiEdit filtering is unchanged.Reproduction
~/.claude/hookify.test.local.mdwithevent: stop,action: block, and any condition that matches an arbitrary PreToolUse input (e.g. a transcript regex condition that already matches).ToolSearch,WebFetch,Read).Verification