claude-code - 💡(How to fix) Fix SessionEnd hook event — fires once on true session exit, supports agent/prompt hook types [1 comments, 2 participants]

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…
GitHub stats
anthropics/claude-code#56360Fetched 2026-05-06 06:30:12
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1

Fix Action

Fix / Workaround

Workaround Today

RAW_BUFFERClick to expand / collapse

Problem

The current Stop event fires after every response turn, making it unsuitable for end-of-session work. There is no hook event that fires once when the user genuinely exits or closes a Claude Code session. The agent and prompt hook types — which can invoke Claude reasoning — are restricted to tool events (PreToolUse, PostToolUse, PermissionRequest), leaving session-lifecycle events limited to dumb shell commands.

Requested Changes

  1. Add a SessionEnd event (or rename/repurpose a variant of Stop) that fires exactly once when the user closes the session, not after every turn. Distinguish it from the existing intra-session Stop event.
  2. Allow agent and prompt hook types on SessionEnd, so an intelligent summary/checkpoint can be written automatically without user intervention.

Concrete Use Case

A user wants an automatic session checkpoint — Claude writes a "where we left off" summary to a notes file on exit. This requires reasoning, not just a shell script. Currently impossible without a manual slash command.

Suggested Companion Feature — GDG-Style Output Versioning

For any hook or slash command that writes a file, consider supporting a generation-versioned filename pattern (inspired by IBM OS/360 Generation Data Groups) as an option — e.g., NOTES.G0001V00.md, NOTES.G0002V00.md — so writes never overwrite prior state. Users concerned about destructive overwrites could opt into this naming scheme via a hook output field or slash command convention. This gives a recoverable audit trail without requiring git for every personal notes file.

Workaround Today

Manual /checkpoint slash command in ~/.claude/commands/checkpoint.md. Works, but requires user discipline at session close.


Suggested by KG5ZSH — filed via Claude Code

extent analysis

TL;DR

Implement a SessionEnd event that fires once when the user closes the session, allowing for intelligent summary/checkpoint creation without user intervention.

Guidance

  • Introduce a new SessionEnd event that distinguishes itself from the existing Stop event, ensuring it only fires when the user genuinely exits the session.
  • Modify the agent and prompt hook types to support the new SessionEnd event, enabling the creation of automatic session checkpoints.
  • Consider adding an option for generation-versioned filename patterns to prevent overwrites and provide a recoverable audit trail.
  • In the short term, users can utilize the manual /checkpoint slash command as a workaround, but this requires user discipline.

Example

No code snippet is provided as the issue focuses on feature requests and event handling rather than specific code implementation.

Notes

The implementation of the SessionEnd event and supporting hook types will require careful consideration of session lifecycle management and event handling. Additionally, the generation-versioned filename pattern feature, while useful, may add complexity to the system.

Recommendation

Apply a workaround by using the manual /checkpoint slash command until the SessionEnd event and supporting features are implemented, as this provides a functional, albeit imperfect, solution for creating session checkpoints.

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…

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 event — fires once on true session exit, supports agent/prompt hook types [1 comments, 2 participants]