[FEATURE] Add persistent total cost tracking across compactions
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
When a conversation gets compacted (either manually via /compact or automatically when context limits are reached), the /cost counter resets to $0. This makes it impossible to know the true total cost of a session.
Use case: When working on a feature or project within a single session, the conversation often gets compacted multiple times. I'd like to know the total cost of the entire session, not just the cost since the last compaction.
Current behavior:
- /cost shows usage only since the last compaction
- After compaction, the counter resets to $0
- No way to retrieve the cumulative cost
Expected behavior:
- /cost should show both the current segment cost AND the cumulative session total
Example output could include a line like Total session cost: $X.XX alongside the current segment breakdown
Workaround: Manually noting down /cost before each compaction and adding them up, which is error-prone and easy to forget.
Proposed Solution
Persist a running total — Before each compaction, snapshot the current cost and add it to a running total stored in session metadata (outside the conversation context that gets compacted).
Display both values in /cost — Show "Current segment" and "Total session" as separate lines.
Optional: Session summary file — On session end or on demand, write a cost summary to a local file (e.g., ~/.claude/sessions/<id>/cost.json) so users can reference it later for project budgeting.
Optional: /cost --all — A flag to list cost breakdown per segment (e.g., Segment 1: $12.52, Segment 2: $2.34, Segment 3: $0.38).
Alternative Solutions
_No response_
Priority
Critical - Blocking my work
Feature Category
CLI commands and flags
Use Case Example
I'm working on a feature that requires multiple rounds of code exploration, implementation, debugging, and testing — all within a single session. The conversation gets compacted 3-4 times as context fills up. At the end, I want to report the total AI-assisted development cost for this feature to my team/manager, but /cost only shows the last segment ($0.38) instead of the real total (~$15+). I have no way to recover the earlier costs.
Additional Context
This is especially important for enterprise/team usage where developers need to track and justify AI tooling costs per feature or sprint
Users on usage-based billing plans need visibility into actual spend to stay within budgets
Long-running sessions (1-3 hours) for complex features almost always trigger multiple compactions, making this a frequent pain point
The data is already being calculated per segment — it just needs to be accumulated rather than discarded
This would also help users make informed decisions about when to start a new session vs. continue an existing one
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗