claude-code - ✅(Solved) Fix hookify: _extract_field returns wrong key for Write tool on new_text field [1 pull requests, 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#48284Fetched 2026-04-16 07:04:08
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×3cross-referenced ×2commented ×1

Root Cause

  1. Create a hookify rule with event: file and field: new_text
  2. Trigger a Write tool call
  3. The rule never matches because tool_input.get('new_string', '') returns empty string for Write inputs

Fix Action

Fix

Line 239 should check both keys:

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 tools.

PR fix notes

PR #48335: fix(hookify): support Write content for new_text rules

Description (problem / solution / changelog)

Summary

  • make field: new_text read content for Write tool payloads as well as new_string for Edit tool payloads

Related issue

  • Closes #48284

Guideline alignment

  • one focused runtime fix in a single plugin file
  • no unrelated plugin, docs, or generated-file changes

Validation

  • git diff --check
  • local Python assertion covering both Write and Edit extraction paths

Changed files

  • plugins/hookify/core/rule_engine.py (modified, +1/-1)

Code Example

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

Bug

In plugins/hookify/core/rule_engine.py, the _extract_field method (line 239) handles the new_text field for file events by returning tool_input.get('new_string', ''). This works for the Edit tool, but the Write tool uses content as its key, not new_string.

Any hookify rule using field: new_text with event: file silently fails to match on Write tool operations. It only works on Edit.

Reproduction

  1. Create a hookify rule with event: file and field: new_text
  2. Trigger a Write tool call
  3. The rule never matches because tool_input.get('new_string', '') returns empty string for Write inputs

Fix

Line 239 should check both keys:

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 tools.

extent analysis

TL;DR

Update the _extract_field method in rule_engine.py to handle both 'new_string' and 'content' keys for the new_text field.

Guidance

  • Identify the line of code causing the issue (line 239 in rule_engine.py) and update it to check for both 'new_string' and 'content' keys.
  • Verify the fix by creating a hookify rule with event: file and field: new_text, then trigger a Write tool call to ensure the rule matches as expected.
  • Test the fix with both Edit and Write tool operations to ensure compatibility.
  • Review other parts of the codebase that may rely on the new_text field to ensure this change does not introduce any regressions.

Example

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

This code snippet updates the _extract_field method to return the value of either 'new_string' or 'content' from the tool_input dictionary.

Notes

This fix assumes that the 'new_string' and 'content' keys are mutually exclusive in the tool_input dictionary. If this is not the case, additional logic may be needed to handle the overlap.

Recommendation

Apply the workaround by updating the _extract_field method as described, as it provides a clear and targeted solution to the issue.

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

claude-code - ✅(Solved) Fix hookify: _extract_field returns wrong key for Write tool on new_text field [1 pull requests, 1 comments, 2 participants]