claude-code - 💡(How to fix) Fix SessionEnd hook reports 'Hook cancelled' even when hook exits 0 immediately

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

A SessionEnd hook that exits with code 0 within milliseconds is still reported as failed: Hook cancelled in the terminal output at the end of every session.

Error Message

No error message, or a success confirmation.

Root Cause

A SessionEnd hook that exits with code 0 within milliseconds is still reported as failed: Hook cancelled in the terminal output at the end of every session.

Code Example

"hooks": {
     "SessionEnd": [
       {
         "hooks": [
           {
             "type": "command",
             "command": "/path/to/hook.sh"
           }
         ]
       }
     ]
   }

---

Resume this session with:
claude --resume <session-id>
SessionEnd hook [/path/to/hook.sh] failed: Hook cancelled
RAW_BUFFERClick to expand / collapse

Description

A SessionEnd hook that exits with code 0 within milliseconds is still reported as failed: Hook cancelled in the terminal output at the end of every session.

Steps to reproduce

  1. Add a SessionEnd hook to ~/.claude/settings.json:
    "hooks": {
      "SessionEnd": [
        {
          "hooks": [
            {
              "type": "command",
              "command": "/path/to/hook.sh"
            }
          ]
        }
      ]
    }
  2. Make hook.sh a script that exits 0 immediately (e.g. #!/bin/bash + exit 0)
  3. End a session with /exit

Expected behavior

No error message, or a success confirmation.

Actual behavior

Resume this session with:
claude --resume <session-id>
SessionEnd hook [/path/to/hook.sh] failed: Hook cancelled

This appears even when the hook script:

  • Exits with code 0
  • Completes in under 10ms
  • Has trap '' INT TERM HUP to ignore all catchable signals
  • Has been verified to do its work correctly (side effects happen)

Additional context

  • Tested with both a simple exit 0 script and a more complex script that forks work to a double-forked background process before exiting
  • The hook's actual work (writing to a file) completes successfully — the "failure" is purely a display artifact
  • The message appears consistently on every /exit, not just occasionally
  • Platform: macOS 26 (Darwin 25.5.0)

Request

Either:

  • Don't show "failed: Hook cancelled" when the hook exits 0, or
  • Clarify what "Hook cancelled" means and provide a way to suppress the message for hooks that intentionally run fire-and-forget

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

No error message, or a success confirmation.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix SessionEnd hook reports 'Hook cancelled' even when hook exits 0 immediately