[Feature Request] Fire PostToolUse or PostToolUseFailure for <tool_use_error> responses

Resolved 💬 4 comments Opened Feb 11, 2026 by moonxorsun Closed Mar 12, 2026

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:

  1. PostToolUseFailure (preferred) — with tool_name, tool_input, and the error message in stdin
  2. PostToolUse — with the error information in tool_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

  1. Configure a PostToolUseFailure hook that writes to a debug file:
{
  "hooks": {
    "PostToolUseFailure": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "python debug_hook.py --hook post-failure"
          }
        ]
      }
    ]
  }
}
  1. Read a non-existent file: the tool returns <tool_use_error>File does not exist.</tool_use_error>
  1. Check the debug file — it is never created. The hook was never called.
  1. Contrast with Bash failure (non-zero exit code) — the debug file is created, confirming PostToolUseFailure works 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 PostToolUseFailure hook 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

View original on GitHub ↗

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