Add `SessionEnd` hook event for session/thread shutdown
Resolved 💬 7 comments Opened Apr 30, 2026 by matteomekhail Closed Apr 30, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
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—/exitor/quitinterrupt— Ctrl+C / Ctrl+Dhangup— SIGHUP / terminal closedclear—/clearresume—/resumeother— 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
7 Comments
What do you mean by "session/thread shutdown"? New turns can be added to any thread — either immediately or after resuming. So there's really never any point where a thread "ends". If you're looking for a hook that fires when a turn ends, you can use the Stop hook.
What i mean is that this hook should fire everytime we do a /exit or a ctrl+c to close codex
Here is an example of what Claude Code has:
<img width="763" height="482" alt="Image" src="https://github.com/user-attachments/assets/813f2142-8128-4695-bcf1-eaaf2540c96f" />
A thread can be resumed after it "ended", but that does not mean that it was never ended in the first place, it ended and then resumed
This hook would be useful to do a bunch of operations like generating summaries, get information on the type of chat we had, and more
The
/exitaction really makes sense only for a TUI. Our other clients don't support a similar action. Hooks need to work across all surfaces, so I don't think this would make sense to add, at least not in this form.Yes i get the point, in my case i mostly use it in TUI, if something similar can be implemented everywhere it would be nice too
I can imagine calling the hook on command+q when closing the Codex app, ad example
Indexed this hook ticket in the umbrella tracker: #21753
Goal: collect the scattered Codex hook requests and bugs into one parity matrix for Full Claude Code Hook Parity (29+), while preserving this issue as the detailed thread for its specific behavior.
Maybe instead of a /exit-specific hook, we could introduce more generic lifecycle hooks such as SessionAttach / SessionDetach.
Those events would map better across different surfaces (TUI, VSCode, Desktop, Web, etc.), while still allowing unsupported surfaces to simply ignore them if needed.
This would also be very useful for multitask workflows, where external tooling may want to monitor active threads/sessions, track which sessions are currently attached to a client, or perform cleanup/maintenance when the last client detaches.
i see this is not planned but i also see it referenced in this issue.
so should we expect this being added to codex sometime in the future @etraut-openai? a proper session end hook really helps power a lot of useful automation.