anthropics / anthropics/claude-code
[FEATURE] Show total time and token/cost usage for each finished session
- Dominant language
- Python
- Stars
- 145k
- Forks
- 23.1k
- PR merge metrics
- PR metrics pending
Description
## Problem Statement
There is no per-session accounting anywhere in Claude Code. `/usage` reports the active 5-hour block and totals by period, which answers "how much have I used lately" but never "what did *that* session cost".
That gap matters as soon as sessions get long. Two sessions that look the same in the list can differ by an order of magnitude in tokens, because cache reads scale with how large the context has grown and how many turns were taken at that size. Without a per-session figure there is no way to compare two ways of doing the same work, to notice afterwards that one session ate a large share of the weekly allowance, or to tell which part of a workflow is expensive. Measuring it today means parsing the session's own `.jsonl` transcript and summing `message.usage` by request id — which works, but nobody should have to write that script.
## Proposed Solution
When a session ends, show a compact summary for that session:
- total wall-clock time the session ran
- total tokens, ideally split into input / output / cache-creation / cache-read
- the API-equivalent cost of those tokens
Put it in two places: as a line under each finished session in the session list, and at the end of the transcript when the session closes. The single API-equivalent cost figure is the important part; the token breakdown is a bonus.
## Alternative Solutions
Summing `message.usage` from the transcript JSONL, collapsing records by `requestId` so the per-content-block duplicates are not double counted. It gives the right number but requires knowing the transcript format, and it is not available to anyone who is not scripting against it.
`/usage` covers aggregate consumption and is not a substitute: it cannot attribute usage to one session.
## Additional Context
Applies to Claude Code both in the desktop app and in the CLI. With auto-compaction disabled and long-running sessions, the per-session figure is the one number that makes cost decisions possible.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the existing /usage flow, the finished-session list, and the transcript-close path; the issue does not name specific files or entry points. Inspect transcript JSONL message.usage records and requestId handling first. Done means finished sessions show wall-clock time, token totals or breakdown, and API-equivalent cost in both requested locations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, desktop
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100