claude-code - 💡(How to fix) Fix Add lifecycle hooks for session clear and exit events [2 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#47861Fetched 2026-04-15 06:40:14
View on GitHub
Comments
2
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×2labeled ×2subscribed ×1
RAW_BUFFERClick to expand / collapse

Problem

Hooks currently only fire on tool-call events (pre/post). There's no way to trigger actions when a session ends — either via /clear, exit, or terminal close.

Use case

I use CLAUDE.md to instruct Claude to save conversation history to markdown files and commit them to git at the end of each session. This works when I remember to ask, but there's no way to automate it. A pre-clear or pre-exit hook would allow running a shell command (or prompting Claude to act) before context is lost.

Proposal

Add hook events for session lifecycle:

  • pre-clear — fires before /clear wipes context
  • pre-exit — fires before the session terminates

These would follow the same settings.json hook format as existing tool hooks.

extent analysis

TL;DR

Implementing pre-clear and pre-exit hook events in the session lifecycle would allow for automated actions before context is lost.

Guidance

  • To address the issue, consider adding hook events for session lifecycle management, specifically pre-clear and pre-exit, to trigger actions before context is wiped or the session terminates.
  • These new hook events should follow the existing settings.json hook format used for tool hooks to maintain consistency.
  • Evaluate the feasibility of integrating these hook events into the current system, ensuring they do not interfere with existing functionality.
  • Consider the potential use cases and benefits of such hook events, such as automating tasks like saving conversation history to markdown files and committing them to git.

Example

No code snippet is provided due to the lack of specific implementation details in the issue.

Notes

The proposal suggests adding new hook events, which may require modifications to the existing system. It is essential to assess the impact of these changes on the overall functionality and performance.

Recommendation

Apply workaround: Implementing the proposed pre-clear and pre-exit hook events would provide a direct solution to the issue, allowing for automated actions at the end of each session.

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