[BUG] if-scoped PreToolUse hook fires unconditionally and doesn't actually block, but reports a stale "blocked" result a turn late
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?
Impact: an if-scoped PreToolUse hook currently provides no real protection (never actually blocks) while producing confusing, delayed false-positive messages that look like the assistant froze.
What Should Happen?
Expected: the hook only runs (and only blocks) when the Bash command text actually matches the if glob pattern.
Actual (confirmed from the session's own transcript JSONL, three separate occurrences):
The if filter isn't enforced — the hook's command executed on Bash calls whose text contained neither delete_item nor Remove-Item anywhere, verified programmatically against the raw tool_use.input.command string.
Despite the hook echoing {"continue": false, ...}, the gated Bash tool call was not actually blocked — in all three cases the underlying command ran to completion and returned its real result (e.g. a Python traceback, or a successful script output) before the hook_stopped_continuation event was recorded.
The hook_stopped_continuation record is logged at the same timestamp as the tool call's own completion, but is surfaced to the user as a message in a subsequent turn — disconnected from the tool call that supposedly triggered it. From the user's side this presented as the assistant appearing to hang/freeze, with an unexplained "deletion blocked" message showing up out of context afterward.
Error Messages/Logs
Steps to Reproduce
Repro steps:
Add the hook above to ~/.claude/settings.json.
Run any Bash tool call whose command text does not contain delete_item or Remove-Item.
Observe: the hook fires anyway (hook_success attachment in the transcript), the Bash command still completes normally, and a hook_stopped_continuation message appears attached to a later turn.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.221
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗