claude-code - 💡(How to fix) Fix [BUG] PreToolUse hook does not fire when Read tool reads image/binary files

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…

Code Example

{
     "hooks": {
       "PreToolUse": [{
         "matcher": "Read",
         "hooks": [{
           "type": "command",
           "command": "echo '{\"hook\":\"PreToolUse\",\"tool\":\"Read\"}' >> /tmp/hook-log.txt"
         }]
       }]
     }
   }
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report
  • I am using the latest version of Claude Code

What's Wrong?

When Claude Code reads an image file (PNG, JPEG, etc.) using the Read tool, the PreToolUse hook is not triggered. The image is sent directly to the model's vision capabilities. Only a PostToolUse hook fires afterward, with no output content.

For text files, PreToolUse fires correctly with the file_path in tool_input, allowing hooks to inspect or block the read. For image files, this step is skipped entirely.

This means any PreToolUse hook that validates, filters, or blocks file reads based on file path or content cannot intercept image file reads.

What Should Happen?

The PreToolUse hook should fire for Read tool calls on image/binary files, just as it does for text files. The hook data should include tool_input.file_path so hooks can inspect or block the read before it reaches the model.

Steps to Reproduce

  1. Create a PreToolUse hook in ~/.claude/settings.json that logs all tool calls:
    {
      "hooks": {
        "PreToolUse": [{
          "matcher": "Read",
          "hooks": [{
            "type": "command",
            "command": "echo '{\"hook\":\"PreToolUse\",\"tool\":\"Read\"}' >> /tmp/hook-log.txt"
          }]
        }]
      }
    }
  2. Ask Claude to read a text file: Read the file /path/to/test.txt
  3. Check /tmp/hook-log.txt — entry appears (PreToolUse fires correctly for text)
  4. Ask Claude to read an image file: Read the file /path/to/screenshot.png
  5. Check /tmp/hook-log.txtno new entry (PreToolUse does not fire for images)

Claude Model

Opus

Is this a regression?

I don't know

Claude Code Version

2.1.150 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

This also affects the PostToolUse hook — when it does fire for image reads, the tool response contains no output, so hooks cannot inspect image content at any stage.

Related: #16592 (image data not available in UserPromptSubmit hooks either). Together, these two gaps mean there is no hook-based way to intercept or scan image content before it reaches the model.

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 - 💡(How to fix) Fix [BUG] PreToolUse hook does not fire when Read tool reads image/binary files