analyze-claude-sessions
Skill1 starsChanged 5 months agoMITView on GitHub
Analyze your Claude Code sessions for any time window — start, duration, project, message counts, title, token usage, API-equivalent cost, and an A–D cost-efficiency grade — straight from the local transcripts. Use when asked what sessions happened this week/month, where time or usage went, to find a past session, or how to spend less.
- Reads credentials
The file
Files
Analyze Claude Sessions
Answer "what Claude Code sessions did I have this week / last month / in this range — and which were expensive or wasteful?" Claude Code writes every conversation to a JSONL transcript on disk (one file per session); this skill scans those transcripts and reports the sessions that were active in a window — newest first — with each session's start, end, duration, project, message counts, title, token usage, an API-equivalent cost, and a cost-efficiency grade, plus a deep dive into models, tools, skills/MCP invoked, and files edited.
No configuration, no network. It only reads local files under
~/.claude/projects.
Script: scripts/analyze_claude_sessions.py (Python 3.8+, standard library only).
When to Use
- "What Claude sessions did I have this week?" →
list(default window this week) - "My sessions last week with models and token usage?" →
list --period last-week - "Sessions in the myproject repo this month?" →
list --project myproject --period this-month - "Where did my week go across projects?" →
projects --period this-week - "Which sessions were wasteful / how do I spend less?" →
efficiency --period this-week - "Everything between June 1–15?" →
list --start 2026-06-01 --end 2026-06-15 - "Find that session about the calendar work" →
find calendar - "Show me the details of that session" →
show <session-id> - Building a standup / weekly review of your AI-assisted work.
Prerequisites
Python 3.8+ (standard library only). No environment variables required — the
transcript root defaults to ~/.claude/projects. If your transcripts live
elsewhere, override per-run with --projects-dir PATH, or set
CLAUDE_PROJECTS_DIR in the environment (or in ~/.claude/.env, which the skill
reads directly).
Go straight to list / efficiency; run check only to confirm the transcript
root and counts if something looks empty.
Commands
SCRIPT=scripts/analyze_claude_sessions.pycheck — verify the transcript root
python3 $SCRIPT check
python3 $SCRIPT check --json
python3 $SCRIPT check --projects-dir /custom/pathPrints the resolved transcript root, the number of session transcripts, and the
number of project directories. Returns non-zero (and "exists": false in JSON)
if the root isn't found.
list — sessions active in a window (default)
python3 $SCRIPT list # this week, most expensive first — full table
python3 $SCRIPT list --sort recent # newest first instead of by cost
python3 $SCRIPT list --shorten # compact 5-column view (no tokens/cost)
python3 $SCRIPT list --project myproject # only sessions whose project path contains "myproject"
python3 $SCRIPT list --period last-week
python3 $SCRIPT list --days 14
python3 $SCRIPT list --start 2026-06-01 --end 2026-06-15
python3 $SCRIPT list --limit 0 # no cap (show every match)
python3 $SCRIPT list --jsonlist is the default, so python3 $SCRIPT with no args == this week's sessions.
Output is always a table (one row per session), sorted most expensive first
by default — pass --sort recent for newest-first. By default it is the
full table — models, token usage, cost, and efficiency (described below).
Pass --shorten for the compact 5-column view: When, Duration, Prompts
(typed prompts), Project, Title. (--rich is still accepted for backward
compatibility but is now a no-op, since the full table is the default.)
Subagents are folded into their parent. A subagent (Task) conversation is
written to its own agent-*.jsonl transcript whose sessionId points at the
session that spawned it; the skill merges each one's tokens, cost, models, and
tool activity into that parent row (and counts it in the N sub flag) instead of
listing it separately. So a session's row and its show reflect the full cost
of the work it drove, subagents included.
The full table adds six columns to the compact five: Model, Input/Output
(input/output tokens), Cache Read/Write (cache read/write tokens — each split
by /), API Cost (API-equivalent list price, not your bill; a trailing +
means a model in the mix was unpriced), Efficiency (A–D cost-efficiency grade
- rating, followed by any subagent / api-error counts, e.g.
D bloated, 117 sub, 2 err), and Recommendation — the compact cost-reduction levers that apply to that session:/compact(heavy context re-read per turn),/clear(multi-day span),split N% out(only N% of the spend produced output — this lever only fires on sessions costing at least five dollars, since a tiny run naturally reads more context than it writes), orleanwhen nothing trips. A Legend printed under the table spells out every column and lever, so the cells stay short and the table fits the terminal; runshow <id>for the full-sentence recommendation. Output is capped at--limit(default 100, newest first).
efficiency — grade sessions by cost efficiency + suggest habits
python3 $SCRIPT efficiency --period this-week
python3 $SCRIPT efficiency --period this-month --json
python3 $SCRIPT efficiency --project myproject --period last-monthA cost-efficiency audit: every session with usage in the window, ranked by
API-equivalent cost and given a grade A–D (lean → bloated). The grade is
not a judgment of the work — it measures how much of the spend went to
re-shipping context rather than producing output. The primary signal is the
average context re-read per assistant turn (Ctx/turn); a multi-day
wall-clock span drops the grade further, because idle gaps expire 1-hour caches
that then get rewritten at a premium with no reuse. The table shows Ctx/turn
and Cache% (share of cost that was cache read+write) per session, then a
Habits summary consolidating the top fixes across the window.
Why these signals: on a long session, cache-read dominates cost — the whole
growing context is re-sent (and re-billed at the cache-read rate) on every turn.
So the levers are (1) keep sessions short-lived and focused (/compact at
phase boundaries, /clear between unrelated tasks), and (2) do a task in one
sitting rather than dragging it across days.
find — search sessions by title / slug / project (all time)
python3 $SCRIPT find calendar # sessions whose title/slug/project matches "calendar"
python3 $SCRIPT find refactor --project myproject
python3 $SCRIPT find calendar --jsonfind searches every transcript (ignores the time window) and matches the
query, case-insensitively, against each session's title, slug, project path, and
id. It prints each match with its id (feed it to show) and slug, newest
first, capped at --limit (default 50).
projects — one row per project
python3 $SCRIPT projects --period this-week
python3 $SCRIPT projects --period this-month --jsonA compact per-project summary: Project, Sessions, Prompts, In, Out (token totals), and an API-eq column (API-equivalent list price), sorted by session count desc, with a TOTAL row.
show — deep dive on one session
python3 $SCRIPT show 98f902ca-c180-4218-8c91-f3a07080ee35
python3 $SCRIPT show 98f902ca # unique id prefix is enough
python3 $SCRIPT show 98f902ca --jsonFull detail for a single session by id (the transcript filename stem) or a unique prefix: title, project + branch, start/end/duration, prompt & assistant-turn counts, models, the full token breakdown (input / output / cache-read / cache-write), the API-equivalent price, an efficiency verdict (grade + rating, context/turn, cache-vs-output split, and concrete tips), tools used with counts, skills / MCP servers invoked, and the list of files edited.
API-equivalent cost (what it is — and is NOT)
show, list, projects, and efficiency show a $ figure computed from
each session's recorded token usage at Anthropic's published per-model list
prices (per 1M tokens):
| tokens | rate |
| input | model's input price (Opus $5, Sonnet $3, Haiku $1, Fable $10) |
| output | model's output price (Opus $25, Sonnet $15, Haiku $5, Fable $50) |
| cache read | 0.1× the input price |
| cache write (5-min TTL) | 1.25× the input price |
| cache write (1-hour TTL) | 2× the input price |
⚠️ This is NOT your bill. On a subscription plan (Pro / Max) you pay a flat monthly fee and usage does not bill per token — this figure is what the same usage would cost on the pay-as-you-go API. Read it as (a) a relative gauge of which sessions/projects consume the most, and (b) the leverage your plan gives you. Each model is priced at its own rate; a session mixing in an unpriced/unknown model is flagged
[partial]. In practice cache reads dominate long sessions.
Efficiency grade (how it's computed)
efficiency, list, and show grade each session A–D on cost
efficiency. It is derived, not billed, and reads purely from the recorded token
usage:
| Signal | What it measures | Effect on grade |
Context re-read per turn = cache_read ÷ assistant_turns | how big the context is that gets re-sent (and re-billed as cache-read) every turn | primary axis: ≤60k lean → ≤180k moderate → ≤350k heavy → >350k bloated (as a fraction of a 1M window) |
| Wall-clock span = first→last activity | multi-day sessions leave idle gaps that expire 1-hour caches, rewritten at a premium (2× input) with no reuse | ≥2 days drops one grade; ≥5 days drops two |
| Output cost share = output$ ÷ total$ | how much spend produced text vs. carried context | a session with <25% output is flagged (context-heavy) |
The grade rates the session's shape, never the quality of the work. The two levers it surfaces are always the same: keep sessions short-lived/compacted, and do a task in one sitting.
Windows (shared by list / projects / efficiency)
| Flag | Meaning |
--period | today, this-week (default), last-week, this-month, last-month, this-year, last-year |
--days N | the last N days, inclusive of today |
--start / --end | explicit YYYY-MM-DD range (both required, end inclusive) |
--project SUBSTR | only sessions whose project path contains SUBSTR (case-insensitive) |
--projects-dir PATH | transcript root (overrides $CLAUDE_PROJECTS_DIR / the ~/.claude/projects default) |
--sort | (list only) cost (most expensive first, default) or recent (newest first) |
--shorten | (list only) compact 5-column view (default is the full table: models, tokens, cost, efficiency) |
--limit N | (list/find only) max rows to show, newest first (0 = all) |
--json | machine-readable output |
Precedence: --start/--end > --days > --period. Current periods are capped at
today.
How sessions are counted (read before interpreting numbers)
- One transcript file = one session (
~/.claude/projects/<encoded-cwd>/<id>.jsonl), except subagent transcripts (agent-*.jsonl), which are folded into the parent session named by theirsessionIdfield — their tokens/cost/models/tools merge into that parent row and bump itsN subcount. (Note:agent-namerecords inside a normal transcript just re-label that same session as its focus shifts; they are not subagents and are not counted as such.) - Window filter is by activity overlap: a session is included if any of its activity falls inside the window. A long session that spans a week boundary appears in both weeks — intentional ("held during that week").
- Times are local: transcript timestamps are UTC, converted to the machine's local timezone, so "this week" is Monday→today in your clock.
- Prompts counts your typed turns only — tool-result turns, injected
reminders, and slash-command wrappers are excluded. Assistant turns counts
each unique model response (
message.id). Claude Code re-emits the same response across several JSONL lines as it streams — all with the identical finalusage— so the skill de-duplicates bymessage.idbefore summing tokens/cost. Counting every record would roughly double the figures; deduping makes them line up with Claude Code's own/usageper-session totals. - Title prefers a user-set custom title, then the auto-generated AI title, then
the first line of your first real prompt, then
(untitled). - Sessions with no timestamps at all can't be placed in a window and are
skipped; the
listfooter reports how many.
Verification
python3 scripts/analyze_claude_sessions.py check # root + counts
python3 scripts/test_analyze_claude_sessions.py # 57 offline unit testsTests are offline (no network, no real ~/.claude — transcripts are synthesised
in tempdirs) and live next to the script.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

