claude-code - 💡(How to fix) Fix hookify plugin: rule_engine.py _extract_field doesn't handle Write tool's content field [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48287Fetched 2026-04-16 07:04:03
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Fix Action

Fix

Line 239:

return tool_input.get('new_string') or tool_input.get('content', '')

This makes new_text work as a universal "new content being written" field for both Write and Edit.

Code Example

return tool_input.get('new_string', '')

---

return tool_input.get('new_string') or tool_input.get('content', '')
RAW_BUFFERClick to expand / collapse

Bug

In plugins/hookify/core/rule_engine.py at line 239, the _extract_field method handles the new_text field for the Write tool by returning:

return tool_input.get('new_string', '')

But the Write tool uses content, not new_string. Only Edit uses new_string.

Impact

Hookify rules configured with field: new_text and event: file never match on Write tool operations. They only match on Edit. Any rule meant to catch patterns in newly-written files (em dashes, forbidden phrases, secrets, etc.) silently fails when the file is created via Write instead of edited via Edit.

Fix

Line 239:

return tool_input.get('new_string') or tool_input.get('content', '')

This makes new_text work as a universal "new content being written" field for both Write and Edit.

extent analysis

TL;DR

Update the _extract_field method in rule_engine.py to handle both new_string and content fields for the Write and Edit tools.

Guidance

  • Verify that the issue is indeed caused by the mismatch between new_string and content fields in the Write and Edit tools.
  • Update line 239 of rule_engine.py to use the suggested fix: return tool_input.get('new_string') or tool_input.get('content', '').
  • Test the updated code with both Write and Edit tool operations to ensure that the new_text field works as expected.
  • Review existing Hookify rules to ensure they are correctly configured to use the new_text field for file events.

Example

# Updated _extract_field method
def _extract_field(tool_input, field):
    if field == 'new_text':
        return tool_input.get('new_string') or tool_input.get('content', '')
    # ... rest of the method remains the same

Notes

This fix assumes that the content field is always present in the Write tool input when the new_string field is not. If this is not the case, additional error handling may be necessary.

Recommendation

Apply the suggested workaround by updating the _extract_field method, as it provides a universal solution for both Write and Edit tools.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING