PostToolUse hooks should fire for failed tool calls (not just successful ones)
Summary
This is a follow-up to #6371, which was auto-closed due to inactivity. The feature request remains relevant.
Current behavior: PostToolUse hooks only fire when tools complete successfully. Failed tool calls (e.g., Bash commands with non-zero exit codes) skip the hook entirely.
Requested behavior: PostToolUse should fire for all tool completions, with success: false and failure details when the tool fails.
Refined Proposal (from #6371 discussion)
Instead of introducing a separate PostToolFailure hook, modify PostToolUse to:
- Fire for all tool completions (success or failure)
- Include
"success": truefor successful calls (current behavior) - Include
"success": falseplus afailure_detailsobject for failed calls:
{
"session_id": "abc123...",
"hook_event_name": "PostToolUse",
"tool_name": "Bash",
"tool_input": {
"command": "ls nonexistent-file.txt"
},
"success": false,
"failure_details": {
"exit_code": 2,
"stdout": "",
"stderr": "ls: cannot access 'nonexistent-file.txt': No such file or directory",
"error_type": "CommandFailed"
}
}
The existing tool_response.success field already exists in the schema, suggesting this may have been the original design intent.
Use Cases
- Analytics & logging: Track all tool usage including failures to improve MCP server instructions and tool schemas
- Contextual error feedback: Hook can provide Claude with better context (e.g., "file not found - here are files in current directory")
- Automated remediation hints: Parse stderr and suggest fixes (e.g.,
git push --set-upstream origin branch-name) - Cleanup after failures: Remove temp files/directories created before a multi-step operation failed
Original Issue
See #6371 for full reproduction steps, debug output evidence, and detailed discussion. Credit to the original author and commenters (@Twizzes, @coygeek, @richardkmichael) for the thorough analysis.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗