hookify: PreToolUse loads ALL rules (incl. event: stop) for non-Bash/Write/Edit tools — event=None bypasses the event filter and denies MCP tools

Author: fegome90-cmdCreated Aug 27, 2026Updated Sep 27, 2026

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:

python
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):

python
# Filter by event if specified
if event:                      # ← None bypasses the filter: ALL rules load
    if rule.event != 'all' and rule.event != event:
        continue

Chain for an MCP tool with tool_input.content:

  1. event = None → filter bypassed → event: stop rules load into the PreToolUse evaluation.
  2. Legacy pattern: .* → condition field=content, regex_match .* (Rule.from_dict maps non-bash/file patterns to the content field).
  3. tool_input.content exists on write-style MCP tools → .* matches → _rule_matches → True.
  4. action: block + PreToolUse → {"hookSpecificOutput": {"permissionDecision": "deny"}} with no permissionDecisionReason (companion gap: #4260) → the deny surfaces as the generic Blocked 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:

markdown
---
name: stop-rule-deny
enabled: true
event: stop
action: block
pattern: .*
---
placeholder

From the project root (the loader globs .claude/hookify.*.local.md relative to CWD):

bash
# 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:

diff
-            # 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:
+                continue

Alternative (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