SessionEnd hook intermittently not fired for headless (-p) sessions (~50% observed)
Status Fixed / completed
Maintainer reply None cached
Workaround ✓ Mentioned in description ↑
Activity 2 comments · opened Sep 29, 2026 · closed Sep 29, 2026
Summary
When running claude -p headless sessions programmatically (spawned by an external daemon, permission-mode acceptEdits, --allowedTools set, --session-id given), the SessionEnd hook fires for only about half of the sessions. The other half terminate normally (transcript complete, exit) but never execute the SessionEnd hook — no hook process launch, no manifest, nothing.
Environment
- Windows 11, claude CLI via cmd.exe shim
-pmode,--session-idprovided- SessionEnd hook registered in project settings — works reliably in interactive sessions and fires in some headless runs
Reproduction (A/B pair from the same daemon, same code path, minutes apart)
- Session A (
1110c2e7…): headless-prun → SessionEnd fired → our hook created its expected on-disk artifact (session-end-jobs/<sid>.json). - Session B (
fd32ff8f…): headless-prun, same shape → no SessionEnd at all: transcript exists and is complete, but the hook never launched (no artifact, no log entry from the hook itself). - Across 6 headless sessions in one day: 3 fired, 3 didn't. Presence/absence of specific transcript ending shapes did not correlate with firing.
Impact
Anything that relies on SessionEnd for cleanup or downstream triggering in headless/automation contexts (CI agents, daemon-driven agent fleets) silently loses the signal ~50% of the time.
Workaround
None found; we currently poll for artifacts instead of trusting the hook (undesirable).
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗