[BUG] PreToolUse hook "block" response ignored on Windows

Resolved 💬 2 comments Opened Jan 30, 2026 by mspsealsdev Closed Jan 30, 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?

reToolUse hooks execute correctly and output valid {"result":"block",...} JSON to stdout, but Claude Code ignores the block response and proceeds with the tool execution anyway.

What Should Happen?

  • Hook outputs {"result":"block","reason":"..."}
  • Claude Code blocks the Write operation
  • User sees the block reason message

Error Messages/Logs

Debug logging added to the hook confirms:


[2026-01-30 13:11:18] PYTHON: Raw input received, length=509
[2026-01-30 13:11:18] PYTHON: tool_name=Write, file_path=D:\msp seals\warehouse\claude\test_python.md
[2026-01-30 13:11:18] PYTHON: Checking filename: test_python.md
[2026-01-30 13:11:18] PYTHON: BLOCKING: Filename 'test_python.md' contains underscores...

Steps to Reproduce

  1. Create a PreToolUse hook script (check-underscore-filename.py):
#!/usr/bin/env python3
import sys
import json
import os

def main():
    raw_input = sys.stdin.read()
    data = json.loads(raw_input)
    tool_name = data.get("tool_name", "")
    file_path = data.get("tool_input", {}).get("file_path", "")

    if tool_name in ("Edit", "Write"):
        if file_path and file_path.lower().endswith(".md"):
            filename = os.path.basename(file_path)
            if "_" in filename:
                print(json.dumps({
                    "result": "block",
                    "reason": f"Filename '{filename}' contains underscores."
                }), flush=True)
                return

    print(json.dumps({"result": "continue"}), flush=True)

if __name__ == "__main__":
    main()
  1. Configure the hook in ~/.claude/settings.json:
{
  "hooks": {
    "PreToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "python C:\\Users\\USERNAME\\.claude\\hooks\\check-underscore-filename.py",
            "timeout": 5000
          }
        ]
      }
    ]
  }
}
  1. Restart Claude Code
  2. Ask Claude to create a file like test_underscore.md

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.23 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

hook-bug-report.md

View original on GitHub ↗

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