claude-measure-usage
A read-only debugger over the Claude
Code session transcripts
in ~/.claude/projects/. It answers the question "where did all those
tokens go?" — across projects, across sessions within a project, across
turns within a session, and down into every spawned subagent, recursively.
It has three front-ends over one analysis engine:
- a Python library, for scripting your own analysis;
- an interactive terminal UI, built with
Textual;
- a
/measure-usage slash command, for checking usage from inside a
live Claude Code session.
Requires Python 3.10+.
Install
pip install claude-measure-usage
That gets you both the library and the claude-measure-usage command
that launches the TUI. If the TUI is all you want, an isolated tool
install keeps it out of your project's dependencies:
uv tool install claude-measure-usage
The slash command installs separately, as a
plugin.
To track unreleased changes, install from a git checkout instead:
uv tool install git+https://github.com/zytedata/claude-measure-usage,
or uv tool install --editable /path/to/claude-measure-usage for
development.
The library
from claude_measure_usage import (
compute_metrics,
find_transcript_path,
format_metrics,
)
path = find_transcript_path("e75ec368-…", cwd="/path/to/project")
metrics = compute_metrics(path, start_ts=0) # 0 = the whole session
print(metrics["total_tokens"]) # raw count, subagents included
print(format_metrics(metrics)) # the same summary the slash command prints
parse_transcript and build_agent_tree give you the raw per-turn rows and
the subagent tree if you want to compute something compute_metrics doesn't.
The TUI

This is the session detail screen — the heart of the app: one row
per assistant turn, with a cost decomposition per turn. The dimmed ↳
rows under turn 1 are subagents — here, two parallel Explore agents
that ran on a different model than the main session; ↵ on one drills
into its own per-turn table. The columns right of what hold the raw
transcript counts (model, in, out, cache_r, cache_w) —
exactly what the API reported, unnormalized. One exception: on rows
marked ≈, the transcript never recorded the turn's final usage, so
out is estimated from content length. On narrow terminals the
table scrolls horizontally with ←/→.
Three kinds of rows share the table:
- Turn rows — one per assistant turn.
↵ opens the turn detail
modal: full text preview, tool calls with their inputs, raw token
counts, and the rigorous own = self + subagents breakdown.
- Subagent rows — dimmed
↳id footnotes under the turn that
spawned them, one row per subagent regardless of its internal size.
↵ drills into a full session-detail screen for that subagent;
nesting can go arbitrarily deep, esc always pops one level.
- Non-turn rows — user messages, attachments, slash commands,
compact boundaries, permission-mode changes.
↵ opens a payload
modal with the full, untruncated content.
Two picker screens lead here — the whole app is a stack (projects →
sessions → session detail → modals) where ↵ drills in and esc
always backs out one level:
Projects — every project directory under ~/.claude/projects/, with
session count and last activity. The cursor starts on the project matching
your current working directory.
Sessions — every transcript in the selected project: start time, turn
count, token usage, peak context, model, and a first-user-message summary.
Transcripts parse in a background worker with a progress bar, so big
projects stay responsive while loading.
Keys
| Key | Action |
|---|
↵ | Open detail modal; on a ↳ subagent row, drill into it |
esc | Back one level (modal → table → sessions → projects) |
s | Cycle sort (natural → took → cost → own → carry → caused); clicking a column header also sorts |
/ | Filter rows by substring on the what column |
i | Session summary overlay (totals, per-tool cost, agent tree) |
r | Reload from disk |
q | Quit |
? | Help with the current screen's bindings |
Sort is glued: subagent footnotes always stay attached below their
spawning turn, and non-turn rows keep their natural transcript position.
Filtering never orphans context — a matching subagent brings its parent
turn along, and vice versa.
Reading the numbers
Sonnet input-equivalent