Skip to content

[FEATURE] Pre-exit Claude-action hook — let Claude perform actions before session ends #47612

Closed as not planned

Description

@SWSovereign

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

There is currently no way for Claude to perform actions (file writes, tool calls) before a session ends. Hooks today only support shell commands, and even those don't reliably fire on /exit (#35892).

My concrete use case: I maintain project memory files that Claude reads at session start to pick up where we left off. Before every session ends, Claude needs to update those files with current status and next steps. Today, I have to remember to ask Claude manually before typing /exit. If I forget, context is lost and the next session starts cold.

This goes beyond what was requested in #12755 (closed/locked) and #9293 — those asked for shell-level pre-exit hooks. What's needed is the ability for Claude itself to be the actor during the exit flow.

Proposed Solution

Add a PreSessionEnd hook event where Claude receives and processes a configurable prompt before the session terminates.
Example configuration:
{
"hooks": {
"PreSessionEnd": [
{
"type": "prompt",
"prompt": "Update project memory files with current session status, decisions made, and next steps. Then offer to commit and push any uncommitted changes.",
"timeout": 30
}
]
}
}

Behavior:

  1. User types /exit
  2. PreSessionEnd event fires
  3. Claude receives the configured prompt and executes it — reading/writing files, calling tools as needed
  4. Session ends after Claude completes

Why this matters beyond my use case

The common thread: a shell command can detect these situations, but only Claude can act on them intelligently.

Alternative Solutions

No response

Priority

Medium - Would be very helpful

Feature Category

Configuration and settings

Use Case Example

No response

Additional Context

No response

Activity

  1. github-actions commented on Apr 13, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. Feature Request: PreSessionEnd Hook #16886
    2. Hook before Exit #39085
    3. Add blocking pre-exit hook to prevent session end with uncommitted changes #12755

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. SWSovereign commented on Apr 14, 2026

    @SWSovereign
    Author

    Thank you for flagging the potential duplicates. Let me address each one:

    #16886 — Genuine overlap. Both issues ask for a pre-exit hook where Claude can act autonomously (run a prompt, not just a shell command). My issue covers more use cases, but the core ask is the same. I'd support consolidating these if the maintainers agree.

    #39085 — Partial overlap only. That issue asks for a user-facing reminder or prompt before exit — a UX nudge. My issue asks for Claude to act autonomously at session end without user interaction. Different emphasis, different solution space.

    #12755 — Not a duplicate. That issue is specifically about shell-command hooks that block /exit via non-zero exit code. My issue explicitly cites #12755 and argues that mechanism is insufficient — it can prevent exit but cannot trigger autonomous Claude action. The two issues are complementary, not redundant.

    Suggestion: If maintainers agree #16886 and #47612 are asking for the same thing, consolidation makes sense. But #39085 and #12755 address meaningfully different problems and should remain open independently.

  3. luisbarcia commented on Apr 27, 2026

    @luisbarcia

    Use case: auto-run verification/cleanup skills before session end

    I run a verification-before-completion skill that audits uncommitted changes, stale TODO items, and plan file updates before I finish a session. Today I have to remember to invoke it manually — and I forget ~50% of the time.

    A PreSessionEnd hook (or BeforeExit) that lets Claude execute a prompt/skill autonomously would solve this cleanly. The existing Stop hook fires a shell command after Claude responds — it can't trigger Claude to act (read files, run tools, update plans).

    What I'd configure:

    {
      "hooks": {
        "PreSessionEnd": [{
          "type": "prompt",
          "prompt": "/verification-before-completion"
        }]
      }
    }

    This aligns with #47612's ask — the mechanism needs to be a Claude-action hook (prompt-based), not just a shell-command hook like the Stop event.

  4. github-actions commented on May 30, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  5. github-actions commented on Jul 31, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  6. locked as resolved and limited conversation to collaborators on Jul 31, 2026
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions