DCR: PreSessionEnd and PreClear hook events
Resolved 💬 3 comments Opened Feb 15, 2026 by abecutter Closed Feb 19, 2026
Summary
Add hook events that fire before session termination (/exit, terminal close) and before context clear (/clear).
Problem
Claude Code sessions accumulate state that needs cleanup before exit:
- Uncommitted changes that will be lost
- Unpushed commits (local work invisible to collaborators)
- Issues closed without resolution documentation
- Handoff notes not updated for session continuity
- Worktrees not cleaned up
- Background tasks still running
Current situation: Users must remember to run cleanup manually. They don't. Context is lost, work is orphaned, continuity breaks.
Proposed Solution
Add two new hook events:
PreSessionEnd
Fires before /exit or terminal close.
PreClear
Fires before /clear wipes context.
Hook Contract
{
"hooks": {
"PreSessionEnd": [
{
"type": "command",
"command": "powershell -File cleanup.ps1"
}
],
"PreClear": [
{
"type": "command",
"command": "powershell -File save-context.ps1"
}
]
}
}
Input to hook: Session metadata (duration, tools used, files modified, git status)
Constraints:
- Must complete in <5s or timeout
- Cannot block exit (exit always succeeds even if hook fails)
- Advisory only - can display warnings but not prevent action
Use Cases
- Warn about uncommitted/unpushed changes
- Update session handoff notes automatically
- Clean up temporary resources (worktrees, background tasks)
- Audit trail logging (session end timestamp)
- Prompt to run
/session-endskill if not already run
Value Proposition
Enables "pit of success" - correct behavior by default, not by memory. Critical for methodology compliance in multi-agent workflows where session continuity matters.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗