anthropics / anthropics/claude-code

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

Đang mở
#92,109 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
area:cost enhancement
Ngôn ngữ chính
Python
Star
145k
Fork
23.1k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
cli, desktop
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.