anthropics / anthropics/claude-code
[FEATURE] Show total time and token/cost usage for each finished session
- Lenguaje dominante
- Python
- Estrellas
- 145k
- Forks
- 23.1k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
## 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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- cli, desktop
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100