Skip to content

fix(hookify): support phase-qualified events, absolute paths, and NotebookEdit#42944

Open
Tarun-joy wants to merge 1 commit intoanthropics:mainfrom
Tarun-joy:fix/hookify-phase-events
Open

fix(hookify): support phase-qualified events, absolute paths, and NotebookEdit#42944
Tarun-joy wants to merge 1 commit intoanthropics:mainfrom
Tarun-joy:fix/hookify-phase-events

Conversation

@Tarun-joy
Copy link
Copy Markdown

Summary

  • Fix phase-qualified events (pre-file, post-file, pre-bash, post-bash) being silently dropped due to exact string matching in config_loader.py
  • Use CLAUDE_PROJECT_DIR env var for rule file discovery instead of relative paths (fixes breakage in worktrees and subagents)
  • Add NotebookEdit to file event tool matching in pretooluse.py and posttooluse.py

Problem

Rules with event: post-file never fire because config_loader.py:221 compares 'post-file' != 'file' and filters them out. Users get no error — rules are silently ignored. This affects any hookify user who uses phase-qualified events.

Similarly, load_rules() uses os.path.join('.claude', 'hookify.*.local.md') which fails when the hook runs from a non-project-root working directory (common in worktrees and subagent contexts).

Changes

  • config_loader.py: Added phase parameter to load_rules(), parse phase prefix from event strings, use CLAUDE_PROJECT_DIR for absolute paths
  • pretooluse.py: Pass phase='pre', add NotebookEdit to file event tools, fix import path
  • posttooluse.py: Pass phase='post', add NotebookEdit to file event tools, fix import path

Test

Create .claude/hookify.test.local.md:

---
name: test-post-edit
enabled: true
event: post-file
action: warn
tool_matcher: 'Edit|Write'
conditions:
  - field: file_path
    operator: regex_match
    pattern: \.tsx?$
---
Post-edit reminder showing.

Edit any .ts file — the message should appear after the edit completes.

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.

1 participant