Add blocking pre-exit hook to prevent session end with uncommitted changes
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
- User types
/exitor closes terminal - SessionEnd hook fires
- Hook detects uncommitted changes, logs warning
- Session ends immediately - Claude never sees the warning
Proposed solution
Add a PreSessionEnd hook that:
- Fires BEFORE session termination (when user requests exit)
- Outputs a message that Claude sees and can respond to
- 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.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗