OmniscioGuidesPreToolUse hook error
PreToolUse hook error in Claude Code
Last checked against Anthropic's documentation on November 18, 2026. By the Omniscio team. Updated .
What is the exact message?
PreToolUse:Bash hook error: [${CLAUDE_PROJECT_DIR}/.claude/hooks/no-rm.sh]: Blocked: rm commands are not allowedThat is Anthropic's example of a deliberate block: a PreToolUse hook on Bash that exits 2, with its stderr as the reason. The prefix is the event name, the tool name and the hook's command.
The prefix is the same when the hook did not block. What tells the two apart is the text after the bracket: a blocking run repeats your stderr, and a failing run starts with this line instead:
Failed with non-blocking status code: something brokeWhat the exit code decides
- Exit
0: success. Claude Code applies any JSON fields the hook printed, and the action goes ahead unless those fields say otherwise. - Exit
2: a blocking error. OnPreToolUsethe tool call is stopped, and your stderr is the message. - Any other code: a non-blocking error. The action goes ahead, and you see the
PreToolUse:Bash hook errornotice in the transcript.
What the hook prints matters too. A hook that exits 1 but prints one valid JSON object can still set the outcome, because Claude Code reads the fields and ignores the exit code in that case.
Reading the notice
Failed with non-blocking status code:the hook didn't exit 0 or 2, and its stdout was plain text or empty. The call went ahead.No such file or directoryafter that line: the hook never ran, usually because the script path in the configuration is wrong.failed; blocking because onFailure is "block": the hook setsonFailure: "block", so a failure blocks the call. When it times out, the same line saystimed out.- A parse or validation message: the hook printed JSON Claude Code could not read, and the notice carries the reason.
How do I fix it?
- If the block was intended, nothing is broken. The call was stopped by your own policy, and the reason is the stderr your script printed.
- If the hook should have allowed the call, check its exit code. Exit
2always blocks onPreToolUse: exit0to allow, and print JSON if you want to decide more precisely. - If the script never ran, correct the path where the hook is configured. In shell form, a missing or non-executable script makes the shell exit with a code like 127 and the notice carries the interpreter's message.
- If the notice cuts off your stderr, start Claude Code with
claude --debug-file <path>, or runclaude --debugand read~/.claude/debug/<session-id>.txt. The--debugflag writes to that file rather than to the terminal. - If a policy hook must block when it crashes, set
"onFailure": "block"on that hook. Anthropic notes it requires Claude Code v2.1.295 or later.
On Windows without Git Bash
A different rule applies there. A PreToolUse or PermissionRequest command hook that fails or times out blocks the call, and the error says why:
blocking because Git Bash wasn't found, so only exit code 0 or 2 counts as this hook's verdict.Two of the fixes in Anthropic's list: add "onFailure": "continue" to the hook if the call should go ahead when it fails, or install Git for Windows so a shell-form hook runs in Bash rather than PowerShell.
Where these answers come from
- Both message forms, the exit-code rules and the JSON exception: Anthropic's hooks reference, read November 18, 2026.
onFailure, the failure and timeout wording, and the v2.1.295 note: the same reference, in "Block the action when a hook fails", read November 18, 2026.- The Windows-without-Git-Bash line and its fixes: the same reference, read November 18, 2026.
- The debug log commands: the same reference, "Debug hooks", read November 18, 2026.
Common questions
Did the tool run anyway?
Read the notice. A blocking error stopped the call; a non-blocking error let it run. The two are told apart by the wording and by whether the tool's own output appears.
Why does my hook pass some calls and fail others?
A hook sees each tool call's input, so a script that decides from that input answers differently per call. The notice names the tool, which tells you which branch of your script ran.
Can I turn a single hook off without deleting it?
Anthropic's hooks reference covers where a hook is configured and how it is matched. Moving or removing the entry there stops the notice, and the hooks guide walks the file.
Does a hook error mean Claude Code is broken?
No. The notice reports what your hook did. Claude Code itself carried on, and where the action was blocked it was blocked by the hook's own exit code.