Feature request: SessionEnd / BeforeSessionEnd hook event

Resolved 💬 4 comments Opened Mar 26, 2026 by jkot Closed May 25, 2026

Problem

There's no hook event that fires once when a session is about to end. The closest options:

  • Stop — fires after every response, not just the last one. Too noisy for session-end logic.
  • PreCompact — fires before context compaction, but with 1M context windows most sessions never trigger it.

Use Case

Maintaining persistent memory (notes, summaries, decisions log) across sessions. There's no reliable automated trigger to save session context before it's lost. Currently relies on CLAUDE.md instructions, which is the "remember to do it" approach — the same class of problem that git hooks solve for linting.

Proposed Solution

A BeforeSessionEnd hook event that fires once when the session is ending:

  • User closes terminal / kills process
  • User runs /clear or starts new conversation
  • Session times out from inactivity

Should support systemMessage injection so Claude can take a final action (write memory, summarize) before context is gone.

SessionEnd (post-close, shell command only) would also be useful but less powerful since Claude can't act on it.

Alternatives Considered

| Approach | Problem |
|----------|---------|
| Stop hook | Fires after every response — pollutes context |
| PreCompact hook | Rarely fires with large context windows |
| CLAUDE.md instruction | Relies on discipline, unreliable |
| UserPromptSubmit counter | Hacky, still noisy |

View original on GitHub ↗

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