[FEATURE] track cost on multiple sessions and provide a shutdown hook to do that ?
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
---
Title: Add SessionEnd hook and expose /cost data to hooks
Body:
Feature Request
Problem
There's no way to run automation when a Claude Code session ends, and /cost data (session cost, tokens, duration) is only available as an internal CLI command — not exposed to hooks or scripts.
Requested Features
- SessionEnd hook event — fires once when the session exits (via /exit, Ctrl+C, or terminal close). This would enable cleanup tasks, cost tracking, session logging, etc.
- Expose /cost data to hooks/environment — make session cost/token data available as:
- Environment variables ($CLAUDE_SESSION_COST, $CLAUDE_SESSION_TOKENS_IN, etc.), or
- A JSON file written on session end (~/.claude/last-session-cost.json)
Proposed Solution
Automatic cost tracking across sessions. Currently the only workflow is manually running /cost and copying numbers. With these two features, a plugin could automatically append cost data to a tracking file
on every session exit.
Alternative Solutions
Workaround
Currently using a /update-cost slash command that requires the user to manually run /cost first, then /update-cost to parse the output from conversation context.
Priority
Medium - Would be very helpful
Feature Category
CLI commands and flags
Use Case Example
Workaround
Currently using a /update-cost slash command that requires the user to manually run /cost first, then /update-cost to parse the output from conversation context.
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗