⌨️PostToolUseFailure Hook
Also known as PostToolUseFailure
The event when a tool fails, used to log, alert or give Claude a hint.
Think of it like
It is like an alarm. It rings only when a job goes wrong.
Example
Jack's tests keep failing on a missing package. His hook spots that error and tells Claude to run npm install first.
Why it matters
Success and failure come through different doors. A hook on success never sees a failure.
Definition
Example code
json
{
"hooks": {
"PostToolUseFailure": [
{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "./log-failure.sh" }] }
]
}
}Common mistake
Key takeaways
- 1When a tool fails. Not on success.
- 2Gets the error. Name, input, error.
- 3Log or hint. Common uses.