anthropics / anthropics/claude-code

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

Offen
#92,109 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area:cost enhancement
Vorherrschende Sprache
Python
Sterne
145k
Forks
23.1k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

## 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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
cli, desktop
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.