Backfill
backfill adopts the transcripts Claude Code already keeps on disk (~/.claude/projects/**/<id>.jsonl) as first-class history: sessions from before you installed, or from while the stack was down.
claude-transcripts backfill --dry-run # preview: adopt / skip / repair per session
claude-transcripts backfill # adopt everything not already stored
claude-transcripts backfill --force --session <id> # rebuild one adopted session
claude-transcripts backfill --repair # finish sessions an interrupted write left short
All flags: cli.md.
What it writes
For each session, the same shape a live recording has, delivered through the webapi's /api/ingest/* routes (indexed for search within system.search.flushIntervalMs, 3 min by default, like any other write):
- the
summary:<id>doc, withsource: "backfill"andbackfilled_at; - one
eventdoc per reconstructed hook event; - full-content
chunkdocs (byte-range only with--no-content); - the transcript blob in S3.
Timestamps are the transcript's own, never the time of the backfill. --host and --actor set attribution. Token usage is computed with the same sumTranscriptTokens the hook uses, so counts match a live recording.
Subagents
Subagents are recorded the way the live hook records them: a SubagentStart and a SubagentStop marker each (agent_id, and agent_type when known), plus a PostToolUse / PostToolUseFailure marker for every tool call made inside one, counted into the summary's tool_counts. Backfill finds them in every layout Claude Code has used: <session>/subagents/agent-<id>.jsonl (with its .meta.json), agent-<id>.jsonl beside the session files, and isSidechain lines inside the session transcript itself. An agent-*.jsonl file is never adopted as a session of its own.
What a transcript can't give back:
- marker times are the subagent's first and last transcript line, not the moments the hooks fired;
- a
SubagentStopis written for every subagent found, since a transcript doesn't say whether it finished or was cut off; agent_typeis left out when neither the meta file nor the spawning tool call names it;- sidechain lines with no agent id (older Claude Code) get no markers, because there is no
agent_idto give them. The run says how many there were.
A subagent's own transcript file is not uploaded or chunked; the live hook doesn't store it either. Sidechain lines inside the session transcript are part of it, so they are. Sessions adopted by an older CLI have no subagent markers; --force rebuilds them.
Model switches and directory changes
A PostModelSwitch marker (from_model, to_model) is written where the model that answers the session's main chain changes, and a CwdChanged marker (old_cwd, new_cwd) where its working directory does; each later marker carries the cwd in force then. Subagent lines and Claude Code's own placeholder turns (<synthetic>) are not switches. The summary lists every model as models. What a transcript can't give back: the switch's source and cost estimate, the exact moment (the marker takes the first line that shows the new value), and DirectoryAdded, which leaves no trace in the file. Sessions adopted by an older CLI have none of these; --force rebuilds them.
Re-running
- Default — sessions that already have a summary doc are skipped, so repeat runs are cheap.
- A transcript with no dated entries is always skipped,
--forceor not. Claude Code leaves such files behind, holding only file-history snapshots; they have no start, cwd or turns, so they would make a session no view can place in time. --dry-runreads the store and writes nothing, so the preview shows exactly what a real run would skip. If the webapi is unreachable it says the preview is a guess.--forcere-processes adopted sessions, for example ones adopted with--no-contentor by an older CLI that wrote byte-range-only chunks. It first deletes the session's derived docs (DELETE /api/ingest/{id}): re-ingesting over the top would duplicate event docs (their ids are assigned by CouchDB) and leave old chunks beside new ones (chunk ids are byte offsets). The S3 transcript and the on-disk JSONL are never deleted, so an interrupted--forceis fixed by running it again. Afterwards, runclaude-transcripts reindexto drop search entries for chunks that no longer exist.--replace-live—--forcerefuses live-recorded sessions, whoseend_reason, model, token usage and per-event markers a transcript can't reproduce. Add this flag to rebuild them anyway.--repair— for an adopted session with no readable turns, or whose transcript never reached S3 (a cancelledSessionEnd): adds the missing chunks or blob and leaves the summary and events alone. It refuses running sessions and sessions that already have turns.
reconcile
A session killed or crashed before SessionEnd has its event markers and chunks but no summary:<id>, so it reads as incomplete with no token totals. reconcile writes the summary it never got:
claude-transcripts reconcile # every session that reads as incomplete
claude-transcripts reconcile <id>… [--force] # these sessions; --force also takes a running one
claude-transcripts reconcile --dry-run --json
- Counts (events, prompts, errors, tools) are the session's recorded event markers, the same figures the session list already showed, so they don't move.
- Token usage and transcript size come from the S3 transcript when there is one. Without one (S3 off, or the upload never happened) the summary has no token figures rather than zeros. If S3 is on but doesn't answer, the session fails and is left for the next run, because a summary written without tokens would stay that way.
timestampis the session's last activity andend_reasonisunknown;source: "reconcile"andreconciled_atrecord how and when.- It reads and writes through the webapi (
/api/ingest/summary), and skips sessions that already ended. If a reconciled session is later resumed, its liveSessionEndreplaces the reconciled summary. Between the resume and thatSessionEnd, the session reads asended.
Automatically: the webapi's change follower runs the same command every hour on up to 50 sessions that read as incomplete (system.sessions.reconcile, configuration.md). It needs the CLI beside the webapi; the app image ships it. A session the command fails on isn't retried until the webapi restarts.
Not built
couch/s3power-user passthroughs andmeta postenrichment.