[Feature Request] Fire PostToolUse or PostToolUseFailure for <tool_use_error> responses
Feature Type
Hook system enhancement
Problem Description
When built-in tools (Read, Edit, Glob, Grep) return <tool_use_error> responses (e.g., "File does not exist", "Directory does not exist"), neither PostToolUse nor PostToolUseFailure hooks are fired. This makes it impossible for hook developers to detect or react to these common tool failures.
Current Behavior
| Tool | Failure Scenario | PostToolUse | PostToolUseFailure |
|------|-----------------|-------------|-------------------|
| Bash | Non-zero exit code | Not fired | Fired ✅ |
| Write | ENOENT (invalid path) | Not fired | Fired ✅ |
| Read | "File does not exist" | Not fired ❌ | Not fired ❌ |
| Edit | "File does not exist" | Not fired ❌ | Not fired ❌ |
| Glob | "Directory does not exist" | Not fired ❌ | Not fired ❌ |
| Grep | "Path does not exist" | Not fired ❌ | Not fired ❌ |
Tools that return <tool_use_error> produce no hook event at all — no PostToolUse, no PostToolUseFailure, no operations log entry. The error is only visible in the AI's tool result text.
Expected Behavior
When a tool returns a <tool_use_error> response, at least one of the following should fire:
PostToolUseFailure(preferred) — withtool_name,tool_input, and the error message in stdinPostToolUse— with the error information intool_response
This would allow hook developers to:
- Track and log tool failures
- Implement retry/escalation logic (e.g., "3 consecutive failures → ask user for help")
- Provide debugging context after failures
- Build observability tooling that covers all tool outcomes
Steps to Reproduce
- Configure a
PostToolUseFailurehook that writes to a debug file:
{
"hooks": {
"PostToolUseFailure": [
{
"hooks": [
{
"type": "command",
"command": "python debug_hook.py --hook post-failure"
}
]
}
]
}
}
- Read a non-existent file: the tool returns
<tool_use_error>File does not exist.</tool_use_error>
- Check the debug file — it is never created. The hook was never called.
- Contrast with Bash failure (non-zero exit code) — the debug file is created, confirming
PostToolUseFailureworks for Bash.
Environment
- Claude Code Version: 2.1.34
- Platform: Windows (MINGW64)
- Hook types tested: PostToolUse, PostToolUseFailure
Additional Context
- Related: #19372 (PostToolUseFailure documentation is missing from the main Hooks reference)
- The
PostToolUseFailurehook works correctly for Bash (non-zero exit code) and Write (ENOENT), confirming the hook system itself is functional - The gap is specifically for
<tool_use_error>responses from built-in tools like Read, Edit, Glob, and Grep
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗