You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SessionEnd hook does not fire with /clear as documentation states. #6428
Runs when a Claude Code session ends. Useful for cleanup tasks, logging session statistics, or saving session state.
The reason field in the hook input will be one of:
**clear - Session cleared with /clear command**
logout - User logged out
prompt_input_exit - User exited while prompt input was visible
other - Other exit reasons
However, I spent a long time testing with --debug and couldn't make SessionEnd fire on /clear command. The SessionStart does fire of course since its a new session after clearing. I'd expect /clear to fire SessionEnd and then SessionStart in succession.
It looks like this issue has been solved in version 2.0.50. I’ve been testing it since I saw this bug report and can confirm that Claude now invokes SessionEnd and SessionStart.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
Related: filed #26052 requesting a PreClear hook event as a broader solution. Even if SessionEnd is fixed to fire on /clear, a dedicated PreClear hook would give users a reliable pre-clear interception point for session logging and state preservation.
env vars in subshells (CLAUDE_SESSION_ID, etc.) stay frozen at pre-/clear values
the new jsonl transcript does carry the correct sessionId in every entry
net effect: tools doing session identity tracking across /clear (mcp servers, external session indexers, hook-based attribution) have to read the transcript filesystem directly since no env/process signal rotates. a SessionEnd:clear event plus a refreshed pid file would close the identity-resolution gap.
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.
Activity
mysehyunhope commentedon Nov 24, 2025
It looks like this issue has been solved in version 2.0.50. I’ve been testing it since I saw this bug report and can confirm that Claude now invokes SessionEnd and SessionStart.
claude code cli, ubuntu(wsl)
github-actions commentedon Dec 25, 2025
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
kyakumithis commentedon Jan 16, 2026
Same issue on Windows 11 with v2.1.9.
SessionEnd hook doesn't trigger for any exit method (
/clear,/exit,Ctrl+D, or closing VS Code window).I've posted detailed findings including test results on #17885, and submitted a full bug report at #18500 with Windows-specific details.
Key finding: On Windows, even
Ctrl+Ddoes NOT trigger the hook (unlike macOS where it reportedly works).bkjou commentedon Feb 16, 2026
Related: filed #26052 requesting a
PreClearhook event as a broader solution. Even ifSessionEndis fixed to fire on/clear, a dedicatedPreClearhook would give users a reliable pre-clear interception point for session logging and state preservation.seanmartinsmith commentedon Apr 24, 2026
adjacent context from testing
/clearidentity behavior on v2.1.119, windows 11:SessionEnddoesn't fire on/clear— this issueSessionStart:clearDOES fire and receives the new sessionId in its hook input~/.claude/sessions/{PID}.jsonkeeps the pre-/clearsessionId— filed separately as ~/.claude/sessions/{PID}.json sessionId field doesn't refresh on /clear — only updatedAt does #53037CLAUDE_ENV_FILEwritten by the re-fired SessionStart hook isn't re-sourced on /clear — [BUG] CLAUDE_ENV_FILE not sourced after /clear creates new session #14433 (closed not-planned)CLAUDE_SESSION_ID, etc.) stay frozen at pre-/clear valuesnet effect: tools doing session identity tracking across
/clear(mcp servers, external session indexers, hook-based attribution) have to read the transcript filesystem directly since no env/process signal rotates. aSessionEnd:clearevent plus a refreshed pid file would close the identity-resolution gap.github-actions commentedon May 28, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Jul 27, 2026
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.