hookify: PreToolUse loads ALL rules (incl. event: stop) for non-Bash/Write/Edit tools — event=None bypasses the event filter and denies MCP tools
Summary
hooks/pretooluse.py derives the rule event from the tool name (Bash → bash, Edit|Write|MultiEdit → file) and leaves event = None for every other tool — including all mcp__* tools. load_rules(event=None) then skips the event filter entirely (core/config_loader.py, if event: guard), so rules authored for other events (e.g. event: stop) are loaded and evaluated during PreToolUse. A stop rule using the legacy pattern field becomes a content condition; any MCP tool whose tool_input contains a matching field (e.g. content) gets denied — with no permissionDecisionReason, so the client surfaces only the generic Blocked by PreToolUse hook message.
Root cause (verified at current HEAD)
plugins/hookify/hooks/pretooluse.py:
event = None
if tool_name == 'Bash':
event = 'bash'
elif tool_name in ['Edit', 'Write', 'MultiEdit']:
event = 'file'
rules = load_rules(event=event)plugins/hookify/core/config_loader.py (~line 220):
# Filter by event if specified
if event: # ← None bypasses the filter: ALL rules load
if rule.event != 'all' and rule.event != event:
continueChain for an MCP tool with tool_input.content:
event = None→ filter bypassed →event: stoprules load into the PreToolUse evaluation.- Legacy
pattern: .*→ conditionfield=content, regex_match .*(Rule.from_dictmaps non-bash/file patterns to thecontentfield). tool_input.contentexists on write-style MCP tools →.*matches →_rule_matches→ True.action: block+ PreToolUse →{"hookSpecificOutput": {"permissionDecision": "deny"}}with nopermissionDecisionReason(companion gap: #4260) → the deny surfaces as the genericBlocked by PreToolUse hook.
Read-only MCP tools (no content field) pass, which makes the failure look nondeterministic. Because the hook exits 0 and "succeeds", nothing shows up in hook failure logs — in our case every memory-write MCP call was silently denied for weeks while looking like a client bug.
Note: the same stop rules never actually fire on Stop either — Stop payloads have no content field, so _extract_field returns None and the condition fails. The rules are dead code on their target event and only do collateral damage here.
Reproduction
Rule file at <project>/.claude/hookify.stop-rule-deny.local.md:
---
name: stop-rule-deny
enabled: true
event: stop
action: block
pattern: .*
---
placeholderFrom the project root (the loader globs .claude/hookify.*.local.md relative to CWD):
# MCP tool WITH a content field → denied
printf '%s' '{"hook_event_name":"PreToolUse","tool_name":"mcp__engram__mem_save","tool_input":{"content":"hello"}}' \
| CLAUDE_PLUGIN_ROOT=<path-to>/plugins/hookify python3 plugins/hookify/hooks/pretooluse.py
# → {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny"}, "systemMessage": "**[stop-rule-deny]**\nplaceholder"}
# Same rule, MCP tool WITHOUT a content field → allowed
printf '%s' '{"hook_event_name":"PreToolUse","tool_name":"mcp__engram__mem_doctor","tool_input":{}}' \
| CLAUDE_PLUGIN_ROOT=<path-to>/plugins/hookify python3 plugins/hookify/hooks/pretooluse.py
# → {}Impact
Any user with an action: block rule for a non-PreToolUse event that uses the legacy pattern field gets all MCP tool calls carrying a matching tool_input field denied, with a generic message that points at the client rather than the plugin. Read-vs-write asymmetry (field presence) makes it look intermittent.
Suggested fix
Make the event filter unconditional in core/config_loader.py so that when event is None only event: 'all' rules apply:
- # Filter by event if specified
- if event:
- if rule.event != 'all' and rule.event != event:
- continue
+ # Filter by event; when the caller passes event=None (tool class
+ # not mapped, e.g. MCP tools), only 'all' rules should apply.
+ if rule.event != 'all' and rule.event != event:
+ continueAlternative (or complementary): have pretooluse.py bail out before loading rules when it could not classify the tool: rules = load_rules(event=event) if event else [].
Additionally, pairing this with permissionDecisionReason on deny outputs (#4260) would have made this class of failure self-explanatory.
Workaround
Disable the offending rule files (enabled: false) or scope them with explicit conditions on fields that only exist in their intended event's payload.
Related: #4260
Source: anthropics/claude-plugins-official