[BUG] hookify file rules miss Write tool content for new_text/pattern matching

Resolved 💬 3 comments Opened Feb 9, 2026 by ashwingopalsamy Closed Mar 9, 2026

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_field for Write/Edit)

What Should Happen?

For file rules, new_text should match both:

  • Write via tool_input.content
  • Edit via tool_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

  1. 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
``

  1. Trigger a Write operation that includes console.log(...) in file content.
  2. Observe: no hook warning is shown.
  3. Trigger an Edit operation that adds console.log(...) via new_string.
  4. 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗