Skip to content

fix(hookify): correct field mapping for stop and prompt events#33007

Open
daniel-dallimore wants to merge 1 commit intoanthropics:mainfrom
daniel-dallimore:fix/hookify-stop-prompt-field-mapping
Open

fix(hookify): correct field mapping for stop and prompt events#33007
daniel-dallimore wants to merge 1 commit intoanthropics:mainfrom
daniel-dallimore:fix/hookify-stop-prompt-field-mapping

Conversation

@daniel-dallimore
Copy link
Copy Markdown

Fixes #32153

Root cause

Rule.from_dict() in plugins/hookify/core/config_loader.py converts a simple pattern field into a Condition by inferring which field to match against based on the event type. The else branch was catching stop and prompt events and mapping them to field='content', but _extract_field() in rule_engine.py has no handler for content on those events — it expects reason for Stop and user_prompt for UserPromptSubmit. This caused _extract_field() to return None, so pattern matching always silently failed.

Fix

Add explicit branches before the else fallback:

elif event == 'stop':
    field = 'reason'
elif event == 'prompt':
    field = 'user_prompt'

Test plan

  • Create a hookify rule with event: stop and a simple pattern — verify it now matches when Claude stops
  • Create a hookify rule with event: prompt and a simple pattern — verify it now matches on user input
  • Existing event: bash and event: file rules continue to work unchanged

🤖 Generated with Claude Code

Rule.from_dict() was mapping stop and prompt events to field='content',
but _extract_field() in rule_engine.py has no handler for 'content' on
those events. It uses 'reason' for Stop and 'user_prompt' for
UserPromptSubmit, so patterns on stop/prompt rules never matched.

Add explicit branches for 'stop' -> 'reason' and 'prompt' -> 'user_prompt'
so simple-pattern rules on these events work correctly.

Fixes anthropics#32153

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: hookify stop/prompt rules never match due to wrong field mapping in config_loader.py

1 participant