fix: resolve hookify rules from the project root#32931
fix: resolve hookify rules from the project root#32931Atman36 wants to merge 1 commit intoanthropics:mainfrom
Conversation
|
Adding a real-world report from a team I work with, in case it helps prioritize review. The incidentWe have a Last week a bug fix landed in production that introduced exactly this banned pattern — a The thing that made me write this comment is that the hookify rule existed, was enabled, had the correct regex, and would have blocked the exact edit that shipped the bug. It just wasn't loaded. When I investigated after the fact I found this PR, and it was immediately obvious what had happened. Why the rule didn't fireThe session that reviewed and merged the fix was started inside a git worktree at From that cwd, Reproduction (about 60 seconds)mkdir -p /tmp/repro/.claude /tmp/repro/sub/dir
cat > /tmp/repro/.claude/hookify.demo.local.md <<'EOF'
---
name: demo
enabled: true
event: file
conditions:
- field: new_text
operator: contains
pattern: banned_marker
---
blocked
EOF
cd /tmp/repro/sub/dir && python3 -c "
import sys
sys.path.insert(0, '<path-to-hookify-plugin>')
from core.config_loader import load_rules
print('rules loaded:', len(load_rules()))
"
# current main: rules loaded: 0
# this PR: rules loaded: 1On the fix itselfThe approach — One small suggestion if there's appetite for it: printing a single stderr line like There are two sibling PRs for nearby bugs that are worth looking at together with this one: #23972 (Python 3.8 compat + a narrower Happy to add more data, run against a specific branch, or help with review if it would move this along. Thanks for looking. |
What
Resolve hookify rule discovery from the project root instead of assuming the current working directory is the repo root.
Add a unit test that covers loading rules both with
CLAUDE_PROJECT_DIRset and when the process starts from a nested directory.Why
Hookify rule files live in the project's
.claude/directory, but the loader currently looks for.claude/hookify.*.local.mdrelative to the current working directory.That causes hooks to silently stop finding configured rules when Claude Code is launched or resumed from a subdirectory.
How to verify
Notes
No workflow or plugin manifest changes. Scope is limited to rule discovery and regression coverage.