Add blocking pre-exit hook to prevent session end with uncommitted changes

Resolved 💬 5 comments Opened Nov 30, 2025 by MikeNikiforos Closed Jan 31, 2026

Problem

The SessionEnd hook fires when a session ends, but it's advisory-only. By the time it fires, the session is already ending and Claude can't act on warnings (e.g., "you have uncommitted changes").

Use case

I use hooks to track uncommitted changes and remind Claude to commit before session end. The SessionEnd hook correctly detects and logs warnings to session notes, but Claude has no opportunity to see or act on these warnings before the session terminates.

Current behavior

  1. User types /exit or closes terminal
  2. SessionEnd hook fires
  3. Hook detects uncommitted changes, logs warning
  4. Session ends immediately - Claude never sees the warning

Proposed solution

Add a PreSessionEnd hook that:

  1. Fires BEFORE session termination (when user requests exit)
  2. Outputs a message that Claude sees and can respond to
  3. Optionally: Can return a non-zero exit code to block the exit (with override like /exit --force)

Workaround attempted

Using Stop hook for periodic reminders works during the session, but doesn't catch the final exit moment. The warning ends up in logs but doesn't prevent the problem.

Example hook usage

{
  "hooks": {
    "PreSessionEnd": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "git status --porcelain | grep -q . && echo 'WARNING: Uncommitted changes!' && exit 1"
          }
        ]
      }
    ]
  }
}

This would allow the hook to block session exit until changes are committed, or at minimum give Claude a chance to respond before the session ends.

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗