anthropics / anthropics/claude-code

[FEATURE] Show total time and token/cost usage for each finished session

Ouverte
#92,109 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
area:cost enhancement
Langage dominant
Python
Étoiles
145k
Forks
23.1k
Métriques de merge des PR
Métriques de PR en attente

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
cli, desktop
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
Active
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.