Feature Request: PostToolUseFailed hook for bash command failures

Resolved 💬 8 comments Opened Jan 4, 2026 by rfisch Closed Mar 1, 2026

Summary

Add a PostToolUseFailed hook (or extend PostToolUse with failure context) that triggers when a bash command exits with a non-zero exit code.

Use Case

I'm building a "learning flywheel" system where command failures should be captured as lessons learned to prevent repeating mistakes. Currently:

  1. Bash command fails (exit code != 0)
  2. I want to automatically prompt/remind to run a failure capture command
  3. Problem: PostToolUse only fires on successful completion, so failures go undetected by hooks

Current Limitation

From the docs, PostToolUse runs "after a tool completes successfully." There's no hook for when tools fail.

Proposed Solution

Option A: Add PostToolUseFailed event type

{
  "hooks": {
    "PostToolUseFailed": [
      {
        "matcher": { "tool_name": "Bash" },
        "hooks": [{ "type": "command", "command": "./on-failure.sh" }]
      }
    ]
  }
}

Option B: Extend PostToolUse to always fire, with exit code in context

{
  "tool_name": "Bash",
  "exit_code": 1,
  "succeeded": false,
  "output": "..."
}

Impact

This would enable:

  • Automated failure logging/learning systems
  • CI-style failure notifications
  • Quality enforcement workflows
  • Better debugging context preservation

Environment

  • Claude Code CLI
  • macOS/Linux

View original on GitHub ↗

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