[FEATURE] Add SessionExit hook event (e.g., for cost tracking)
Resolved 💬 4 comments Opened Mar 9, 2026 by Dunken Closed Apr 12, 2026
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
There's no way to run cleanup commands when a Claude Code session ends. The current hook events (PreToolCall, PostToolCall, Notification, Stop) don't cover session termination via /exit, Ctrl+C, or natural completion.
Proposed Solution
Add a SessionExit hook event that fires when:
- User types /exit
- User presses Ctrl+C
- Session ends naturally
Example configuration in settings.json:
{
"hooks": {
"SessionExit": [{
"command": "~/.claude/scripts/log-session-cost.sh"
}]
}
}
Alternative Solutions
- Shell wrapper: Wrapping the claude command in a shell function works but feels hacky and doesn't capture Ctrl+C gracefully
- PostToolCall hook: Logging on every tool call is wasteful and creates duplicate entries
Priority
Medium - Would be very helpful
Feature Category
Other
Use Case Example
I want to automatically log session costs (token usage, API costs) to a CSV file when exiting Claude Code. Currently I have to manually invoke a custom slash command before every exit, which is easy to forget.
Additional Context
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗