Preflight Checklist
Problem Statement
Since some time, I miss the cost report on exiting. I wanted to bring it back ... but "according to Claude", currently, when exiting Claude Code, there is no way to automatically view the session cost report. Users must remember to manually run /cost before exiting, otherwise the cost information is lost when the session ends.
Proposed Solution
Add one of the following options:
Option 1: Pre-Exit Hook (Preferred)
Add a new hook event PreExit or Exit that runs before the Claude Code session terminates. This would allow users to execute commands like /cost automatically.
Example configuration:
{
"hooks": {
"PreExit": [
{
"hooks": [
{
"type": "command",
"command": "echo 'Session Cost Summary:' && claude-code /cost"
}
]
}
]
}
}
Alternative Solutions
Auto-Display Cost Setting
Add a setting to automatically display the cost report when exiting to bring it back as it was few times ago :
{
"displayCostOnExit": true
}
Priority
Critical - Blocking my work
Feature Category
CLI commands and flags
Use Case Example
As a user who tracks AI usage costs, I want to:
- Automatically see my session costs when I exit Claude Code
- Keep a record of costs without having to remember to run
/cost manually
- Optionally save cost reports to a log file for tracking purposes
Additional Context
- The existing
Stop hook runs after each agent response, not on application exit
- Currently, there is no hook that runs when the user exits the CLI
- Cost data is only available during an active session, making it impossible to retrieve after exit
Alternatives Considered
- Shell alias wrapper - Not viable because cost data is unavailable after session ends
Stop hook - Not suitable as it runs after every response, not on exit
- Manual
/cost before exit - Current workaround, but easy to forget
Benefits
- Improved user experience for cost-conscious users
- Better cost tracking and budgeting capabilities
- Consistent with user expectations for session summary information
- Could be extended to show other session statistics (duration, token usage, etc.)
Preflight Checklist
Problem Statement
Since some time, I miss the cost report on exiting. I wanted to bring it back ... but "according to Claude", currently, when exiting Claude Code, there is no way to automatically view the session cost report. Users must remember to manually run
/costbefore exiting, otherwise the cost information is lost when the session ends.Proposed Solution
Add one of the following options:
Option 1: Pre-Exit Hook (Preferred)
Add a new hook event
PreExitorExitthat runs before the Claude Code session terminates. This would allow users to execute commands like/costautomatically.Example configuration:
{ "hooks": { "PreExit": [ { "hooks": [ { "type": "command", "command": "echo 'Session Cost Summary:' && claude-code /cost" } ] } ] } }Alternative Solutions
Auto-Display Cost Setting
Add a setting to automatically display the cost report when exiting to bring it back as it was few times ago :
{ "displayCostOnExit": true }Priority
Critical - Blocking my work
Feature Category
CLI commands and flags
Use Case Example
As a user who tracks AI usage costs, I want to:
/costmanuallyAdditional Context
Stophook runs after each agent response, not on application exitAlternatives Considered
Stophook - Not suitable as it runs after every response, not on exit/costbefore exit - Current workaround, but easy to forgetBenefits