[BUG] PostToolUseFailure hook always shows 'hook error' even with exit 0
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?
Any PostToolUseFailure hook always shows "PostToolUseFailure:Bash hook error" in the TUI output, even when the hook script exits with code 0 and no stderr output. The hook script also doesn't appear to execute at all (no side effects like log file writes).
This was tested with a minimal hook:
#!/bin/bash
cat > /dev/null
exit 0
And a Python hook that writes to a log file - the log file never gets new entries when triggered by Claude Code (but works fine when tested manually with piped stdin).
Version
Claude Code 2.1.50 on Linux (Ubuntu)
Steps to Reproduce
- Add a PostToolUseFailure hook to
~/.claude/settings.json:
{
"hooks": {
"PostToolUseFailure": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "/tmp/minimal-hook.sh"
}
]
}
]
}
}
- Create the minimal hook:
#!/bin/bash
cat > /dev/null
exit 0
chmod +x /tmp/minimal-hook.sh
- Run any Bash command that fails (e.g.,
falseor a command that exits non-zero)
- Observe "PostToolUseFailure:Bash hook error" in the output
What Should Happen?
- The hook should execute without showing an error (it exits 0)
- The hook should actually run (side effects like log file writes should occur)
- If no stdout is produced, no "hook error" message should be shown
Additional Context
Related to #17088 (PreToolUse hook shows 'error' label even for successful runs), but this is specifically about PostToolUseFailure and the hook script not executing at all (not just a cosmetic label issue).
Tested with:
- Minimal bash hook (cat > /dev/null; exit 0)
- Python hook that writes to a JSONL log (works manually, never runs via Claude Code)
- Absolute paths and tilde paths
- Empty matcher and tool-specific matchers
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗