Skip to content

Add SessionEnd hook event for session/thread shutdown #20374

Closed as not planned
Closed as not planned

Description

@matteomekhail

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

Activity

  1. added
    CLIIssues related to the Codex CLI
    hooksIssues related to event hooks
    sessionIssues involving session (thread) management, resuming, forking, naming, archiving
    on Apr 30, 2026
  2. etraut-openai commented on Apr 30, 2026

    @etraut-openai
    Contributor

    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.

  3. removed
    CLIIssues related to the Codex CLI
    sessionIssues involving session (thread) management, resuming, forking, naming, archiving
    on Apr 30, 2026
  4. matteomekhail commented on May 1, 2026

    @matteomekhail
    Author

    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:
    Image

    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

  5. etraut-openai commented on May 1, 2026

    @etraut-openai
    Contributor

    The /exit action 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.

  6. matteomekhail commented on May 1, 2026

    @matteomekhail
    Author

    The /exit action 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

  7. oxysoft commented on May 8, 2026

    @oxysoft

    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.

  8. lowlandsheperd commented on May 15, 2026

    @lowlandsheperd

    The /exit action 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.

    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.

  9. idodekerobo commented on May 24, 2026

    @idodekerobo

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthooksIssues related to event hooks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions