Skip to content

[FEATURE] Pre-Exit Hook ( or bring us back Automatic Cost Display on Exit) #9293

Closed as duplicate

Description

@pimpin

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

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

  1. Shell alias wrapper - Not viable because cost data is unavailable after session ends
  2. Stop hook - Not suitable as it runs after every response, not on exit
  3. 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.)

Activity

  1. github-actions commented on Oct 10, 2025

    @github-actions

    Found 3 possible duplicate issues:

    1. Feature Request: Log cost of session to disk (ideally in a structured way) #2622
    2. Need token usage status back in the status line #6222
    3. Feature Request: Restore Time & Token Indicators + Add Context Usage Display #7111

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. added
    duplicateThis issue or pull request already exists
    and removed
    enhancementNew feature or request
    has reproHas detailed reproduction steps
    on Oct 14, 2025
  3. github-actions commented on Oct 14, 2025

    @github-actions

    This issue has been automatically closed as a duplicate of #2622.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  4. mjaggard commented on Oct 17, 2025

    @mjaggard

    @claude @github-actions this is not a duplicate!

  5. aiXander commented on Oct 19, 2025

    @aiXander

    This feature should absolutely be restored. Transparency about costs/task is essential for me

  6. github-actions commented on Oct 26, 2025

    @github-actions

    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.

  7. locked as resolved and limited conversation to collaborators on Oct 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions