Skip to content

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

@ashwingopalsamy

Description

@ashwingopalsamy

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolsbugSomething isn't workingduplicateThis issue or pull request already existshas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions