scribe
A deterministic extractor that turns a Claude Code transcript into a structured event log, so session summaries stop being guesswork.
Summarizing a coding session is normally set up as: hand a model the conversation text and ask it what happened. That fails for a reason that has nothing to do with the model. The conversation text is a small and unrepresentative fraction of the session — the tool calls, the commands, the file edits and their results are all in the transcript, and none of them are in the text.
Scribe extracts them first.
The measurement that motivated this
Claude Code writes each session to a JSONL transcript. The pipeline scribe replaces parsed those transcripts by keeping user text and assistant text and skipping everything else. Measured against one real 2.5 MB session:
| Block type |
Count |
Characters |
Fate under the old parser |
| user text |
12 |
1,733 |
kept |
| assistant text |
35 |
32,262 |
kept |
tool_use |
176 |
227,893 |
dropped |
tool_result |
176 |
261,658 |
dropped |
thinking |
96 |
— |
dropped |
33,995 of 523,546 characters — 6.5% — reached the summarizer. The prompt then asked that model to "mention file names, function names, tool names, and concrete outcomes": a category of fact that had been removed from its input. A capable model degrades to filler under that instruction; a smaller one invents plausible file paths. Both look like a model-quality problem, and neither is.
Running scribe over the same session captures all 176 tool events.
Why not just stop dropping the tool blocks
Three reasons, and the extractor addresses all three at once:
| Problem with raw tool bodies |
What scribe does |
| Cost. Full-fidelity tool traffic runs roughly $26/month against a $30 allowance. |
Compresses each call to a name, a bounded argument digest, exit status and the path or command it touched. |
Secrets. Raw tool_result bodies carry docker inspect env blocks and Bearer headers verbatim into a file that then gets indexed. Measured across 429 real transcripts: 8,015 secret-shaped values in 324 of them (76%). |
Redacts at extraction time, and reports a count so you can tell "found nothing" from "did not run". |
| Granularity. Per-turn summarization cannot express a cross-turn finding, because the summarizer never sees two turns at once. |
Emits the whole session as one document. |
What it produces
python -m scribe.extract path/to/transcript.jsonl --json | jq '.stats'
{
"turns": 12,
"tool_events": 176,
"tool_results": 176,
"failures": 4,
"raw_content_chars": 642858,
"extracted_chars": 194667,
"compression_ratio": 0.3032,
"token_estimate": 48667,
"secrets_redacted": 45,
"degradation_level": 1,
"budget_exceeded": false
}
The document is a list of turns. Each turn carries the user's message, the assistant's replies, every tool call as an event, and a rollup — files read, files written, commands run, MCP tools called, failures, tickets, PRs and git refs, all derived in code rather than inferred by a model:
{
"turn_uuid": "9f2c1e4a-…",
"user_text": "Check the release workflow",
"events": [
{"seq": 0, "tool": "Bash", "kind": "bash",
"target": "gh run list --workflow release.yml", "ok": true,
"result_digest": "completed success v0.5.1 …"}
],
"rollup": {
"commands": ["gh run list --workflow release.yml"],
"files_written": ["/repo/CHANGELOG.md"],
"tickets": ["#843"],
"prs": ["TadMSTR/scribe#1"]
}
}
That rollup is what makes a summary checkable. A digest claiming a file was edited can be tested against files_written — deterministically, with no second model involved.
Since 0.18.0 (event-log schema_version 2) the document also records:
entrypoint — sdk-cli for claude -p, sdk-ts for an SDK host, cli for the terminal.
subagents — one entry per Agent call: subagent_type, description, background,
agent_id, status (the result's own, or the background task-notification's), and the
path of the subagent's transcript with whether it existed at extraction. The subagent's
transcript itself is never read.
compactions — one entry per compact boundary: ts, turn_index, trigger,
pre_tokens, post_tokens. The post-compaction recap is still excluded from the text.
background_pending — background tasks launched in the final turn with no
task-notification yet.
queued_input on a turn — a <task-notification> the harness delivered while the
turn was running (a queued_command attachment), counted in stats.queued_commands.
Earlier versions dropped these, so a background subagent's result that arrived mid-turn
never reached the event log.
A version-1 log reads back with subagents, compactions and background_pending as
null — not recorded — never as an empty list, which would claim there were none. A log
with a newer schema_version than the build understands is refused.
Without --json you get a readable rendering of the same thing.
Install
git clone https://github.com/TadMSTR/scribe.git && cd scribe
python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/python -m scribe.extract ~/.claude/projects/*/SESSION.jsonl
The extractor has no runtime dependencies and makes no network calls. That is deliberate and worth keeping: it is the one component that reads raw transcripts, which are the least trustworthy input in the system.
Design commitments
Read-only on transcripts. Scribe never writes to ~/.claude/projects/*/*.jsonl. Those are the only durable record of what happened, and Claude Code already deletes them cleanupPeriodDays after their last write (default 30, configurable). The test suite asserts this on both content and mtime rather than trusting code review.
Redaction is counted, not just applied. secrets_redacted is a number. "No secret appears in the output" is also true of an extractor that produced nothing, so absence alone proves nothing — the count is what shows the filter ran.
Redact before truncating. A digest is a truncation, and truncating first can cut a token in half and leave the leading half. A shorter fragment of a credential is not a safer one.
Tool identity is never discarded. When a session exceeds the byte budget, scribe drops result digests first, then argument digests, then tightens targets — never removing them. A Bash event's target is its command line, the single most valuable fact in the log. If even the floor exceeds the budget, it says so via budget_exceeded rather than shipping a stripped log that looks like a quiet session.
Measured across 429 real transcripts at the default 200,000-character budget: 74% need no degradation at all, the busiest reaches the bottom of the ladder, and 5 exceed the budget on user and assistant text alone.
Options
| Flag |
Default |
Meaning |
--json |
off |
Emit the event log as JSON instead of a readable digest |
--indent N |
compact |
Pretty-print the JSON |
--max-chars N |
200000 |
Byte budget before degradation; 0 disables it |
Exit codes: 0 success (including an empty session, which is a real outcome), 2 the transcript could not be read.
Architecture
Seven components: extract, summarize, writeback, qc, journal, recover, state.
The ordering that matters most is the one in the middle — the event log is written to disk
before the model is called, not after. Everything scribe knows about a session is already
persisted by the time anything can fail, so a crashed or rate-limited run still leaves complete
evidence behind. A pipeline that summarized first and persisted second would lose the session
and the record of it together.
flowchart TD
T["Claude Code transcript<br/>~/.claude/projects/**/*.jsonl"]
E["extract<br/>deterministic, no model"]
L[("event log<br/>eventlogs/session-id.json")]
S["summarize<br/>the only model call"]
Q["qc<br/>grounding gate"]
D[("digest<br/>digests/agent/date.md")]
ST[("state<br/>scribe.sqlite3")]
J["journal"]
R["recover"]
T -->|read-only, never written| E
E --> L
L -->|persisted BEFORE any model call| S
S --> Q
Q -->|grounded| D
Q -->|rejected| ST
E --> ST
L -.->|replays a past session| J
ST -.->|finds lost or provisional digests| R
R -.->|rewrites from the event log| D
classDef store fill:#e8eef7,stroke:#48607f,color:#17212f
class L,D,ST store
Two consequences of that shape are worth naming, because they are what the design buys:
recover can rebuild a digest without the transcript, because the event log is the input to
summarization rather than a by-product of it.
extract is the only component that reads a transcript, and it never writes to one. That is
asserted in the test suite against both content and mtime, not just documented here.
The rest of the pipeline
python -m scribe run # dry run: discover, extract, check. No network.
python -m scribe run --live # live run: also summarize and write
python -m scribe events SESSION_ID # print the event log behind a digest
python -m scribe qc --digest D --events E # exits non-zero on an ungrounded digest
python -m scribe journal # SessionStart hook payload for this agent
python -m scribe recover # report sessions whose digest was never written
python -m scribe recover --apply # reopen them, so the next run redoes them
python -m scribe index --rebuild # regenerate index.jsonl from the digests on disk
python -m scribe index --check # exits non-zero on drift, or on a session with >1 block
python -m scribe session SESSION_ID --brief # everything scribe holds about one session
run defaults to a dry run. It discovers finished sessions, extracts them and reports —
without constructing a provider, reading a credential or calling anything. The mode that
spends money and sends data off the machine has to be asked for by name.
A dry run may observe; it must not process. It writes no digest and no event log, and it
does not advance a session's read offset or mark it summarized, so the live run that follows
still has everything to do (vikunja#902). What it does write is discovery's own record of
what is on disk — a transcript's size and mtime — because an observation says what was seen,
not what was handled (invariant 8). Measured on the live corpus, one sweep touches ~460 such
rows. That is the pass doing its job, not a leak in the guarantee: scribe run earlier said
it wrote nothing, which was never true of discovery and is the claim #902 corrected.
A session is finished once its transcript has been idle past a quiet period, because the Stop
hook fires per turn and there is no session-end signal. That inference can be wrong in one
direction — Claude Code appends to an existing transcript when a session resumes — so state
records how far the file was read, and growth past that offset makes a session live again
regardless of its status.
When the provider is down
A provider outage delays digests; it does not lose them and it does not spend their retry
budget. Each call is still tried 3 times with backoff. If the session's last attempt failed
because the provider did not answer at all, scribe writes no block, touches no state, and leaves
the session pending. "Did not answer" is narrow on purpose: a connection refused or timed out
(ConnectError, ConnectTimeout, PoolTimeout), a connection closed mid-protocol
(RemoteProtocolError), a 429 or a 5xx. Its read offset has not moved, so the next sweep
offers it again. A timeout is not in that list, for httpx or for claude-cli: a slow answer can
be the input's fault, so it spends retry budget like any other failure. An endpoint that
accepts the connection and then never answers is therefore not deferred.
One deferral is a suspicion; two in a row is an outage. The next session is the probe. If
it also finds the provider down, the sweep stops calling the provider, and the remaining
sessions are counted as not attempted and left pending. If the provider answers any session
in the sweep, before or after the deferred one, that session's failure was its own: it is
re-run onto the provisional path, and its retry budget bounds it. That holds when it is the last
or only session too, as long as something else in the sweep got an answer.
One case is not bounded, and it is accepted: two deferrals in a row with nothing answered
before them read as an outage, so the sessions behind them wait. It takes two sessions whose own
requests each make the endpoint refuse, drop or 5xx. Telling that apart from an outage would
need a per-session deferral count in the state DB.
live: 8 session(s), ...
!! provider unavailable: 2 deferred, 6 not attempted -- left pending, no retry budget spent; the next sweep retries them
Everything else spends one of state.MAX_PROVISIONAL_ATTEMPTS, as before, because the
failure can be a property of the input. That covers an unparseable response envelope, a 4xx
other than 429, and a read or write timeout or dropped stream (the provider was reached and was
slow or cut off). A request that could not even be built or encoded fails at once and is not
retried.
There is no fallback provider. A late digest is acceptable; a lost or silent one is not. That
is why the exit code changes:
scribe run exit code |
meaning |
0 |
the sweep ran; any failures are in the output and in the state DB |