codex - 💡(How to fix) Fix Add `SessionEnd` hook event for session/thread shutdown [4 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
openai/codex#20374Fetched 2026-05-01 05:43:34
View on GitHub
Comments
4
Participants
2
Timeline
11
Reactions
1
Timeline (top)
commented ×4labeled ×4unlabeled ×2closed ×1

Root Cause

The idea for it came because i was developing https://clawd.date, and i wanted to support codex CLI, i can't do it without a session-end hook

Fix Action

Fix / Workaround

A SessionEnd hook that fires before a thread tears down, with a reason field that doubles as the dispatch matcher:

RAW_BUFFERClick to expand / collapse

What variant of Codex are you using?

CLI

What feature would you like to see?

Codex has SessionStart but no symmetric SessionEnd hook. There is currently no reliable way to flush analytics, archive a transcript, or clean up scratch files when a session ends.

A SessionEnd hook that fires before a thread tears down, with a reason field that doubles as the dispatch matcher:

  • slash_exit/exit or /quit
  • interrupt — Ctrl+C / Ctrl+D
  • hangup — SIGHUP / terminal closed
  • clear/clear
  • resume/resume
  • other — logout, etc.

An example of how i would implement it is here: https://github.com/matteomekhail/codex/tree/session-end-hook

Additional information

The idea for it came because i was developing https://clawd.date, and i wanted to support codex CLI, i can't do it without a session-end hook

Here is my implemention of this session hook if it can accellerate things: https://github.com/matteomekhail/codex/tree/session-end-hook

extent analysis

TL;DR

Implementing a SessionEnd hook with a reason field can provide a reliable way to flush analytics, archive transcripts, and clean up scratch files when a session ends.

Guidance

  • Review the proposed implementation of the SessionEnd hook at https://github.com/matteomekhail/codex/tree/session-end-hook to understand the suggested changes.
  • Consider the different reason fields (e.g., slash_exit, interrupt, hangup, clear, resume, other) and how they can be used to handle various session termination scenarios.
  • Evaluate the potential impact of adding a SessionEnd hook on existing Codex functionality and integrations.
  • Discuss the proposed implementation with the Codex development team to determine the best approach for integrating the SessionEnd hook.

Example

No code snippet is provided as the issue links to a GitHub repository with the proposed implementation.

Notes

The implementation of the SessionEnd hook may require careful consideration of the various session termination scenarios and how they should be handled to ensure reliable cleanup and analytics flushing.

Recommendation

Apply workaround: Implement the proposed SessionEnd hook as described in the issue, as it provides a clear solution to the problem of reliably flushing analytics and cleaning up resources when a session ends.

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

codex - 💡(How to fix) Fix Add `SessionEnd` hook event for session/thread shutdown [4 comments, 2 participants]