Source Code:
src/gaia/factory/harvest/What this is
Claude Code writes a full JSONL transcript of every session to~/.claude/projects/
— every prompt, every tool call, every failure, every token spent. This tool turns
that exhaust into an evidence-backed report: what you actually use the agent for,
how often it fails and recovers, and what it costs.
The four core steps are deterministic Python — no LLM calls, no network access, no
dependencies beyond the standard library. Two further steps are optional and do call
a model through your local Claude Code install: classify labels each session’s use
case, and synthesize writes the analysis of the tables. Neither is required, and
neither changes a figure the deterministic steps produced.
Prerequisites
If you can already rungaia commands in this repo, you’re set — the harvest
scripts need nothing beyond the base install (no [dev], [eval], or other
extras). If not, follow the Dev Guide first
(uv venv && uv pip install -e .). The two optional LLM steps need the
Claude Code CLI on your PATH — your existing
subscription, not an API key. Set GAIA_CLAUDE_BIN if it lives somewhere unusual.
Quick start
Never redirect output into the repository. These tables are built from real transcripts — an untrackedtables.md at the repo root is one git add -A away
from being published. Everything below defaults to ~/.gaia/cache/factory/
(created automatically), which lives outside any repo so it can’t get committed
by accident. As a second safety net, this repo’s .gitignore also blocks these
four filenames at its own root, in case you forget $FACTORY and redirect bare.
On Windows, run these in Git Bash (installed alongside Git for Windows),
not PowerShell. This output has em dashes and other non-ASCII characters;
PowerShell’s console encoding silently corrupts them on redirect (
>),
while Git Bash writes clean UTF-8 like macOS/Linux.1
Extract — deterministic, no LLM, no network
Roughly linear in transcript count. Writes
traces.jsonl, intents.jsonl, and
stats.json into $FACTORY.2
Tables — absolute counts and share-of-total for every figure
3
Context — per-request prompt size and local KV-cache memory
Re-reads the raw transcripts, because With use-case labels:
scan/report aggregate per session and
that hides how large any single request got.4
Savings — what a proposed fix would actually save
In tokens and dollars.
5
Label use cases — optional, needs Claude Code
Writes
labels.txt, which unlocks the “by use case” sections. Re-run report
and context with --labels afterwards.6
Analysis — optional, needs Claude Code
The written findings the tables do not state on their own.
scan fails loudly and tells you which directory it searched
instead of silently reporting zero — that’s expected on a machine that has never
run Claude Code.
Flags
--root relocates the scan, it does not narrow it. The path it takes is the
directory holding your projects — sessions are read as <root>/<project>/*.jsonl
— so pointing it at one project directory matches nothing and exits with the
“no sessions found” error. There is no supported way to scan a single project.
Output files
The frozen request snapshot
context and savings measure every individual API request, which is expensive
and — because the corpus grows while you work — gives a different answer every
run. So the first context run freezes its measurement into requests.json and
both reports reuse it, which is what makes a published median reproducible.
Once the corpus changes under that snapshot — new sessions, or ones already in it
that have since grown — both refuse to run rather than narrate figures that
disagree with tables.md:
traces.jsonl recorded inside
requests.json, so re-running scan and finding nothing new does not trip
it — scan rewrites that file on every run regardless. A snapshot frozen before
this fingerprint existed has none to compare, so it falls back to file timestamps
and may ask you to choose after a no-op rescan; --refresh once re-freezes it
with a fingerprint.
Both outputs carry a line naming the snapshot they were measured on — timestamped
in UTC — so a report always says which corpus it describes.
Classifying intent
Optional — the reports above already work without this; it only adds a “by use case” breakdown.scan produces intents.jsonl but assigns no use-case label. classify does
that step against a closed taxonomy, in batches, and writes labels.txt:
no_instruction locally,
without a model call, because “unclassifiable” is a fact about the transcript
rather than a judgement. A batch whose labels don’t cover it exactly is an
error, and nothing is written until every batch has validated — a partial
labels.txt silently shrinks the population every use-case table is drawn over.
Sessions are classified from the first user message, not the auto-generated
session title — the title summarizes what happened, which leaks the outcome
into the label.
To label by hand instead, write $FACTORY/labels.txt as
<8-char-session-prefix> <use-case>, one per line. It carries session-id
prefixes, so it stays in the cache directory, never in a repo.
Prefixes are checked against the corpus. A file where nothing matches stops the
run rather than rendering an empty table, and a partially-matched file prints how
many sessions it covers — on stderr and inside each use-case table — so the
labelled subset is never mistaken for the whole corpus.
Writing the analysis
Optional, and the second of the two steps that call a model. The tables are evidence, not a report: nothing in them ranks what matters or connects two sections.synthesize does that, reading only what the other
steps already wrote:
Things that will mislead you if you skip them
- Subagents are not sessions. A delegated
Task/Agentrun gets its own transcript under<session-uuid>/subagents/. Say explicitly which scope a number covers (main session only, or including subagents). - There is no ground truth for task success. Nothing in a transcript says whether the goal was actually met — never present a tool-failure rate as a task-failure rate.
- Friction signals are proxies, not proof. Corrections and interrupts are evidence of friction, not confirmation of it.
- Cost is API-equivalent, not money spent, if the sessions ran on a subscription rather than metered API usage.
- Duration is unusable past the median. A session left open overnight reports the whole night as active time.
- The corpus grows while you analyze it. The session doing the analysis is itself being recorded. Timestamp the snapshot you’re reporting on.
Privacy
By default,scan covers every Claude Code project on your machine — not just
this repo — because ~/.claude/projects/ holds one subdirectory per project you’ve
ever used Claude Code in, and there’s no per-project filter. tables.md doesn’t
break the count down by project; check the top_projects field in stats.json if
you want to see the mix before sharing anything.
Transcripts contain absolute paths, branch names, repository content, and anything
pasted into a prompt. The pipeline writes only to ~/.gaia/cache/factory/. If a
report needs to be shared, put it somewhere private and scrub paths first — nothing
derived from a corpus belongs in a public repository or a GitHub comment.
The four deterministic steps never leave the machine. The two optional ones do:
classify sends the opening instruction of every session, and synthesize sends
the rendered tables. Both go to the same Claude Code install you already use and
nowhere else, but if your opening instructions are sensitive, label by hand
instead.
Driving this from Claude Code
If you want Claude Code itself to run this pipeline, review the output, and produce a written report, use theanalyzing-claude-sessions skill
(.claude/skills/analyzing-claude-sessions/SKILL.md) — it carries the same
commands above plus guidance on what to actually report and how to verify the
analysis before publishing it.
Roadmap
The current pipeline covers extraction and reporting only. A broader design — turning harvested sessions into eval scenarios and distilled skills for local models — is proposed but not implemented indocs/plans/claude-session-harvest.md.
Nothing on this page depends on that plan landing.