[BUG] hookify file rules miss Write tool content for new_text/pattern matching
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
hookify file rules that rely on new_text (including legacy event: file + pattern) do not trigger when the tool is Write.
In Write, content is sent via tool_input.content, but new_text resolution only checks new_string.
Result: warnings/blocks can trigger for Edit but silently fail for Write.
Affected area:
plugins/hookify/core/rule_engine.py(_extract_fieldforWrite/Edit)
What Should Happen?
For file rules, new_text should match both:
Writeviatool_input.contentEditviatool_input.new_string
So the same rule behaves consistently for new-file writes and edits.
Error Messages/Logs
No explicit runtime error is shown.
Behavioral mismatch only: rule does not trigger on Write.
Steps to Reproduce
- Create a hookify rule file:
hookify.warn-console-log.local.md
````
---
name: warn-console-log
enabled: true
event: file
pattern: console\.log\(
action: warn
---
Console.log detected
- Trigger a
Writeoperation that includesconsole.log(...)in file content. - Observe: no hook warning is shown.
- Trigger an
Editoperation that addsconsole.log(...)vianew_string. - Observe: hook warning appears.
Claude Model
Not sure / Multiple models
Is this a regression?
No, this never worked
Last Working Version
N/A
Claude Code Version
2.1.37
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
A minimal fix is to map new_text across both fields for file tools:
new_string(Edit)content(Write)
PR prepared from fork addresses this exact mapping -> #24321
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗