Skip to content

Application Model

claude-code-log reads Claude Code transcript files (JSONL on disk) and produces readable HTML, Markdown, and structured JSON views, with optional caching, a TUI for navigation, and per-project aggregate pages.

This document is the entry point for dev-docs/: a high-level view of the parts, what each does, and where to read about them in detail. For end-user documentation see the project README.md; for contributor onboarding see CONTRIBUTING.md; for user-facing operations docs see docs/.


1. Subsystems at a glance

Subsystem Owner module(s) Deep-dive
CLI cli.py inlined below (§ 2.1)
TUI tui.py inlined below (§ 2.2)
Cache (SQLite) cache.py + migrations/ inlined below (§ 2.3); user-facing in docs/restoring-archived-sessions.md
Migrations migrations/ + migrations/runner.py inlined below (§ 2.4)
Parsing parser.py, factories/ rendering-architecture.md § 3
Message taxonomy models.py messages.md
DAG (sessions, forks, agents) dag.py dag.md
Sync sub-agents (#79) converter.py, factories/agent_metadata_factory.py agents.md § 1
Async task agents (#90) converter.py, factories/task_notification_factory.py agents.md § 2
Teammates (#91) renderer.py, factories/teammate_factory.py, html/teammate_formatter.py teammates.md
Dynamic workflows (#174) workflow.py, converter.py, renderer.py workflows.md
Rendering pipeline renderer.py, html/, markdown/, json/ rendering-architecture.md
Themes (classic, minimal) cli._resolve_theme, utils.DEFAULT_THEME, html/renderer.py (theme, generator stamp), html/minimal_theme.py, transcript.html ({% if minimal %} branches), html/templates/components/minimal/ option and staleness below (§ 2.1); the minimal theme's as-built reference starts at minimal-theme.md (map of its parts in § 0); user guide docs/themes.md
Branch lanes (minimal theme's DAG data) lanes.py (model), html/minimal_theme.py (data-* attributes) agents.md § 6, dag.md § Branch lanes; attribute schema in minimal-theme.md § 12
Minimal theme's DAG engine (branch modes, rail) html/templates/components/minimal/minimal_dag.js, dag.css minimal-theme.md
Fold-bar / message hierarchy html/templates/components/, JS in transcript.html message-hierarchy.md
CSS class taxonomy html/templates/components/*.css css-classes.md
JSON export (#36) json/ inlined below (§ 2.5)
Depth filter renderer.py § Depth filtering, models.RenderingDepth inlined below (§ 2.6)
Image export image_export.py, image_store.py inlined below (§ 2.7)
Performance profiling renderer_timings.py inlined below (§ 2.8)
Markdown engine (wenmode) markdown_plugins.py, html/utils.py, markdown/renderer.py inlined below (§ 2.17)
Intra-project render fan-out render_pool.py (mechanism) + render_dispatch.py (policy) inlined below (§ 2.10)
Diagnosing hangs (SIGUSR1) cli.py _install_stack_dump_signal inlined below (§ 2.11)
Watch mode / live page updates watch.py, html/templates/components/live_update.js inlined below (§ 2.15); design in work/watch-mode.md; user-facing in docs/live-updates.md
Recent sessions page (recent.html) recent.py (data), converter._write_recent_page, cli.watch (refresh), html/templates/recent.html + components/recent/ inlined below (§ 2.18); user-facing in docs/recent-sessions.md
Adding a new tool renderer factories/tool_factory.py, html/tool_formatters.py implementing-a-tool-renderer.md (how-to)
Which tools have a specialized renderer or provider adapter TOOL_INPUT_MODELS / TOOL_OUTPUT_PARSERS in factories/tool_factory.py, plus provider adapters tools-coverage.md (Claude and Codex status vs. upstream references)
Plugin system (third-party message transformers) plugins.py, factories/priorities.py, Renderer._dispatch_format plugins.md

A note on cross-cutting concerns: some behaviour spans several rows of the table above and isn't owned by any single subsystem. Label and preview composition (session header titles, branch labels, fork-point box captions) is the most common one — it touches the DAG layer (which decides what's a branch), the renderer's session machinery (which assembles the label text), and the parsing layer (which feeds the preview source). See the SessionHeaderMessage entry in § 4 for the function-level surface.


2. Subsystems without their own deep-dive

The subsystems above with "inlined below" pointers don't have a dedicated dev-doc — the paragraph here is the canonical reference.

2.1 CLI

cli.py is the command-line entry point (claude-code-log) built on Click. The default invocation processes the entire ~/.claude/projects/ hierarchy; explicit paths target a single transcript or directory. Major flags:

  • --tui — launch the interactive TUI (§ 2.2).
  • --depth {session,user,assistant,agent,tool,hook} (default tool) — how deep into the message hierarchy to render (§ 2.6). Legacy --detail {full,high,low,minimal,user-only} is a deprecated alias.
  • --from-date "yesterday", --to-date "today" — natural-language date filtering via dateparser.
  • --open-browser — open the generated index.html after rendering.
  • --no-cache / --update-cache — bypass or force-refresh the SQLite cache (§ 2.3).
  • --format {html,md,markdown,json} — switch output format (HTML is the default; Markdown is mainly used for sharing transcripts inline; JSON exports the processed tree for downstream tooling — see § 2.5).
  • --compact — Markdown-only; suppresses repeated headings.
  • --page-size N — paginate the combined-transcript HTML/Markdown output, packing whole sessions into pages of up to N messages each (sessions are never split across pages, so individual pages may overflow). Per-session HTML files are not paginated.
  • --jobs N / -j N — worker processes for the all-projects conversion phase (default: CPU count; 1 disables parallelism). Also caps the per-project render fan-out, which is opt-in via $CLAUDE_CODE_LOG_RENDER_JOBS (§ 2.10).
  • --theme {classic,minimal,default} — HTML theme (also on serve and watch, and passed to the TUI for its HTML exports). default is the built-in default, resolved through utils.DEFAULT_THEME (currently classic); precedence is flag > $CLAUDE_CODE_LOG_THEME > built-in default, and an unknown environment value is a usage error (cli._resolve_theme). Only resolved names (classic/minimal) are ever rendered or stamped. HTML-only: Markdown/JSON warn on an explicit flag and render as before. The minimal page layers its own stylesheets and a sticky toolbar over the classic markup, with light/dark following prefers-color-scheme or an in-page toggle — see rendering-architecture.md § 8, css-classes.md § Minimal Theme and minimal-theme.md (the theme's entry point); the user guide is docs/themes.md.

CLI orchestration delegates to converter.py (which owns the high-level "load + render + write" flow) and never touches renderer.py directly. Output paths follow a stable convention so the cache and re-renders can find existing files: combined_transcripts.html, session-{id}.html, index.html, with --depth and --compact adding suffixes per utils.variant_suffix.

--theme deliberately adds no suffix: a theme overwrites the same files. What tells the themes apart is the generator comment on line 2 of every page, which the staleness checks already read: <!-- Generated by claude-code-log v1.2.3 --> for classic (the same stamp classic pages carried before themes existed) and <!-- Generated by claude-code-log v1.2.3 theme=minimal --> otherwise (html/renderer.py::html_generator_stamp). HtmlRenderer.is_outdated, is_html_outdated(path, theme) and the cache's is_transcript_stale / get_stale_sessions / is_page_stale all compare the stamp against the theme a page rendered now would carry, so a page from the other theme reports file_version_mismatch on every path — single-file, paginated, streaming (§ 2.13), session-scoped (§ 2.12), render pool (§ 2.10), the all-projects plan, watch/serve. Cache rows (html_cache, html_pages) are shared between themes and need no theme column. One promotion keeps archives single-themed and current: a --combined no run whose combined output carries the other theme, or another library version's stamp, rewrites it once (converter.combined_output_outdated), because its session pages link back to it. Without it, an upgrade would leave the combined pages in the old rendering for as long as only watch or serve --watch ran. The project index and the archive search page are rewritten on every run and decide nothing from their stamp; they are rendered in the run's theme on every path that writes them (the all-projects run and so serve, its --watch ticks and watch --all-projects, and the provider hierarchy; the TUI writes neither) and stamped like the other pages (minimal-theme.md § 13).

For the all-projects invocation, process_projects_hierarchy runs in three phases: plan (sequential, cheap — per-project staleness via cache mtimes, also ensures DB schema/migrations exist), execute (stale projects fan out over a ProcessPoolExecutor with the spawn start method, largest-first; rendering is CPU-bound pure Python and projects are independent, so this scales near-linearly with cores; when the per-project render fan-out is enabled, any budget left over after one worker per stale project is handed to it, § 2.10), and collect (sequential — per-project index data is read back from the cache and the cross-project index.html is written last). Under --from-date / --to-date the pass writes a view of the window, and a window phase runs between plan and execute: each project's cache is refreshed in the parent, serially, and the window is read from it (_project_window_view). window_session_ids (a trunk session with a message in the window, among the sessions the index lists) is the one reading of it: it decides the session pages the conversion writes (the workers get the set, so a session started meanwhile waits for the next run), the sessions the index links, and the pages the destination may not already hold. That check (_window_view_files: the index pages, each shown project's combined page and its window's session pages, not the vendored assets) runs before anything is written and raises WindowOutputExists unless the run is forced; nothing is ever removed. A project the window shows nothing of is not converted, is counted as having no messages in the window and is left out of the index, which gives each listed project the window's totals; archived projects are left out too. Workers run silent; the parent prints one progress line per converted project as results arrive, after a single line counting the projects it had nothing to do for (cached, or with no messages in the window). All workers share the WAL-mode SQLite cache DB — each writes only its own project's rows, and WAL serialises the short write transactions. Serialised is not the same as fair, though. SQLite does not queue writers: one that finds the lock taken polls with a growing back-off, and whoever is awake when it frees takes it, so a worker that has just committed tends to win again. Measured with eight processes doing back-to-back short write transactions for 20 s, the worst-off waited the full 20 s for a single turn — no long transaction required — and issue

332 lost 23 of 57 projects to database is locked this way. (A plain

cross-process mutex is no better: the releaser re-acquires before a woken waiter runs.) So the pool shares one fair write queue (write_queue.py): a ticket lock the parent creates and each project worker installs as the pool's initializer. Every cache write goes through cache.write_transaction, which takes a turn, opens BEGIN IMMEDIATE, writes and commits. The same measurement under it gave every worker 90-91 transactions and a worst wait of 0.41 s. Inside a pass, then, no worker gives up on a sibling; the busy timeout (30 s, $CLAUDE_CODE_LOG_CACHE_TIMEOUT) only bites while a turn holder waits on a writer in another process (a TUI, a second serve). For that case a locked-out project is deferred, not failed: it prints cache busy, will retry and is converted again inline after the pool and the held-back projects have finished. Only a second lock-out is reported as a failure. Outside a pool no queue is installed and the turn is free. A worker that dies holding its turn (an OOM kill) leaves its siblings queued behind it, and ProcessPoolExecutor can miss that death under spawn — it starts workers on demand, and its manager thread may be waiting on a sentinel list that predates the dead one (reproduced on CPython 3.11: dead worker, exit code set, pool reporting healthy), so it only notices when another result arrives, which here is never. The pool is therefore drained through write_queue.as_completed_watching_workers, which checks the workers itself between results and, on any abrupt exit, terminates the rest and raises BrokenProcessPool into the inline fallback. The parent never installs a queue, so that fallback cannot meet the stuck one. test_write_queue.py pins it. Uncontended, the queue plus BEGIN IMMEDIATE add ~10 µs to the smallest write (update_html_cache, 46 → 56 µs) and nothing measurable to a session save; whole passes are unchanged at --jobs 1 and within ~4% on a pooled incremental pass, the price of strict turn-taking. The queue makes waiting safe; it does not shorten the holds, and the longest thing a worker did while holding the lock was not the row insert but maintaining the search index: save_cached_entries called search.reindex_files inside its write transaction, so once an index exists every rewritten file was decompressed and tokenised under the lock (3.4 s of an 11.2 s save on the largest session measured, 122 MB / 46k entries), in every worker, with the rest of the pool queued behind it. So a hierarchy pass defers index maintenance (search.deferred_index_maintenance in the parent, search.defer_index_maintenance in the pool initializer _init_project_worker): the entry writes leave the index alone, and after _process_projects_hierarchy returns — pool exited, hold-backs and retries done — cache.catch_up_search_index re-indexes the files whose cached_files.cached_mtime moved, one short transaction per file on the pass's leased connection, before the WAL checkpoint. What this buys is shorter holds, not a shorter pass: on 32 large projects (9 GB, 3,201 transcripts all touched, index present, --jobs 16) the parallel phase went from 555 s to 230 s and the longest save_cached_entries from 44.8 s to 15.2 s (p90 6.8 s → 2.8 s), but the serial catch-up then took ~305 s, so the whole run was 555 s against 536 s. The tokenising is the same work wherever it lands; in the workers it was paid under the lock, and a hold that long is what pushes a writer in another process (the TUI, a second serve) past its 30 s budget. On the daily shape — a handful of files changed — the catch-up is seconds. Parallelising it (extract in workers, insert in the parent) is the open lever if that worst case ever matters. A single file or directory conversion (convert_jsonl_to with no pass around it) still re-indexes inside the write, where nothing competes for the lock. CLAUDE_CODE_LOG_SEARCH_AUTO_INDEX=0 switches both off. The queue is per pass, so two passes over one cache — a second CLI run, or a serve --watch tick while a CLI run refreshes the same archive — are, to each other, one tight-loop writer each, and the unfair polling above applies between them (it is also the realistic way two refreshes of one project overlap; each commits whole, § 2.3, so the later one wins and the next pass repairs what it lost). So process_projects_hierarchy first takes the pass lock (pass_lock.py): an exclusive transaction on a sidecar SQLite file beside the cache (<cache>.pass-lock), held around the WAL trim, the conversions, the index catch-up and the checkpoint, and released with the holder's process (nothing stale to clean after a kill). A second pass waits, announces what it is waiting for after 2 s, then runs and usually finds the work done; CLAUDE_CODE_LOG_PASS_LOCK=<seconds> bounds the wait (then PassLockTimeout, nothing converted) and =0 disables the lock. Re-entrant within a process (process-wide, not per thread), though nothing nests today: serve finishes its startup pass before its watch thread ticks. The lock is keyed on the resolved cache path, so a symlinked cache shares it. It degrades rather than fails: a lock file that cannot be created (read-only directory), is not SQLite (junk), or cannot be written (another user's; a read-only BEGIN EXCLUSIVE excludes nobody, which one rolled-back write inside the transaction makes surface) is announced by name and the pass runs without the lock. Outside the gate, by design: the TUI's writes and a single-file convert_jsonl_to are short transactions with the ordinary busy timeout, as before. test_pass_lock.py pins the waiting, the bound, the switch, the three degrade cases, the symlink, two concurrent passes serialising, and that the lock is held through the WAL trim, the index catch-up and the checkpoint (pass_lock.pass_lock_held, recorded from inside each). Measured on the 32 largest projects of a real archive (every file re-saved, two passes started together at --jobs 8): without the lock each pass took ~872 s and the pair re-saved 1.4x the files; with it the first ran alone in 552 s and the second, after waiting, found every project current in 0.2 s. serve takes the same --jobs as the main command. A pool-level failure (e.g. a library caller without the if __name__ == "__main__" guard spawn needs) degrades to inline sequential processing with a warning rather than aborting.

2.2 TUI

tui.py is a Textual application that browses the projects index, drills into individual sessions, and exposes quick actions: render session to HTML, resume a session via claude --resume, archive a session (move to cache-only), and so on.

Architecture is straightforward Textual: a few Screen subclasses, a DataTable for the session list, key bindings dispatched through Textual's BINDINGS mechanism. The TUI reads through cache.py exclusively (never re-parses JSONL itself) — opening a 50-project hierarchy takes milliseconds because cache hydration is incremental.

HTML exports honour --theme / $CLAUDE_CODE_LOG_THEME (§ 2.1): run_session_browser(..., theme=) hands it to SessionBrowser as html_theme (not theme, which is Textual's own UI theme), and _ensure_session_file renders with it — regenerating a session page left in the other theme, under the same session-{id}.html name. Before it renders a live session, _ensure_session_file refreshes the cache (ensure_fresh_cache), then renders what that refresh committed (§ 2.3): the cache the TUI read at start may predate the session's newest lines.

The "archive" action is interesting: it moves a session's source JSONL out of ~/.claude/projects/ while keeping the cache row intact. The session then renders from cache only. See docs/restoring-archived-sessions.md for the user-facing behaviour and recovery flow.

2.3 Cache (SQLite)

cache.py maintains a SQLite database at ~/.claude/projects/claude-code-log-cache.db (or $CLAUDE_CODE_LOG_CACHE_PATH). Stored data:

  • Per-session: id, summary, first/last timestamps, message count, per-role token totals, team_name (added in migration 005).
  • Per-message: a denormalised view used by archived-session restoration (the cache holds enough to re-render even after the source JSONL is deleted). Each row's content is the entry as zlib-compressed JSON, written at CONTENT_COMPRESSION_LEVEL (3, not zlib's default 6: levels only diverge on large payloads, so across a real 18,288-row archive it costs 2.6% more bytes and makes a cold conversion 11% faster — compressing rows is the largest item in a watch tick). Reading is level-agnostic, so rows written at any level still load.
  • Per-image (migration 017): each distinct image an entry carries (a pasted image, a tool result's: mostly Read screenshots) is stored once, as raw bytes, in image_blobs, keyed by a BLAKE2b-128 digest (cache_images.py). Entries hold each image as a reference from the parse on (§ 2.7), so the row's JSON holds {"type": "ref", "digest": …, "media_type": …} and messages.image_refs lists the digests as a JSON array. Reading a row leaves the reference as it is: _entries_for_file only checks, in one query, that the cache still holds every blob the batch references, and export_session_to_jsonl, whose lines leave the cache, puts the base64 back. A source swaps only when it is exact: no other key, base64 that re-encodes to the same text, and at least 2 KB of it; any other stays inline. Blobs are written in the transaction of the rows that reference them, from the bytes the process holds (a reference whose bytes it no longer holds names a blob a cache already has), and those bytes are released from memory once it commits. A refresh spools them with its rows (refresh_spool.py has its own image_blobs) and its merge copies each file's blobs before its rows (cache_images.MERGE_BLOBS, through the rows' own image_refs and json_each, which check_json1 makes sure of at migration), and the overlay a refresh reads through has an image_blobs view too. Blobs outlive their rows when a file is rewritten or deleted: at the end of an all-projects pass, under the pass lock, sweep_image_blobs marks the blobs no row references, unmarks those referenced again, and deletes those marked for over an hour. A reader that still misses one (it would have to hold its rows for that hour) reads the file as not cached and parses it again; the render's snapshot read (load_snapshot_entries), which may not parse again, and an archived session, with no transcript to parse, show a placeholder for that image and keep the rest. Identical bytes under two media types share a blob; each reference keeps its own media type. On the archive measured in #416 this took the cache from 4.13 GB to 3.46 GB (3,881 distinct images, 1.03 GB raw, referenced from 5,980 rows); _CONTENT_SCHEMA_SALT 3 re-parses older caches once.
  • Per-rendered-HTML: the HTML output itself, indexed by source file mtime + depth + compact flag (migrations 002–004) — so re-runs with unchanged inputs serve the cached HTML directly.
  • Cross-session sidecar (migration 008): compact projections of a full load's SessionTree — per-session parent linkage, junction points, and cross-session dedup winners — persisted so the session-scoped incremental path (§ 2.12) can regenerate one stale session without loading the project. Rewritten wholesale on every full directory load, inside the same batch as the per-file writes, so it is exactly as fresh as cached_files.

Invalidation is mtime-based: when a JSONL's mtime is newer than its cache row, the session is reparsed. The schema-version row also invalidates the entire HTML cache when migrations bump the version, since rendered output may have changed even when source data hasn't.

A date-filtered run is not recorded as complete. The cache describes the source files, whatever window a run renders: ensure_fresh_cache takes no date range, so a --from-date / --to-date run refreshes exactly as an unfiltered one would (nothing when no file changed, the incremental refresh when it can, otherwise a full unfiltered load), and the window applies only to the entries it renders. The trade, accepted: when files changed and the incremental refresh declines, a filtered run's refresh holds whole files, where it used to hold only their entries inside the window; in exchange a filtered run over unchanged files no longer pays a refresh at all, where it used to pay a full load on every run. The files it writes hold only the window's messages, so no count describes them: instead of recording one, mark_rendered_from_window sets the count of each file's html_cache row (and of page 1's html_pages row, which shares the combined file's name) to -1, which no session or project matches, so the next unfiltered run re-renders it. Only a view written in place does: the rows are keyed by project and file name, so a view written to another directory touches none, and the full view's pages stay current. The rows stay, so a paginated project keeps its page count. JSON output has no html_cache row and goes by its own version field; a JSON file written from a window carries the window as date_range, and JsonRenderer.is_outdated reads such a file as outdated. The cache's pre-filter (load_cached_entries_filtered) and the renderer's cut (filter_messages_by_date) read a bound through one function, utils.parse_date_bounds, in UTC: a bound naming a whole day (today, N day(s) ago, in any case, or a date without a time) covers that day, while now, 2 hours ago or any explicit time, midnight included, is an instant.

A refresh commits whole or not at all. A refresh writes each transcript file's entry rows, then the session rows, project aggregates and cross-session sidecar (§ 2.12) derived from them. Staleness reads both halves: a file is modified when its cached_files row is older than the file, and a rendered session is stale when its sessions row disagrees with the html_cache row of its last render. When each of those writes was a transaction of its own, a refresh that stopped in between (a write lost to database is locked, issue #332, or a kill) left the files current and the session rows as old as the renders, and every later run reported the project as cached while its renders lacked the new messages; migration 015's refresh_pending flag carried such a failure to the next run, with a limit (two processes refreshing one project could clear each other's) and special rules of its own. Now, over a project the cache already holds, ensure_fresh_cache_detailed runs either path inside CacheManager.atomic_refresh(): while the refresh parses, each file's rows go to a private spool file beside the cache (<cache>.spool-<pid>-<n>, refresh_spool.py; journal in memory, nothing synced, this process's own), with no shared lock held and the CPU work of serialising where it was; the derived writes are deferred; and the scope's end attaches the spool, copies each file's rows in with INSERT … SELECT (no Python per row under the lock, and less time than the direct executemany took), runs the deferred writes, and commits, in one write transaction or one per file (below). A refresh whose single transaction stops leaves the cache as it was and the spool is removed; the next run, or the pass's in-pass retry, redoes it, re-parsing the modified files. Only a process killed mid-parse leaves a spool behind, and a pass removes the spools of dead processes before it starts, under its lock. A reader on another connection sees either the whole refresh or none of it. Inside the scope, two TEMP views named cached_files and messages shadow the tables for every read on the scope's connection (the table minus the rows the spooled files replace, UNION ALL the spool's rows), because the incremental refresh (§ 2.14) reads back the rows it has just written; a write through them fails, which is the point. A sidecar write that fails at the merge for a reason other than contention rolls back to a savepoint and drops the sidecar_state marker (as abandon_session_sidecar does for a direct write), so readers fall back to the full load until a refresh writes it afresh; contention fails the refresh, to be redone. Migration 016 dropped the flag and kept 015's one-time heal: a project it still marked gets its message total zeroed, which the next run reads as a cache to refresh in full, from the cached entries.

How the merge commits, and the cold build. One transaction holds the write lock for the sum of what each file's rows cost to insert, most of it the ten messages indexes maintained in random key order (a cold merge of 191k rows: 0.84 s to copy, about 6 s with the indexes, 1 s to commit); per file, the longest hold is the largest file's. So _merge_refresh merges in one transaction while the spooled content beyond the largest file's is at most ATOMIC_MERGE_MAX_EXTRA_BYTES (16 MB, about half a second of extra hold; CLAUDE_CODE_LOG_ATOMIC_MERGE_MB overrides it, 0 meaning per file whenever more than one file is spooled), which keeps a watch tick and a small daily delta atomic at no cost. Past it, _merge_per_file commits per file between two more transactions: the first marks the project unfinished by zeroing its message total (016's heal: the next run refreshes it in full, from the cached entries), and the last writes the derived rows, whose aggregates lift the mark, but only if no file moved (below). Either way the merge runs with a 64 MB page cache (MERGE_CACHE_SIZE_KIB; SQLite's default is 2 MB, which the indexes thrash: 6.1 s against 3.4 s for the copy above), set for the merge and given back, so no long-lived writing connection keeps it. A cold build, of a project with no cached file (a new project, or one whose rows a version change discarded), takes no spool (CacheManager.cold_build): there are no derived rows to fall out of step with, and the project's total is 0 until the aggregates, the refresh's last write, so a build that stops reads as unfinished and the next run completes it. Its files commit one by one as they are parsed, which keeps a large project's first build to its largest file's hold and adds no spool to its disk.

Two refreshes of one project overlapping. Only a hierarchy pass holds the pass lock; a single-project convert, watch <dir>, a single-session file or the TUI's export refresh beside it. A file a refresh parsed it writes with the record of that parse, so if another refresh committed a newer one in between, the file reads modified and the next run reparses it. A file it took from the cache it does not write, and if the other rewrote that one before this refresh's derived rows landed, those rows (an incremental refresh's total included, which it computes as a delta over the total it read) would describe the rows the other replaced, under a record that reads current, and nothing would recompute them. So both scopes read every file record of the project as they open, after the modified-file gate (which only decides whether to refresh: a commit before the snapshot is one the scope's reads see) and before any read the derived rows come from, and write the derived rows only if every file still carries its record: the one the refresh left on the files it wrote (none to compare in the one-transaction merge, which writes them in the same transaction), the one in the snapshot on every other, a file on one side only counting as moved (_moved_files). Otherwise the derived rows are not written and the project's total is left at 0, so the next run refreshes it in full from what the cache then holds; the one-transaction merge still commits the rows it spooled. A commit after the snapshot that the refresh's reads did see trips the check as well; it costs that one full refresh. A file parsed from an entry_store hit is no exception: the store stamps its entries with the source file's size and mtime, so a hit is never older than the disk.

A run renders what its refresh committed. Only the refresh writes entry rows; the render reads them and writes none. A session file can grow between the two, since sessions are written to while a run converts them. The render used to find that file's rows stale, parse it again and write its rows itself, stamped with the file's new size and mtime, while the session rows and aggregates kept the refresh's counts. The run's pages then showed lines its session rows did not count, and the cache called the file current, so only refresh_pending (above) made the next run look at it again. Now every render-side load passes snapshot=True to load_transcript, through load_directory_transcripts and _load_sessions_partial: Phase 1b (§ 2.12), the streaming page loads (§ 2.13), Phase 2, generate_single_session_file and the TUI's export. In that mode the loader serves CacheManager.load_snapshot_entries, the rows the cache holds at the current content version whatever the file's stamp says now, or a parsed-entry store hit (§ 2.16), which is verified against the file and so describes the same rows. It never parses the file and never writes the cache. A file with no rows yet (created after the refresh) is skipped. Lines that land after the refresh are the next refresh's: that run finds the file modified, as nothing restamped it. --no-cache and single-file mode have no rows and parse as before. The hierarchy's no-cache-data fallback and Codex's wholesale render load and write their rows and session rows from one load, so they keep doing both. The TUI refreshes right before it exports a session, because the cache it would otherwise render may date from its start. test/test_render_snapshot.py grows a file right after the refresh, on each of these paths.

Corruption is recovered by discarding, not repairing. A damaged cache file is unusable and, left alone, permanently so: apply_migration records only a migration that completed, so a CREATE INDEX that hits a damaged page re-fails on every subsequent run. The writing CacheManager.__init__ therefore catches SQLite's corruption errors (is_corrupt_database_error — narrowly matched on message text, since Python funnels "malformed", "not a database", "locked" and "disk full" into the same exception classes), deletes the .db with its -wal/-shm sidecars, and rebuilds. Everything in the cache is regenerable from the JSONL source, so the cost is one slow run.

Two boundaries matter. A read_only manager — every spawned render worker (§ 2.10) — never deletes: several run concurrently against one file, and _lookup_project_id already degrades to "no cached data". And a zero-byte file is not corruption; SQLite adopts one as a new database, so an interrupted create heals without intervention.

Note the cause is usually outside this tool. The case this was built for was a cache truncated to 2833 pages while its own header still claimed 14189 — traced to the virtiofs mount it lived on, not to anything the writer did. It had also been corrupt for some time before it was noticed: migration 012's index build is the first operation that full-scans messages, so earlier versions read around the damage and reported success. Assume corruption can recur on such filesystems, and that recovery, not prevention, is the tool's job.

Paginated output carries an extra invalidation axis. --page-size assigns sessions to pages chronologically, and that assignment is recomputed from scratch on every run, so a page's membership can change while every session it already held is untouched: a new session lands on the partly-filled last page, or sessions imported from another machine sort into the middle by their original timestamps and shift everything after them along. Per-session freshness alone can't see this, so is_page_stale() also compares the run's computed session list against the cached page_sessions rows and reports sessions_changed. Without that comparison the affected pages report up_to_date, and the new sessions land in the cache and in their own session-*.html but never in any combined page (issue #308).

Connections run in WAL mode with synchronous=NORMAL (durable across app crashes; only a power/OS crash can lose the last commit — fine for a regenerable cache), plus journal_size_limit (64 MiB) so a WAL that grew under load is truncated back when it next resets instead of keeping its high-water mark on disk. The pragmas come from migrations.runner.apply_write_pragmas, which every writing connection applies — the two that open outside CacheManager included: the migration runner's own, which is what touches a brand-new database first, and the FTS index builder's. As to the runner, at the SQLite defaults it ran the whole migration chain at an fsync per commit: 128 ms/db against 13 ms/db. Setting only journal_mode is not the fix: it persists in the file, but synchronous is per-connection and stays at FULL (50 ms/db). Those are 20 fresh databases per arm on an idle disk; re-derive with scripts/bench_migration_pragmas.py rather than trusting them, because the ratio is not a constant. Fsync cost scales with device contention, so on a loaded box the same arms measured 1382 ms against 46 ms — while a synchronous=OFF control stayed at 10-12 ms/db across every load, which is what identifies the cost as fsync rather than migration work.

Count the syscalls instead of timing them and the shape is exact, with no dependence on what the disk was doing — strace -c -e trace=fsync over one run_migrations, with the chain truncated to its lowest N migrations:

migrations pre-fix shipped
12 228 7
13 236 7
14 244 7

Every migration added to the chain costs 8 more fsyncs at the defaults, and none with the pragmas — the runner's cost grows with the chain while the shipped one stays flat, so this bounds a cost that would otherwise rise with every schema change, rather than paying for itself once. Don't infer that slope from timings: what an fsync costs swings by more than 10x with contention, so per-migration wall-clock deltas measured on different days are incoherent (one such pair read +16 ms and the next −0.7 ms), while the counts above are stable.

The FTS index builder (cli.py::_build_search_index) is the same shape one file over. It commits once per transcript file so an interrupted backfill resumes, which at the defaults is an fsync per file — 33 / 43 / 63 / 103 fsyncs over 10 / 20 / 40 / 80 files, against a flat 16 once it applies the pragmas. Small in absolute terms (~0.65 ms/file, roughly 1% of a real build, where decompress and tokenise dominate), and included because the slope is what the pragmas remove.

Which writer applies them is pinned rather than asserted: TestConnectionCensus enumerates every sqlite3.connect in the package by AST and fails until each is classified as a configured writer or a reader. Prose could not hold that claim — the migration runner was missed when these pragmas were first written, and the FTS builder was missed again while fixing the runner.

A single-threaded run like that one therefore badly understates what the pairing is worth during a parallel test suite: the unit leg creates ~402 databases, and with the runner's pragmas removed it takes ~130 s against ~51 s, three interleaved pairs with no overlap between the arms. That is ~195 ms saved per database — well above the ~110 ms an idle bench predicts, because fsync does not parallelise. Sixteen -n auto workers do not get sixteen devices; they queue at one, and at synchronous=FULL each worker's commits lengthen every other worker's, so the contention the pragmas remove is largely self-inflicted.

That measurement also carries a diagnostic worth more than the ratio. The slow arm was the stable one (±1.6%) while the fast arm swung ±16%, which inverts the usual expectation — because the slow arm is fsync-bound and therefore pinned by the device, indifferent to whatever else is on the box, while the fast arm is CPU-bound and exposed to it. Stability is not evidence of a quiet box; it can be evidence of a saturated resource. It is also why box load could not swamp the comparison: the noise lived entirely in the arm that got faster.

A mode=ro reader applies neither — it cannot switch journal modes and needs neither pragma. The runner's connection is outside the lifecycle described below and adds nothing to it: _migrated_db_paths memoises the migration check, so it opens once per process and database rather than per call. By default _get_connection() opens and closes a connection per call, so no file handle lingers to block temp-dir cleanup on Windows. A build issues ~190 such opens, which dominates cache-build cost, so the converter wraps its hotspots (ensure_fresh_cache, the per-file load loop, per-session generation) in CacheManager.batch(): one shared connection reused for the scope and closed on exit (including on exception). batch() nesting is a no-op reuse, so the wraps compose.

batch() is per instance, and an instance is per project, so a loop over projects still closes the last connection between every two of them. In WAL mode that is the expensive close: the last connection out checkpoints and deletes the -wal/-shm files, and the next connect + PRAGMA journal_mode=WAL recreates them. process_projects_hierarchy plans every project (11 short queries each) before converting any, which on a 332-project archive was 3,658 open/close cycles — ~90 s of a 96 s no-change pass on Windows against an 890 MB cache (29 ms per cycle with nothing else open, 6.7 ms with one idle connection held). So the pass holds a connection_lease(db_path) for its whole run: one connection per thread and database, which _get_connection() and batch() both yield instead of opening (a lease is an outermost batch that spans instances). Closed on scope exit like a batch, so the Windows guarantee holds at the pass boundary; per thread because sqlite3 connections are thread-bound and serve answers requests on other threads while the watch thread converts. A corrupt database drops the lease before the rebuild deletes the file, and the rest of that pass runs connection-per-call. Same pass with the lease: 5.3 s.

Keeping the WAL bounded. SQLite only checkpoints passively on its own, and only restarts the log when no reader is using it; the other time it truncates is when the last connection closes. A pooled pass has readers and writers overlapping throughout (measured on test data: peak WAL ~3x the serial pass's, 26 MB against 8 MB for a 59 MB cache), and an interrupted pass, or another process holding the database open (the serve search API, a TUI), means the last close never happens — issue

332 found a 17.8 GB WAL beside a 6.35 GB cache, which the next start

had to scan in full before anything could use it. So process_projects_hierarchy ends by calling cache.checkpoint_wal (PRAGMA wal_checkpoint(TRUNCATE) on its lease), as do serve's index build and shutdown. It waits at most 2 s for readers — a TRUNCATE holds writers off while it waits — and a checkpoint that cannot finish is left for the next pass. A log that is already oversized (over WAL_SIZE_LIMIT_BYTES) when a pass or serve starts is compacted first, with a message and the ordinary busy timeout (cache.trim_oversized_wal): the first connection has to read the whole log to recover it anyway, and the checkpoint costs about as much again (2 GB: 1.1 s + 1.1 s on a warm Linux page cache; the reporter's disk ran ~30 MB/s), so paying it up front spares every read and write of the pass. Otherwise it costs one stat. Before its checkpoint a pass also hands free pages back to the disk (cache.compact_cache): SQLite keeps the pages a write frees in the file for later writes, so a re-parse after a content-schema change (#416's left ~1.4 GB of a 5.57 GB cache free) never shrinks it. When at least a fifth of the file, and 64 MB, is free pages, it runs VACUUM, waiting at most 5 s for a writer and otherwise leaving it for the next pass; CLAUDE_CODE_LOG_CACHE_COMPACT=0 turns it off. VACUUM writes the whole database through the WAL, which the checkpoint then truncates. Separately, save_cached_entries and extend_cached_entries serialise their entries (json + zlib, the part that scales with the session) before their first write, because Python's sqlite3 takes the write lock at that write and every other process's writes wait for as long as it is held.

Freshness checks are batched too (issue #12): get_modified_files() fetches every cached row for the project in one query (one connection open, or zero extra inside a batch() scope) and rules out subagent-sidecar fingerprints with one scandir per parent directory, instead of a per-file query + is_dir() probes. The fingerprint covers the agents' transcripts (agent-*.jsonl: count, newest mtime_ns, total bytes) as well as their agent-*.meta.json sidecars, because a trunk's cached rows carry those transcripts spliced in and a running agent grows its file without touching the trunk. Rows written before transcripts joined it are compared on the sidecar part alone, so the upgrade does not re-parse every session at once.

In the flat layout an agent file's children sit beside it in the same subagents/ dir, next to every unrelated sibling. So an agent file's fingerprint counts only the sibling transcripts its parse spliced in — the agent ids on its sidechain entries, which reach grandchildren through the children's own spliced rows — and stores that scope after an @ (cache.SubagentsSnapshot, fingerprint_scope), so a check rebuilds the same narrowing. Without it, one running agent's append invalidated every sibling's row and a watch tick re-parsed the whole family (measured on a synthetic 50-agent family: 50 agent parses per tick → 1). The snapshot is taken before the parse and the scope applied after it, keeping the as-of-the-parse rule; the sidecar part stays family-wide, since only a re-parse can tell whose child a new spawn is. A dir is scanned once per get_modified_files() however many of its agents it checks. This is what makes TUI startup near-instant on multi-thousand-file archives.

For the operations / recovery side (archived sessions, manual deletion, cleanupPeriodDays), see docs/restoring-archived-sessions.md.

2.4 Migrations

claude_code_log/migrations/ is a small migration system. Each migration is a NNN_description.sql file applied in numeric order by migrations/runner.py. The schema-version table tracks which migrations have run; cache.py invokes the runner the first time a given cache DB is opened in a process (memoised per DB path, re-checked if the file disappears), so a fresh checkout running against an old cache DB transparently upgrades.

Current migrations:

  • 001_initial_schema.sql — sessions table + per-message metadata.
  • 002_html_cache.sql — adds the rendered-HTML cache layer.
  • 003_html_pagination.sql / 004_html_pagination_variant.sql — per-page HTML chunks for --page-size.
  • 005_session_team_name.sql — adds team_name to sessions for the teammates feature (PR #125).
  • 006_session_ai_title.sql / 007_subagents_fingerprint.sql — ai_title on sessions; subagent-sidecar fingerprint on cached files.
  • 008_session_sidecar.sql — cross-session sidecar tables (session_parents, junction_uuids, dedup_winners, sidecar_state) for session-scoped incremental rendering (§ 2.12).
  • 009_sessions_hidden.sql — adds hidden to sessions, so warmup / empty sessions stay cached but out of the rendered set.
  • 010_sessions_residual_count.sql — adds residual_count to sessions: the per-session entries a full load traverses but message_count doesn't cover, which the incremental cache refresh needs to recompute projects.total_message_count by delta (§ 2.14). Deliberately NULLable — a NULL means "unknown basis", and the refresh declines rather than compute a delta from it.
  • 011_cached_file_size.sql — adds source_size to cached files, so freshness no longer misses an append that lands inside the mtime tolerance (§ 2.15). NULL on pre-011 rows falls back to mtime alone.
  • 012_message_lookup_indexes.sql — composite indexes for the refresh's per-tick lookups, each of which was walking every row in the project (17–22 ms a call on a 38,706-row archive, 0.2–2.5 ms after). Pure performance: no columns, nothing to backfill. Two things about it are worth knowing:
  • (project_id, session_id, timestamp, file_id) carries timestamp for a caller outside the refresh: load_session_entries (the TUI, and rendering an archived session) filters on session but orders by timestamp, and without that column the planner takes the timestamp index and walks the whole project to load one session. With it, the seek and the ordering come from one index and no sort is needed.
  • That same index is double-edged — it also lets the planner satisfy a bare session_id IS NOT NULL as a range scan over every session-bearing row and prefer that to seeking the uuids a query asked for, so three queries had to move that predicate out of SQL and into Python to keep it from making them slower.
  • 015_project_refresh_pending.sql — added refresh_pending to projects: an entry write whose derived session rows and aggregates had not been written yet. Existing rows start set, because a cache written before it may already hold that damage and nothing else can tell: one full refresh per project, from the cached entries, on the first run after upgrading. Retired by 016 (below), which keeps that heal. For a Codex project that run also re-renders every session page, because render_provider_wholesale picks the pages to re-render from get_modified_files.
  • 016_drop_refresh_pending.sql — drops refresh_pending: a refresh commits whole or not at all (§ 2.3), so nothing marks an unfinished one. A project 015 still marked gets total_message_count zeroed first, which the next run reads as a cache to refresh in full, from the cached entries: 015's heal at 015's price. DROP COLUMN needs SQLite 3.35 (2021), which makes 3.35 the cache's minimum (MIN_SQLITE_VERSION): run_migrations checks it before opening the file, since on an older SQLite the DROP failed as a bare syntax error after the UPDATE had committed, unrecorded, so again on every run. The CLI checks it once up front (convert unless --no-cache or a single file, serve unless --no-convert, watch) and exits 1 with one line naming both versions.
  • 019_session_peak_context.sql — adds peak_context_tokens to sessions: the largest context one main-thread turn sent (input + cache creation + cache read), which the summed totals can't give back because every turn's cache read counts the same context again. The minimal theme shows it as peak in the transcript header and on the index's session rows. NULL means unknown (a Codex session, which reports only cumulative totals, or a session with no usage) and isn't shown. The migration fills the column for every cached session from its messages rows, by compute_session_data's rule (the largest sum over non-sidechain assistant rows), so archived projects get a peak too. It deliberately doesn't mark projects for a full refresh, as 016 does: an archived project is never refreshed again, so the mark (its message total at 0) would never be lifted.

Recreating-tables migrations toggle PRAGMA foreign_keys = OFF/ON around the rebuild to avoid losing rows to cascade-deletes during the swap.

2.5 JSON export

claude_code_log/json/ is a thin renderer that mirrors HtmlRenderer / MarkdownRenderer: same generate(...) / generate_session(...) / generate_projects_index(...) surface, same --depth and --compact honoring. Output is a structured JSON document — top-level version / title / detail / compact / sessions / messages keys; each node carries index / type / title / timestamp / session_id / content, plus optional parent_uuid / agent_id / pair_first etc. when present. Children are nested directly under their parent's children array — it's the same tree the HTML/Markdown renderers walk, serialized verbatim.

The renderer runs entries through generate_template_messages (the same format-neutral pipeline § 3 describes), so JSON output inherits all post-factory polishing for free: slash-command normalisation (bare <command-name>X</command-name> → /X), command-args hardening, teammate session-color enrichment, etc. There is no JSON-specific cleanup pass — the rule of thumb is: if it shows up right in HTML/Markdown, it shows up right in JSON. This is the operative example of the factory-layer normalisation seam: raw TranscriptEntry data is polished once at factory time into the typed MessageContent models that all three renderers share, so display polish lives in one place rather than being re-implemented per output format.

A few JSON-specific touches:

  • _json_default unwraps Pydantic models embedded in MessageContent dataclasses (tool inputs/outputs are Pydantic; dataclasses.asdict doesn't recurse into them, so without this hook they'd stringify via __repr__ and lose structure). Also handles Enum and Path.
  • is_outdated(file_path) reads the version field from existing JSON output and compares against the current library version — same invalidation contract as the HTML cache so re-runs skip unchanged outputs. It guards on Path.is_file() (not exists()) so a non-regular destination like /dev/stdout is treated as outdated rather than opened, which would deadlock the version sniff (issue #223). An explicit --output bypasses the skip entirely (force_regenerate, issue #221) since the version marker can't tell which source produced a user-chosen file.
  • combined_transcripts.json per project; session-{id}.json for individual sessions. The naming respects variant_suffix for detail/compact variants.

The projects-index JSON (all-projects-summary.json) is a parallel top-level file — same shape as HTML's index.html but consumable by external tools (dashboards, query scripts, jq pipelines).

2.6 Depth filter

The --depth flag (#159) lets users dial how deep into the message hierarchy to render — session > user > assistant > agent > tool > hook — naming the level by the node the output stops at. It maps onto models.RenderingDepth (which keeps the older verbosity names internally) via models.DEPTH_TO_DETAIL:

  • hook (= RenderingDepth.HOOK) — everything, incl. hooks + system notices.
  • tool (= TOOL, default, DEFAULT_DEPTH) — detailed but cleaned: drops system/hook noise while keeping the full conversation and tool I/O.
  • agent (= AGENT) — drops most tool I/O, keeps the conversation plus a curated set of "interaction signal" tools (WebSearch, WebFetch, Task, Agent — the ones that show what the agent did, not what it read). See _LOW_KEEP_TOOLS in renderer.py.
  • assistant (= ASSISTANT) — drops all tool I/O (user + assistant only).
  • user (= USER) — drops everything except user messages and steering (for feeding downstream agents, e.g. a requirements doc).
  • session (= SESSION, depth-only, no --detail spelling) — session structure only: session/branch headers + fork landmarks, every message body dropped. Handled by an explicit branch in _ghost_template_by_depth (the visible_at predicate keeps threshold-less built-ins like UserTextMessage visible at every level, so "drop even user messages" can't be expressed via depth_visibility).

The legacy --detail full|high|low|minimal|user-only is kept as a deprecated alias (removed in 2.0) and maps to the same RenderingDepths. Filenames use a single canonical suffix per level — the --depth name (.hook/.agent/.assistant/.user/.session), with the default tool/TOOL suffix-less — regardless of which option selected it (so --detail low and --depth agent share the .agent file). See utils.variant_suffix.

Recaps (AwaySummaryMessage) are a cross-cutting exception: they are a high-level summary of activity, so they stay visible at every content level (depth_visibility = USER), including user. The --no-recaps flag suppresses them at all levels — giving --depth user --no-recaps for a truly user-only view, or --depth assistant --no-recaps to drop the recap/agent redundancy (#179).

Filtering happens in a single post-render pass on TemplateMessage: _ghost_template_by_depth sets each non-visible slot in RenderingContext.messages to None ("ghosting"), keyed by the content class's depth_visibility predicate (plus the _LOW_KEEP_TOOLS allowlist at low and sidechain dropping below HOOK). Indices stay stable — surviving messages keep their message_index, so there is no reindex; the rendered tree simply skips ghost slots. Earlier revisions ran a second, pre-render _filter_by_depth pass on TranscriptEntry plus a _reindex_filtered_context remap after every deletion; the ghosting model collapsed both into this one axis.

Important interaction: _pair_skill_tool_uses also ghosts in place (the slash-command body and the redundant "Launching skill" tool_result). Because anchor-target references can be cached before a slot is ghosted — a branch header's parent_message_index, session_first_message entries, junction forward-links — each ghosting step sanitizes them afterward: _pair_skill_tool_uses calls _drop_anchor_refs_into_ghosts and _ghost_template_by_depth calls _repair_stale_anchor_refs, so no #msg-d-{N} backlink dangles (see PR #131 fix). See rendering-architecture.md § 5 for the full pass order.

2.7 Image export

image_export.py is format-agnostic: HTML and Markdown both call into it. Three modes (matching the --image-export-mode CLI choices):

  • placeholder — drop the image and render a placeholder marker in its place.
  • embedded — base64-encode the image directly into the output as a data URL.
  • referenced — write the image to disk next to the output and embed a src= reference. The default for both formats.

Images are held by reference. A transcript carries each image as base64 inside its entry, and an entry is held whole: in the master list, in every slice fed to a render worker, in the parsed-entry store across watch ticks. So the parser swaps each image's source for a reference before the models are built (image_store.py, take_images, on any line whose text holds "base64"): ImageContent.source is an ImageRef (type: "ref", digest, media_type), and a tool result's image dict carries the same three keys. The swap is the cache's (§ 2.3): only an exact source of 2 KB or more, so a small or odd one stays an inline ImageSource, and every reader takes both, through image_bytes / image_base64 / image_digest, never a field. The bytes are held in the process, once per distinct image, until a cache write that stores them commits (image_store.release, from write_transaction or the end of atomic_refresh); after that, and in any process that opened the cache (each CacheManager registers its database, a render worker's read-only one included), they are read back from image_blobs, one image at a time on a connection of its own, with the last 32 MB read kept for the next pass over the same page. A run with no cache (a single transcript, --no-cache) keeps them held until convert_jsonl_to returns. A render pool hands its workers the parent's caches and, should any be left, the images it still holds. JSON export (JsonRenderer) writes each image out whole, as the transcript had it. A transcript's own ref source is forged (Claude Code writes images inline), so the parser empties it, and an ImageRef digest must be 32 hex characters: it becomes part of a file name. On the two most image-heavy projects of a real archive (43% of their transcript bytes is images), this took 17–31% off the time of every run but the first (which AVIF encoding dominates: 6–7%) and 41–50% off peak memory (30–37% on the first run), medians of three runs, with byte-identical pages (work/cache-image-store.md).

Referenced files land in images/ beside the page, named image_<digest><ext>, from the source image's digest, so an image already exported is found from its reference alone: a warm render reads no image bytes at all. Markdown writes the source bytes under the first 16 hex digits of that digest. HTML re-encodes through export_compressed_image (Pillow): AVIF at quality 50, speed 8, longest side capped at 2000px, full 4:4:4 chroma for non-JPEG sources (mostly screenshots, where subsampling smears coloured text), no EXIF in the output, and a PNG colour key (tRNS) turned into a real alpha channel, which AVIF needs to keep those pixels transparent. Its digest covers the source's digest and the encoder settings (_encoding_tag), so a file is found again — by any pass, run or worker — without decoding the source, and a settings change renames every file instead of leaving old encodings behind a current name. The source is written unchanged when re-encoding would not help (animated, no smaller than the source, Pillow without AVIF or WebP) or Pillow cannot read it. Each HTML <img> carries loading="lazy" and the displayed (EXIF-oriented, scaled) width/height, so lazy loading doesn't shift the layout; the sizes come from the encode or, for a file already on disk, from its header. A render with no output directory (an in-memory page) embeds instead, as does every stdout stream, whose temp directory is discarded. An image written into Markdown text as a data: URL (a fetched page, a pasted snippet) comes out of the Markdown render as an inline <img>; in referenced mode HtmlRenderer._export_inline_data_images moves it into a file the same way, on each formatted fragment, before the fragment store keeps it. Before this, an image-heavy session's page held each Read-tool screenshot as inline base64 — a real 350MB session page is 30MB plus 73MB of AVIF files.

embedded and referenced both refuse an image unless is_safe_source passes: the media type must be PNG, JPEG, GIF or WebP (never the scriptable image/svg+xml) and inline data strictly valid base64 (a reference's bytes passed that check when it was made), otherwise the image degrades to the placeholder, as does a reference whose bytes no cache holds any longer. The transcript's media_type and data are untrusted (an image can come back from a tool, an MCP server or a web page), and a crafted media_type used to break out of the <img src> attribute (issue

277); the HTML sinks also escape_html the final src. Tool-result

images go through the same gate and the same export mode (HtmlRenderer._format_tool_result_image, MarkdownRenderer._tool_result_image), and plugins get it from claude_code_log.plugins (plugins.md § 4.2).

Default is referenced for both: an HTML page or .md file then needs the images/ directory beside it. embedded drops that requirement, but an HTML page is still not a single self-contained file: its timeline loads vis-timeline from the assets/ directory beside it (below).

Referenced filenames are content-addressed — images/image_<digest>.<ext> from the BLAKE2b digest of the decoded bytes (plus, for HTML's compressed exports, the encoder settings, as above) — so a given image maps to exactly one file no matter which render pass, run, or worker process exports it, and re-exporting is idempotent (an existing file is already the right bytes; writers go through a unique temp file + atomic os.replace, so concurrent exporters of the same image replace identical content; on Windows, where one exporter's replace can be refused while another's lands, a refused replace counts as done once the file exists, and is otherwise retried briefly — the same treatment as the timeline assets below). This replaced a per-render counter whose names collided between the combined-page and per-session passes — each pass restarted at image_0001 and assigned the same names to different images, so the last pass to run overwrote the other's files. Content addressing is also what lets referenced-mode renders use the fragment store (§ 2.9) and the render fan-out (§ 2.10).

Images no page shows are removed, by image_export.prune_unreferenced_images: it reads every HTML and Markdown page in the directory for images/image_<digest>.<ext> references and deletes the exported images none of them makes. Files not named like an exported image, and any modified in the last hour, are left alone; an exporter that reuses a file touches it, so an image a concurrent run is about to reference survives. Reading the pages costs about what writing them did, so a conversion sweeps only once per library version per output directory (sweep_images_once, which leaves the version in images/.swept): the run after an upgrade, which re-renders the pages and may orphan a previous encoder's files. converter.sweep_project_images runs it after each project converts (inline, in a pool worker, or from the CLI for one project), never for a date window or a single transcript. --clear-output prunes with no grace period after deleting a format's pages, so pages of the other format keep their images.

The timeline library is a sidecar too. vis-timeline ships in the package (html/assets/vendor/, pinned with checksums in its PROVENANCE.md), and HtmlRenderer.generate copies it into an assets/ folder, with its license, beside every page it renders into an output directory (ensure_vendor_assets in html/utils.py); the page puts the relative paths on #timeline-container and loads them on the first Timeline click. Like referenced images, this needs the output directory, so it holds in every write path (combined, paginated, session files, workers, --expand-paths, -o file.html), and each output directory gets its own copy. A bare-string render (generate_html() without output_dir) gets empty paths, and its timeline reports the missing library rather than fetching one. File names carry the library version, so an upgrade adds files instead of overwriting them; writes are temp file + os.replace because the render fan-out's workers all ensure the folder at once. On Windows one worker's replace can be refused (WinError 5) while another's is landing; a refused replace counts as done once the file is that build (same name, same size), and is otherwise retried briefly (utils.retry_on_sharing_violation) before the page renders without timeline sources — which a parallel render once did, differing from the serial one. The library used to come from unpkg, unpinned, the one network request a generated page made (issue #278).

2.8 Performance profiling

renderer_timings.py provides log_timing(label, t_start) context managers used throughout renderer.py. Set CLAUDE_CODE_LOG_DEBUG_TIMING=1 to print per-phase times to stderr — useful for spotting which phase regressed when a large transcript suddenly takes seconds longer than before.

2.9 Render memo caches

A project conversion renders every message twice: once into its combined-transcript page and once into its individual session-*.html. Both go through HtmlRenderer.generate, which rebuilds the tree from the same source entries, so the per-message formatting work is duplicated wholesale. On a 118-file, 12k-message project that is 22,420 format_content calls covering 11,113 distinct messages.

render_cache.py memoizes the two dominant leaves of that work — Pygments highlighting (html/renderer_code.py::highlight_code_with_pygments) and wenmode Markdown (html/utils.py::_render_markdown_memoized, behind render_markdown / render_user_markdown / render_markdown_inline). Measured effect on that project: 12.4s → 8.7s wall, with all 88 output files byte-identical. Hit rates run ~69% (Pygments) and ~59% (Markdown); Pygments exceeds the 50% that page-vs-session duplication alone implies because the same file contents are commonly re-read across messages.

Two properties matter for correctness:

  • Markdown is not a pure function of its text. The SHA-linkifier plugin resolves commit hashes against the per-render repo cwd carried by git_remote._render_repo_cwd (read via current_render_repo_cwd()), so identical text legitimately renders different links in different projects. That cwd is part of the Markdown key — without it a long-lived host (serve, the TUI) would serve one project's commit links inside another's page. Pygments has no such coupling and keys on its arguments alone.
  • Bounded by bytes, not entries. Rendered fragments are large, so functools.lru_cache(maxsize=N) gives no control over footprint. The caches evict LRU against a byte budget and refuse any single entry above 1/8 of it, so one huge highlighted file cannot evict everything behind it. CLAUDE_CODE_LOG_RENDER_CACHE_MB sets the budget (default 192 MB per cache; 0 disables memoization and restores the previous always-recompute behaviour). Typical projects stay far under it — the measured project held 13.3 MB of Pygments and 2.7 MB of Markdown with zero evictions.

CLAUDE_CODE_LOG_DEBUG_TIMING=1 prints hit rate, entry count and bytes per cache alongside the render timings.

The fragment store sits above the leaf memo and removes the page-vs-session duplication itself rather than its expensive leaves: fragment_store.py caches each message's complete formatted fragment — the (title, html, timestamp) triple _annotate_tree_for_render writes onto the tree — for the length of one conversion, so the per-session pass reuses what the combined-page pass formatted (measured: 64,968 lookups → 32,441 formats, a 50% hit rate, on a 803MB/187-file archive). One store per convert_jsonl_to call, created by _make_fragment_store (HTML only) and handed to the combined-page and session-file loops; it dies with the conversion, so nothing about it ever needs invalidating. CLAUDE_CODE_LOG_FRAGMENT_STORE=0 disables it for bisecting. Because the store is a RAM-for-CPU trade — measured serial peaks on the 803MB reference project: 1252MB store-off vs 1521MB store-on, the +269MB being the fragment text plus per-entry overhead — _make_fragment_store carries a memory valve: when available memory is under _MIN_AVAILABLE_MEMORY_PER_TRANSCRIPT_BYTE (2.4×, the store-on peak plus margin) times the project's transcript bytes, the conversion runs store-less at its pre-store footprint instead of trading its last RAM for CPU. An explicit CLAUDE_CODE_LOG_FRAGMENT_STORE=1 overrides the valve; whenever the valve trips, the render pool's far higher memory bar has already declined, so a store-less conversion is always serial.

What "transcript bytes" means to every memory check (this valve, the streaming valve of § 2.13, the render pool's worker cap of § 2.10 and the all-projects plan that pre-sizes it, and the parsed-entry store of § 2.16): the trunk files' bytes less the image base64 a parse does not hold (utils.resident_transcript_bytes). A parse holds each image by reference and drops a Read result's second copy (§ 2.7), and counts per file the characters it took out that way (image_store.take_images; a resumed parse starts from its held prefix's count), which the cache records in cached_files.image_bytes (migration 018). The coefficients were calibrated on what a parsed entry costs per byte of its line, so the base64 never belonged in the count: on the two most image-heavy projects measured it is 64–67% of the trunk bytes (35–40% image blocks, 27–29% Read copies; 30% across a whole 146-project archive), and the checks overestimated those conversions about threefold. Counted out, the worker cap's estimate matches again: 2.29 GB for the heavier at 8 workers, 2.37 GB measured (before phase 2: 3.97 GB estimated, 4.06 GB measured). With 4 GB free those two projects now render on 8 workers instead of 3, and with 2 GB on 3 instead of 1. A file the cache has no count for yet is taken whole, which only overestimates.

A fragment is not a pure function of its source entry, and the store carries three guards for the three ways the same message legitimately renders differently in different trees (each found by hash-diffing real projects — see work/render-format-once.md § 4.8): fragments embedding per-tree #msg-d-{N} anchors are never stored (output scan); a signature of the tree-derived render inputs (pair presence, display_model, agent_depth, sidechannel/collapse flags) is part of the store key; and get() verifies the requesting tree's content digest matches the one stored at put time before serving. fragment_store.content_digest is a canonical BLAKE2b walk over exactly the compare-relevant state — same field coverage as dataclass equality, with the per-tree message_index/fragment_key fields excluded via compare=False, and any looseness of Python == that the canonical form can't express (bool/int, dict order, identity-repr objects) resolving to a conflict served fresh, never a false hit. A digest is stored rather than the content object so the store holds only strings and bytes — picklable, spillable, and unable to pin object graphs — the property the planned fed-worker format phase depends on. On the reference 803MB archive this is peak-RSS- neutral (measured 1521MB either way: the stored contents alias objects the master entry list keeps alive, and the store-on peak of +269MB over store-off is the 186MB of fragment text plus per-entry overhead), so the fragment text itself is what any future memory bounding must address. Keys are (id(source_entry), part_ordinal) — entry identity, stamped in the pass-2 render loop — because transcript uuids collide across resumed/forked sessions. Renders with image_export_mode="referenced" participate like any other: image filenames are content-addressed (§ 2.7), so a stored fragment's src= names the file the first formatting of that message already wrote, and replaying the fragment skips only a write that has happened.

2.10 Intra-project render fan-out

render_pool.py fans a single project's output files — its combined pages and its per-session files — out over worker processes, and render_dispatch.py is the policy layer that decides when it is used: build_render_pool (should this conversion have a pool), worth_dispatching (is this batch worth sending) and dispatch_render_units (run the batch, falling back inline). The dependency runs one way — render_dispatch imports render_pool, never the reverse — so a worker never loads the policy it executes. This sits below the project-level pool in § 2.1 and exists because that one leaves cores idle in two shapes: the all-projects wall clock is bounded by the largest single project (measured: 5 real projects, 4 cores, 195s of work, 65.0s wall — exactly the largest project's own time, at 2.18 cores average), and an incremental run has only one or two stale projects to fan out at all.

Workers are fed, never self-sufficient: they do not load the transcript at all. Each dispatched unit carries its own slice of the parent's master message list (RenderUnit.entries — a page's sessions' entries, or one session's trunk + integrated agent entries), the master-list ordinal of each entry (entry_ordinals, so fragment-store keys name the same positions in every process), and — for session units — the session's slice of the parent's fragment store (RenderUnit.fed_fragments). The one per-worker piece of state is a slim SessionTree (dag.slim_session_tree, sent via the pool initializer): the render path reads only the DAG lines, junction points and workflow dicts, so the per-message nodes mapping — whose pickled size is the whole transcript — stays behind (its lookups raise on a slim tree, so a future render-path consumer of nodes fails loudly in a worker instead of silently diverging). The parent keeps every staleness check and cache write to itself (so the DB stays single-writer — a worker's own CacheManager, kept only for the per-session combined-link lookup, is constructed read_only=True: no migrations, no project-row upsert, mode=ro connections), slices session units with the same trunk predicate generate_session filters by (so the worker's re-filter of the fed slice is idempotent), and the pool starts lazily on first submit. RenderPool.submit declines a unit with no entry slice to the inline path, and a pool is only created when the conversion has a pre-built session tree — a worker-side DAG rebuild from a slice alone could genuinely differ.

Which batches are worth dispatching is decided per batch by render_dispatch.worth_dispatching, on the work a batch carries rather than the number of units in it. A conversion dispatches two batches: its stale pages (one unit per ~page_size messages, where nearly all the render time is) and its stale session files (cheap, because the page pass has already put their fragments in the store). Weighing them by unit count got this exactly backwards — an 8-unit floor meant a project with fewer than 8 pages rendered its expensive page batch inline and fanned out only the cheap session batch, paying the pool's ~1s of spawn + import for the batch with the least to gain. Weighed by entry count against _MIN_ENTRIES_FOR_RENDER_POOL (4,000, about twice what that startup costs at the ~2,000 entries/s the render phase sustains), projects between ~4k and ~15k messages went from 0.86–1.05× to 1.27–2.27×, and projects below it went from 0.82–0.94× — a real loss — back to 1.00×. Two refinements complete the rule: a lone unit never dispatches (it would render in a worker while the parent waits), and once the pool has started (RenderPool.started) any multi-unit batch does, since the startup is then sunk — which is how the session batch rides along behind the page batch that paid for it. _MIN_MESSAGES_FOR_RENDER_POOL is the same number, and only a short-circuit: every batch is a subset of the project's message list, so a project below it could never form a batch that clears the gate.

Before the feed, each worker re-loaded the whole transcript from the warm cache in its initializer (~0.7s at 12k messages; ~12s of CPU per worker at 329MB of transcript), so per-worker cost scaled with project size rather than unit size — measured post-fragment-feed on a 16-core Mac, 16 workers still burned 286.1s of CPU to do 91.1s of serial work, almost all of it transcript reloads, and 16 workers came out slower than 8. Feeding moves each entry at most twice per conversion (its page unit, then its session unit) instead of once per worker. Fragments cross the boundary as before (plain strings + digests — § 2.9's store made them portable): a page worker returns its fragment store as a delta in its result, the parent absorbs it, and session units dispatch afterwards carrying their slices. Pages always drain before sessions dispatch, so the feed covers essentially every message; every fed fragment is digest-verified on use, so the worst a stale slice can do is cost the recompute it would have cost anyway.

Memory: the cap charges measured post-feeding footprints. The conversion parent is the heavyweight — its master entry list (Pydantic entries, TemplateMessage tree, SessionTree) plus the fragment store's text and in-flight pickled slices measured ~4.4× the transcript's bytes on disk (598MB on a 140MB/47k-message project, 1458MB on 329MB/97k; VmHWM polling, 2026-08-26). Fed workers hold only base imports, their memo caches and the in-flight unit's slice: the largest worker measured ~136MB + 0.59× transcript across the same runs. render_pool.memory_capped_workers charges the parent 4.5× + base and each worker 0.8× + base — a ~1.2–1.35× margin over the fit, because the alternative failure mode is real: when workers each held a full copy, an unguarded auto on a large archive exhausted RAM and drove the machine into swap, pegging every core — far worse than rendering serially. (The one under-charged pathology is a single session spanning most of the transcript, whose unit slice re-inflates toward the parent's ~3× in its worker; it is one outlier inside the headroom, and such projects yield too few units to fan wide.) The cap reads available memory as cgroup limit first (inside a container the host's totals are a lie), then MemAvailable, then free physical pages, taking 60% of it as budget. The all-projects parent applies the same cap with concurrent_projects=resolved_jobs before handing out any budget, and each worker re-checks against its own project before starting a pool. Unknown memory allows at most 2 workers.

Both non-Linux platforms need their own probe, since each would otherwise fall through to that unknown-memory branch and be capped at 2 workers regardless of cores or RAM — a 16-core Mac measured the whole fan-out on 2 before this was fixed. macOS has neither MemAvailable nor SC_AVPHYS_PAGES: _darwin_available_bytes shells out to vm_stat (present on every macOS, no dependency) and counts free + inactive + speculative + purgeable pages, since excluding the cheaply reclaimable ones reports a busy Mac as having almost nothing free. Windows has no /proc and no os.sysconf at all: _windows_available_bytes reads ullAvailPhys from GlobalMemoryStatusEx via ctypes. Every probe returns None rather than raising, so an unreadable platform stays conservative instead of failing a conversion.

On by default at the CPU count, settled by the 16-core measurement below. $CLAUDE_CODE_LOG_RENDER_JOBS overrides: 1 or off disables it, auto is the default, an integer pins a count — see render_pool.resolve_render_jobs. --jobs never enables or disables it; it only caps it, so the two pool levels together can't oversubscribe. An explicit convert_jsonl_to(render_jobs=N) overrides the environment; the default None consults it. render_dispatch.build_render_pool declines regardless for single-file mode, a missing cache manager, a missing pre-built session tree (workers render fed slices against the conversion's tree), projects below _MIN_MESSAGES_FOR_RENDER_POOL, and machines without the memory the cap formula demands; a pool that is created still only starts if some batch clears worth_dispatching above. image_export_mode="referenced" used to decline too, when renders allocated images/image_NNNN.png names from a per-call counter that collided across passes and processes; referenced filenames are now content-addressed (image_export digests the decoded bytes and writes via temp-file + atomic replace), so any pass, run, or worker exporting the same image converges on the same file and the mode fans out like any other.

One ordering change made the pages parallelisable: the paginated writer used to reveal page N-1's "Next" link while generating page N, so page N's render edited page N-1's file. That fixup now runs once after all pages land — order-independent and idempotent.

Measured on 4 cores, 47k-message project (240 session files, 218 output units); the serial floor — cache check, transcript load, planning, all in the parent and none of it parallelised — is 4.7s:

wall total CPU
neither optimisation 44.8s 43.5s
memo only (§ 2.9) 27.6s 26.2s
fan-out only (4 workers) 22.5s 57.0s
both 20.0s 48.8s

Read those together, because the pair is easy to misread. The fan-out parallelises perfectly well on its own — 44.8s → 22.5s is 2.0× on 4 cores against a 4.7s serial floor. It looks weak on top of the memo (27.6s → 20.0s, 1.38×) only because the two optimisations attack the same work: the memo removes the page-vs-session duplication, and splitting units across processes gives each worker a cold cache and brings some of it back. Both together is still the fastest configuration, so they compose — just sub-additively.

A 16-core Mac over 8 real projects (1543MB of transcripts, largest 329MB) shows what happens with cores to spare — and why the two --all-projects scenarios diverge so sharply:

scenario config wall CPU cores used
full rebuild, 8 projects memo only 100.8s 226.0s 2.2 of 16
full rebuild, 8 projects both 79.3s (1.27x) 324.8s 4.1 of 16
incremental, 1 stale memo only 93.2s 90.8s 1.0 of 16
incremental, 1 stale both 34.6s (2.70x) 367.9s 10.6 of 16

The incremental row is what flipped the default: 2.70x on the everyday shape of a run, using 10.6 cores instead of 1.

The full-rebuild row is the unsolved case, and the numbers say exactly why. Converting the largest project alone takes 93.2s; converting all eight takes 100.8s. The other seven cost 7.6s of wall clock between them — the run is, to within 8%, "how long does the biggest project take". The static budget split then gives that project jobs // stale projects = 2 render workers while the seven small ones finish and 13 cores go idle. So the fan-out helps it barely (1.27x) even though the same project alone reaches 2.70x. Pool-bounding projects are now handled by hold-back: _holdback_plans runs a greedy makespan comparison, largest first (hold while pool(rest) + fanned(largest) beats pooling everything, with fanned time from the conservative _fanned_speedup of the workers a lone memory-capped conversion would get), keeps what it holds out of the pool and converts each alone with the full render budget afterwards. Costs compare cached message counts when every plan has one (bytes alone would miss a dense giant), bytes otherwise. On the reference archive it holds exactly the 97k giant — measured 65.4s → 58.5s (1.12x) on the 8-core VM under the original single-dominant rule, whose decision the general rule reproduces there, since the twin 47k projects keep each other's pool bounded — and it additionally covers shapes the 2x-dominance bar missed, such as a runner-up that bounds a pool of small projects without being 2x any of them. What it deliberately never does is serialize level-sized projects (a certain loss — they already saturate the pool) or hold anything a machine can't actually fan. Fixing the truly general case — several level-sized projects sharing one static split — still needs the split to be dynamic, or a single flat pool over render units rather than two nested levels.

Two consequences. First, core count matters a lot: 48.8s of CPU over 4 cores is 12.2s plus the 4.7s floor, so a 10-core machine should land near 9.5s rather than 20s. Second, the per-worker cost (then: a full transcript reload plus a cold memo) grows with worker count, so the speedup saturates rather than scaling indefinitely.

Those tables predate the fragment feed and the entry feed, which removed most of that per-worker cost in two steps. Re-measured on an 8-core VM over the same 8-project archive (1539MB): with fragments fed, the incremental scenario reached 2.08x at +76% CPU over serial (the pre-feed baseline burned +305%); with entries fed as well — no worker transcript loads at all — it reached 2.87x at +3% CPU (62.6s → 21.8s wall, 62.5s CPU vs 60.5s serial), and the single-project sweep's per-worker CPU overhead fell from ~4.4s to ~0.7s at 8 workers. With the memory cap re-sized to the measured post-feeding footprints (above), the same VM's incremental cap went 5 → 8 of 8 workers and the scenario reached 3.24x at +6% CPU (61.8s → 19.1s wall, 63.3s CPU vs 59.5s serial), byte-identical in every configuration. The full-rebuild scenario improved to 1.12x via the hold-back (above, since generalized from the single-dominant rule to the greedy makespan comparison); what remains is its general case — several level-sized projects, where the core split jobs // stale still grants 1 render worker/project — and the serial parent floor (load + parse + plan). Both land with the remaining "format once, assemble many" step: the flat pool over render units. Planned in work/render-format-once.md.

2.11 Diagnosing hangs (SIGUSR1 stack dump)

When claude-code-log appears stuck (100% CPU, no output), a single SIGUSR1 to the running process dumps the live Python stack of every thread to stderr without killing it:

# In another terminal
kill -USR1 $(pgrep -f claude-code-log | head -1)

The handler is wired in cli.py::_install_stack_dump_signal() via faulthandler.register(SIGUSR1, all_threads=True, chain=False) and installed before any heavy work in the entry point. POSIX-only — Windows lacks SIGUSR1, the install is a silent no-op there. Unlike py-spy, this needs no root and no extra install, since the runtime is already wired to dump itself on demand. Added by PR #135 to make the DAG cyclic-children class of bug diagnosable in the field; useful for any future hang.

2.12 Session-scoped incremental rendering

Converting a project used to load its entire transcript even when the cache was fresh and a single session file needed regenerating — the master list, DAG and trees exist before any staleness is consulted. The session-scoped path (streaming stage 2 of work/render-format-once.md) removes that: when the Phase-1b gate in convert_jsonl_to finds the cache fresh, the combined output current, and only session files stale, converter._load_stale_session_transcripts loads only the files holding those sessions' entries and renders them through the ordinary _generate_individual_session_files, byte-identical to the full path.

Three pieces make the partial load faithful:

  • The cross-session sidecar (migration 008, cache.SessionSidecar) is persisted by every full unfiltered directory load, in the same batch as the per-file cache writes: per-session parent linkage (resume/fork attachment points), junction points with their ordered target lists, and the dedup winner for every uuid carried by more than one session (resume replay prefixes). All three are compact projections of the SessionTree the load already built. A partial load enforces the winner map up front (losing copies drop before the DAG sees them), patches parent/junction facts whose other end isn't loaded, and adds empty ancestor stub lines so depth chains resolve.
  • Discovery by the cache's file map, not by filename stem (CacheManager.get_session_file_map): real archives contain files whose entries span two sessions (a continuation written into the previous session's file) and sessions with no file of their own. Co-resident fresh sessions load along with a stale one and are skipped by the per-session staleness check. An archived stale session (cached rows, source deleted) is skipped outright — the full path loads everything and still renders nothing for it.
  • A pagination-aware combined-freshness check (_combined_output_is_stale): the gate used to ask is_transcript_stale("combined_transcripts.html"), a name a paginated project has no cache row for — so paginated projects never early-exited and full-loaded on every direct conversion. The helper replays the pagination pass's plan from cached session data alone (same session→page assignment, same is_page_stale per page, same invalidation triggers). This also makes the plain "everything is current" early exit fire for paginated projects.

Equivalence is held to byte-identity by test/test_session_scoped_render.py — real fixture projects with the full loader monkeypatched to raise, plus a synthetic project pinning resume-replay dedup, cross-session fork parents, junctions and ancestor chains — and by hash runs over real archives (85 and 187 output files byte-identical on the two measured projects, with 64 and 129 session files regenerated through the partial path; sidecars of 300–742 dedup winners in play). Measured on the 8-core VM against the 803MB reference archive, warm cache: one stale session file went 4.6s → 0.6s (7.9x), and a fully-fresh direct conversion 4.6s → 0.4s (the early exit finally firing for a paginated project).

CLAUDE_CODE_LOG_SESSION_SCOPED=0 disables the path for bisecting. Every decline (no sidecar yet, date filters, --no-cache, an inconsistent file map) falls back to the full load, whose behaviour is unchanged. A missing sidecar only costs that speed; a stale one would render wrongly, so a cache refresh that cannot write it either fails and is redone or drops it (§ 2.3).

2.13 Page-granular streaming conversion

The session-scoped path (§ 2.12) still full-loads whenever the combined output is stale, so peak RAM stayed bounded below by the largest single project — a machine under ~2x its largest project could not convert it at all. The streaming path (stage 3 of work/render-format-once.md) removes that floor for paginated HTML conversions: converter._stream_paginated_conversion plans the session→page assignment purely from cached session data (the same _assign_sessions_to_pages call, via the shared _plan_page helper, so the plans cannot drift), then for each page needing work — a stale page, or stale session files on it — loads only the files holding that page's sessions through the § 2.12 partial-load machinery, renders the page and its stale session files together against a per-page fragment store, and drops it all before the next page. Peak residency becomes max(one page's source files), not the project.

When it runs:

  • Structurally: HTML directory conversions with a fresh-able cache, no date filters, no --force-style regeneration, combined output enabled, and pagination in play per the cached counts. The sidecar must exist; since ensure_fresh_cache now persists it too (same batch as the per-file cache writes), a run whose cache was just refreshed can stream instead of loading the project a second time.
  • By a memory valve, with a sparse fallback: in auto mode the path always engages when available memory is under 2.4x the project's transcript bytes — literally the same knee as the fragment-store valve (§ 2.9): both read _MIN_AVAILABLE_MEMORY_PER_TRANSCRIPT_BYTE, one constant so the two can't drift. The ladder is continuous: below ~2.4x the store had already declined, and streaming takes over the serial conversion; the fan-out's own (far higher) memory bar has long since declined by then, which is why streaming renders inline without losing anything. With more memory than that (or none measurable), the pass still runs — but in sparse mode: once it has planned its pages and counted the ones needing work (stale/missing page, or stale session files on it — pure cache and stat queries), it declines itself unless that count is at most a third of the plan (_STREAMING_MAX_SPARSE_FRACTION), falling through to the full load
  • fan-out. The reasoning is measured, not structural: streaming's wall scales with the pages needing work while the full path pays the whole-project load regardless, so sparse work (the daily-run shape) streams faster even where the fan-out is available — but a dense rebuild renders serially and loses to the fan-out on a roomy machine. On the 8-core/16GB VM against a 137MB/26-page archive (scripts/bench_render.py): incremental (1 page + 3 sessions stale) streamed 2.0s/276MB peak RSS vs the fan-out full path's 3.3s/542MB, while a full rebuild streamed 11.1s vs the fan-out's 6.7s; the crossover sits near 36% of pages stale and moves only weakly with core count (the full load, not rendering, is the fixed cost), so 1/3 keeps a margin under it. CLAUDE_CODE_LOG_STREAMING=1 forces the path wherever structurally eligible, bypassing both the valve and the sparse gate; =0 disables it (the bisecting knob).

Two details are load-bearing for correctness:

  • Strict file resolution: a page load requires every one of its sessions to resolve to a complete, present source-file set (_resolve_session_source_files(strict=True)); any gap declines the whole pass to the full load rather than rendering a page with a session's remnant.
  • The co-resident-session restriction: a source file can span two sessions that sit on different pages, so one page's load can carry a partially-loaded session from another page. The per-page session pass is therefore restricted to that page's own stale sessions (_generate_individual_session_files(restrict_to_sessions=...)) — without it, the partial session renders truncated and its cache row then reads current forever (pinned by mutation test in test/test_streaming_render.py::TestFileSpanningSessions).

Byte-identity is held by test/test_streaming_render.py (a real fixture with the full loader monkeypatched to raise, a synthetic project whose resume/fork couplings span the page split, and the file-spanning trap above) and by hash runs over the two coupling-heavy real archives — every scenario (warm parity, full rebuild, incremental) byte-identical on both. Measured on the 8-core/16GB VM, serial, warm cache (full path → streamed): 296MB project full rebuild 454MB → 305MB peak RSS; 803MB project full rebuild 1490MB → 591MB at slightly lower wall (28.2s → 25.2s), incremental 1092MB → 587MB at 7.6s → 4.6s. The remaining ~590MB is the largest page's co-resident files plus interpreter baseline — the floor scales with page size, not archive size.

Declines fall through to the full load unchanged. The cache refresh itself no longer full-loads on changed sources — that is § 2.14.

2.14 Incremental cache refresh

The last full-residency path was ensure_fresh_cache itself: one changed file re-walked every file through load_directory_transcripts to recompute three things — per-session cache rows, project aggregates, and the sidecar. Streaming stage 4 (converter._incremental_cache_refresh) recomputes all three from a bounded closure of the modified files instead:

  • Per-file parse: each modified file's old identity state (sessions, uuids, parentUuids, requestIds, residual type counts) is captured from the messages table, then load_transcript re-parses it (rewriting its rows exactly as always). Old uuids must be a subset of new — a shrunk/rewritten file means history changed and declines.
  • Closure (SQL projections, no entry loading): the modified files' sessions, plus every session holding a copy of a modified uuid (re-election partners), plus owners of external attachment points (the dedup winner's session when duplicated), plus the complete old target list of any junction a modified entry touches or whose uuid is re-elected (so target order rebuilds natively), plus files holding cross-file metadata (summaries by leafUuid, ai-titles by session) for closure sessions. Sidecar-derived ids are trunk-normalized — junction owners/targets can be branch-qualified {trunk}@{uuid12} line ids that the file map doesn't know.
  • Partial load: the closure's files go through _load_sessions_partial with two refresh-mode deviations — old dedup-winner enforcement exempts modified uuids (their election re-runs natively on the full candidate set, which the closure guarantees is loaded), and the sidecar junction patch skips junctions marked native (the old row would erase a new fork/resume target).
  • Facts persist, restricted to closure sessions (all complete by strict file resolution — the co-resident partial-session trap applies to cache facts too): session rows upserted; junction rows rewritten for tree junctions owned by closure sessions (patched ones rewrite their old rows identically — harmless); parent rows and re-elected winners replaced; project aggregates move by delta — new minus old session-row contributions, plus the modified files' summary-row delta, with bookends extended from the loaded entries' own timestamp strings (the DB normalizes formats).

The two migrations the delta needs. total_message_count is len(messages) of a full load — the traversed entry list — so moving it by delta requires every traversed entry to be attributable to a persisted session row:

  • 009 (sessions.hidden): warmup-only and empty/agent-only sessions used to be filtered before the write, leaving their contribution off the record. The writer now persists them from one unfiltered compute_session_data pass, flagged hidden = 1, and every read site meaning "sessions a human would render" filters hidden = 0 — so the visible set is byte-identical to the old filtered computation.
  • 010 (sessions.residual_count): entries a session owns that compute_session_data skips (attachment, ai-title), counted from the traversed list by compute_session_residuals. Counting them from cached message rows instead is wrong, because attachments are parsed into the cache but can be dropped by DAG traversal — a real-archive holdback caught exactly that (+16). A session owning only such entries gets a row of its own (hidden, since it has no first user message) so the arithmetic has somewhere to put them. The column is deliberately NULLable: a pre-010 row's contribution is unknown rather than zero, and the refresh declines on one.

Together they close the identity the delta relies on, verified across the full 78-project corpus:

total_message_count = Σ(message_count + residual_count) + #summary rows

Summary entries are the one class with no session attribution, and they bypass traversal (appended wholesale), so counting their cached rows is exact.

Decline ladder (each falls through to the unchanged full load): missing sidecar/project data, deleted source files (archival is the full path's business), shrunk files, a pre-009 cache (a closure session with prior entries but no row) or a pre-010 one (a closure session whose residual_count is NULL), attachments involved in cross-session dedup, a requestId with independent surviving copies on both sides of the closure boundary (D1 attribution would need global traversal order — same-uuid replay spans are dedup-resolved and safe), any strict-resolution gap, and a closure larger than max(4 files, a third of the project).

The design identities were verified empirically before implementation across the full 78-project real corpus (I1: total_message_count == Σ unfiltered per-session counts + typed residual; I2: token totals == Σ per-session tokens; I3: bookends == raw min/max; zero failures), and the implementation is held to DB-state equivalence — session rows, aggregates, and all three sidecar tables equal to a full refresh's, plus rendered byte-identity — by test/test_incremental_cache_refresh.py and by holdback runs on real archives (hold back the newest files, warm the cache, restore them, then compare the incremental refresh against the full one: matched on the 803MB reference archive, 296MB repower, and 1003MB platform-frontend-next). DB state is the bar rather than HTML because the first bug this caught — a modified file's new summaries titling sessions outside the closure — was invisible in the rendered bytes.

Measured on the 8-core/16GB VM, first conversion after three new sessions appear in the 803MB reference archive (peak RSS / wall): full refresh + full render 1131MB / 10.6s; full refresh + streamed render 901MB / 8.1s; incremental refresh + streamed render 582MB / 6.7s. Once the render streams, the refresh's full load is the peak — which is what this section removes, completing "no archive too big for the machine". CLAUDE_CODE_LOG_INCREMENTAL_CACHE=0 is the kill switch.

2.15 Watch mode and live page updates

Two commands keep output current while a session is still being written: claude-code-log watch (a resident loop) and claude-code-log serve --watch (the same loop on a thread beside the HTTP server). See work/watch-mode.md for the design and the measurements behind it.

The engine never renders. claude_code_log/watch.py polls (size, mtime_ns) over **/*.jsonl and **/agent-*.meta.json under the watched roots, debounces, and calls a callback; the callback runs the ordinary conversion. The poll is one os.scandir walk taking size and mtime from the directory entries, not a glob per pattern plus a stat per hit: over a whole archive (1,896 files) the glob form cost 0.4–0.9 s per poll, more than the poll interval, and the walk returns the same dict 4–7× faster. Name matching follows the platform's case rule, as Path.glob does (insensitive on Windows), so a session the converter discovers is also one the watcher wakes for. The scan is a trigger, not a source of truth — a false positive costs one no-op conversion, while the conversion already knows precisely what is stale. Two file classes are excluded because both land in the watched tree and would make the loop feed itself: dot-prefixed atomic-write temp files, and generated output.

Debounce is a quiet period (--quiet-period, 300ms) with a max-latency cap (--max-latency, 2s): a turn writes several entries in quick succession, so without the quiet period most of a turn is spent rendering states nobody sees; without the cap a long unbroken stream would never surface. tick() (poll once) is split from run() (wait) and the clock is injectable, so tests drive ticks by hand against a fake clock.

A tick stamps the files before it calls the conversion, and the conversion renders what its own refresh committed (§ 2.3). So a line written while a tick renders is in none of that tick's output, and it is a change for the next tick, which refreshes and shows it: one tick late, never lost.

What makes a tick cheap is §2.12's session-scoped path, which is reachable here only because ensure_fresh_cache_detailed reports how it refreshed (CacheRefresh.NONE/INCREMENTAL/FULL). Phase 1b's staleness test is per-session message counts, so it refuses a FULL refresh — which carries no guarantee that a session's content didn't change while its count stayed the same. An INCREMENTAL refresh does carry it: §2.14's ladder only succeeds after proving each modified file's cached rows are an exact prefix of its current rows, i.e. a pure append. --combined therefore defaults to no for watch: with a combined output present, the session's growth makes it stale and the conversion falls to the streaming path instead.

Both commands take --theme (§ 2.1). A theme switch makes every page stale on the first tick; because a --combined no tick would otherwise leave the combined page in the old theme behind session pages that link to it, convert_jsonl_to (and the all-projects plan) promote that one tick to rewriting it — after which ticks are cheap again.

What the tick then spends its time on was, once §2.12 was reachable, no longer the render (12% of it) but the cache refresh. Profiled on the 803MB / 217-file reference archive appending to its largest session file (39.7MB, 207 entries), a 1.03s tick materialised the same entries three times: §2.14's refresh parsed the file from source (488ms, of which 307ms re-serialising and re-inserting every row), then the closure load rebuilt them from those rows (129ms), then the session-scoped render rebuilt them again (141ms). Two changes removed most of that:

  • A per-conversion parsed-entry store (entry_store.py, §2.16) serves the refresh's list to the other two consumers: closure load 255ms → 7ms.
  • The staleness sweep stopped scaling with the session count. get_stale_sessions ran two SQLite queries per session through is_transcript_stale, and each of those called get_library_version(), which re-parsed installed package metadata every time — 173 calls and 35ms a tick. The version lookup is now lru_cached (it cannot change inside a process) and the two tables are read once and joined in Python: 85ms → 4.5ms.

Tick: 1.03s → 0.717s. load_transcript's full re-parse and full row rewrite of the modified file (483ms) was then the remaining bulk, and §2.16's cross-tick resumption takes it to ~35ms: 0.257s steady state in a resident watch. What remained after that was the refresh's own cache queries, every one of which was scanning the whole project — fixed by migration 012's indexes plus one query rewrite (get_file_states joined cached_files and filtered on file_name, which no index could serve; resolving names to file_id first made it 15.9ms → 0.0ms).

A steady-state watch tick on the 803MB reference archive is 0.145s, from 1.03s — with rendering, which was where this began, now a rounding error against it.

The served page updates itself via html/templates/components/live_update.js, polling from load over http(s). (A file:// page cannot fetch anything, not even its own URL; what it does instead, and only when asked, is Following from disk below.) It polls a HEAD of its own URL and compares Last-Modified, Content-Length and X-Content-Revision. Each covers the one before it: HTTP dates have one-second granularity, so two updates inside the same second are otherwise invisible (the same trap as the cache's mtime tolerance, which §2.3 solves the same way), and size is blind to a rewrite that keeps it — a counter or a status word changing width-for-width. X-Content-Revision is a digest of the served bytes, added by server.py to every file response; it is deliberately not an ETag, because the stock send_head skips its If-Modified-Since check whenever a request carries an If-None-Match and never evaluates one, so advertising an ETag would cost the 304s on multi-MB pages. Hashing is cached per (path, mtime_ns, size) but only once the file's mtime is a second old — a file being written right now is re-read, which is exactly the case the header exists for. On Windows an open landing while atomic_write_text swaps the file in can raise PermissionError, which the stock handler answers with a 404; so server.py first opens the file with the writer's own retry (utils.retry_on_sharing_violation) and holds it while the stock handler serves it, because Windows will not replace a file that is held open. On a change the page re-fetches and either patches or swaps.

Patching applies when the new render's node-key sequence extends the one on screen: the nodes whose own markup changed are replaced, new ones are inserted, and everything else is left alone — keeping its scroll, fold, <details> and localised timestamps because it is literally the same DOM. Change detection is a per-node hash of the node's own markup, taken from the freshly parsed document, never from the live DOM: decoration rewrites the live tree (timestamp localisation replaces innerHTML), so a hash taken from it never matches one taken from server bytes. Nothing is emitted server-side for this.

A node's own markup is its :scope > .message plus every non-.message-node child of its .children — a fork point renders inside .children so folding hides it with the subtree, and on a fork-only slot it is the node's only content and carries its id.

Swapping (replace #transcript wholesale) is the fallback for everything else: renumbered or reordered ids, deletions, a node with no key, more than 40 changed nodes, and the first update of a session, which is where the hashes are first taken. It is also what every update did before patching existed. Measured across three real sessions replayed through the renderer, 45 of 47 growth steps are pure extensions; the other 2 are out-of-order arrivals that renumber the positional msg-d-N ids and take the swap.

A swap destroys anything that decorated the old markup, so components register with window.claudeLogOnRehydrate(fn) (defined at the top of <body>, before every component include) and the poller calls window.claudeLogRehydrate(root) — over the whole container after a swap, and over only the elements it placed after a patch. Passing the containing node instead is a live trap: the session header's fold bar counts its descendants, so it is replaced on every append, and its node is the entire page. Currently registered: timestamp localisation (scoped to a subtree), the timeline rebuild, the filter and search refresh (one microtask per update: the active type filter is re-applied and an active search re-run quietly — nothing scrolls, unfolds or opens; registered in transcript.html between the timeline and the engine so it runs after the one and before the other, minimal-theme.md § 11) and, in the minimal theme, the DAG engine's relayout (one microtask per update, before the next paint — minimal-theme.md § 8). Delegated listeners and everything bound to the toolbar or floating buttons survive untouched and must not register. On the swap path only, fold state and <details> are captured and restored by the poller, keyed data-uuid → data-session-id → positional id — session headers and fork points carry no uuid, and on a single-session page the header is the only foldable node.

Measured: ~1s from append to visible. On a 2.4MB / 896-card page, a swap touches 897 cards, re-localises 896 timestamps and blocks the main thread 107ms; a patch of the same append touches 3 cards, 2 timestamps, 61ms. The remaining 61ms is fetch plus DOMParser of the whole page, which only a server-shipped delta would remove. Idle polls cost ~1ms.

Timestamp localisation drains against the idle deadline, not in fixed batches. timezone_converter.js used 25 elements per requestIdleCallback, which made the callback count the cost: a 4MB page's 1,180 timestamps are 8ms of work but took 766ms of wall clock, and a 27MB page's 5,010 took 3.3s — in document order, so a live update's new cards were localised last and the fade-in played over a raw ISO string. Draining while timeRemaining() allows (checked per 32 elements, {timeout: 200}, first slice on the current task under a 24ms budget) takes those to 13ms and 35ms.

Following from disk gives watch without serve the same in-place update, in the same live_update.js. A file:// page cannot fetch anything, but it can frame itself, and the framed copy can postMessage what it holds back up — each file:// document is an opaque origin, so the parent can neither read the frame nor address the message to an origin, but messages pass. So pressing follow (⏬, shown from disk on any page with a card) starts a 1 s poll that loads the page's own file into a display:none iframe (?t=…#ccl-probe=<lastModified>~<token>), and releasing it stops the poll; until then nothing runs but two inert scripts (3.7KB with their comments; the transport adds 8.8KB to live_update.js). Two scripts answer inside the frame:

  • live_probe.js, first in <head>: when the file's document.lastModified equals the one the parent sent, it posts same and calls window.stop() before the body is parsed — ~10ms on a 5.8MB page. It also captures DOMContentLoaded/load on window and stops their propagation: Firefox fires both even after window.stop(), which would otherwise start the page's own scripts (this one included) inside the probe.
  • live_probe_post.js, the first script after #transcript: otherwise it posts #title + #transcript as HTML and stops the load there, so no later script runs. The parent hands that to the same applyUpdate a served page's GET goes through — patch or swap, fold and <details> state, rehydrate hooks and all. A changed page's render is in hand ~130ms (Chromium) / ~100ms (Firefox) after the frame is created on that page.

display:none is load-bearing: a 0×0 or 1×1 frame still lays the page out, in a viewport a pixel wide, and the same read took 1.3s.

Who may read it. Posting to '*' is the only option between opaque origins, so without a check any local HTML file could frame a transcript page at a predictable path (session-<id>.html) and read it — a channel file:// otherwise lacks. The frame posts content only to a parent that names the page's probe token, in <meta name='ccl-probe-token'>: page_key.probe_token(session_id), an HMAC under the install key (§ 2.19), so it is the same every time watch rewrites the page, and is found in that page and nowhere else. The first design took any card's data-uuid as the token, on the reasoning that naming one proves the caller read the file; but uuids are in the JSONL and in archive-search links (session-<id>.html?uuid=…), so a search link was enough (review on #427). Only session pages carry a token and the probe scripts (generate_session passes probe_token), so only they can be followed from disk: a combined page, with every session's cards, would have let one session's uuid read them all under the first design, and stays static from disk (over serve it follows as ever). live_probe.js reads the token into window.__cclProbeToken; live_update.js starts the disk transport only on a page that has one, and live_probe_post.js posts only to a parent that names it. Otherwise it answers refused, and the parent stops following: the file was rewritten under another install key. A guessed-exactly mtime earns same, which carries only that mtime. A page answer also names its theme (whether #transcript sits in the minimal theme's .mn-stage): an update replaces only #transcript and #title, not the styles or the shell, so a render in the other theme stops following as refused does, and the button asks for a reload (review on #427). A served page checks the fetched render the same way in applyUpdate: in the other theme it applies nothing, active is false and the button shows .live-lost, but the polls go on, so it picks up again if the archive goes back to its theme. A frame that loads and posts nothing (a page written without the probe, because watch couldn't read the key; a file missing mid-rewrite) counts as unanswered a second after its load, or at the 30 s give-up. An answering page stops its own load, and no engine fires the frame's load then (measured in Chromium, Firefox and WebKit); since nothing promises it, or orders a posted answer against that timer, a probe counted as unanswered frees the slot but keeps listening until the next probe starts, and an answer landing then is taken as usual. Three in a row mark the follow lost: .live-lost on the button, active false (so the minimal theme stops drawing agents as running), probes every 5 s. Any answer clears it. Lost, back, and beyond following are also said through a visually hidden role=status region (.live-status), since focus is usually in the transcript, not on the button. document.referrer would have been the natural check, but it is empty inside the frame in Firefox and WebKit. An http(s) page cannot frame a file:// one at all.

The one-second mtime. lastModified has one-second granularity, so a rewrite inside the second of the last read leaves it unchanged — the same trap as Last-Modified above. Until the render on screen was read at least two seconds after its mtime, the parent sends no mtime, forcing a full read, and compares the posted render with the last one itself. "When it was read" is the clock as the probe that brought that render went out (the frame reads the file after it); only a render moves it, never a same answer, and the page as loaded has none, so the first probe after pressing follow always reads in full. The clock now is not enough: a page hidden straight after a read stops probing, and a same-second rewrite meanwhile would be answered same when it is shown again seconds later, and missed for good (test_a_same_second_rewrite_while_hidden_is_seen; the page as loaded, …_before_following_is_seen).

The first read. The page on screen came from the file at load, not from a frame, so there is no posted render to compare the first read with. It is compared on what decoration never rewrites — card count, the last card's uuid, #title's text — and adopted without an update when they match. A false match (a rewrite before following that kept all three) shows at the next change.

WebKit reports the current time as a file:// document's lastModified, so the same answer never comes and every poll is a full read (~155ms of main thread on the 5.8MB page, against ~17ms in Chromium and Firefox). Three reads in a row where the mtime moved but the render did not switch the poll to every 5 s. Chromium and Firefox reach that state only through rewrites that leave the render as it was, and a same answer in between resets the count.

claudeLogLiveUpdate.active says whether the page is being kept current — always when served, from disk only while followed — and the minimal theme draws an unreturned agent as running only then; a claudelog:live event on document makes it redraw when follow is pressed or released (minimal-theme.md § 8).

Verified in Chromium 156, Firefox 157 and WebKit 27.2 (test/test_follow_from_disk.py, whose Firefox and WebKit case skips where those engines are not installed — CI installs Chromium only). Playwright's WebKit is not Safari, which adds local-file restrictions of its own.

2.16 Parsed-entry store

entry_store.py. A conversion that refreshes the cache incrementally (§2.14) parses each modified file from source, and then loads those same entries back out of the rows it has just written — once for the closure load and once for the session-scoped render (§2.12). Each rebuild is a zlib.decompress + json.loads + Pydantic validation pass over the whole file, so a one-line append to a 39.7MB session paid it twice at ~130ms each. The store holds the list the first pass produced and serves it to the other two.

Four properties keep the invalidation surface at zero, and they are the reason it is a parameter rather than a memo:

  • One store per conversion, threaded explicitly. Never a global, and never hung off CacheManager — the TUI keeps one of those across many conversions.
  • Only _incremental_cache_refresh fills it, with the files it just parsed, and convert_jsonl_to drops it after Phase 1b. A cold or full conversion therefore stores nothing, and the streaming path (§2.13) is deliberately never handed one: its bounded residency depends on dropping each page's entries before the next page loads, which a store spanning pages would defeat. What it holds is bounded by what changed, not by the archive.
  • Hits are verified against the file. get re-stats and compares (size, mtime_ns) against the stamp captured before the parse. A stamp taken before the parse can only be older than the entries describe, so a file that grew mid-parse declines to the cache rather than serving a list its stamp misdescribes. A file that grew after the refresh declines too, and the render then reads the rows the refresh committed (§ 2.3), not the file. The stamp also carries the file's sub-agent fingerprint (cache.subagents_fingerprint, which covers the agent-*.jsonl transcripts as well as the sidecars, scoped for an agent file as its cache row is — PendingStamp snapshots before the parse and finishes after it): a held trunk list includes its agents' spliced transcripts, and a running agent grows its file while the trunk sits still — a trunk-only stamp kept a watch / serve --watch store serving that block one tick behind until the trunk next changed (minimal-theme.md § 8).
  • Handouts are deep copies, because the pipeline mutates entries in place: _integrate_agent_entries appends #agent-{id} to sessionId and is not idempotent, and dedup re-parents around dropped copies. Today each consumer gets freshly deserialised objects; serving the same objects twice would render …#agent-X#agent-X. The copy stays cheap because the bulk of an entry is immutable strings, which deepcopy shares rather than copies — 2.0ms and 0.83MB for the 207-entry, 39.7MB session, against 123ms to rebuild it from the cache.

Held to byte-identity with the store disabled, over repeated appends on a fixture whose 170 sidechain entries exercise the mutation above (test/test_entry_store.py), with the copy isolation pinned by a test that fails with exactly the doubled suffix when the copy is removed. CLAUDE_CODE_LOG_ENTRY_STORE=0 is the kill switch; a per-file memory valve at put time declines to hold a file when available memory is under 6x its bytes, and =1 overrides that valve.

Owned across ticks, a store does more. watch keeps one for the life of the loop and passes it to every conversion (convert_jsonl_to takes an optional store; a caller-owned one outlives the call, an internally made one doesn't). That turns the store from a within-tick cache into a resumption point, via a second, prefix-pinned mode:

  • The parse resumes. put_prefix records the byte offset the parse consumed plus a BLAKE2b digest of the bytes below it, and the next tick hashes that prefix and reads only the tail. The digest is a stronger check than the row-fingerprint prefix comparison it saves — identical bytes imply identical rows — and it costs 32 ms over 39.7 MB against 143 ms to re-parse them. A mismatch (rewound session, replayed history) drops the prefix and re-reads from the top. Byte reading replaces text reading only when a store is present; every other caller keeps the identical text path, and the held entries are the pre-post-processing parse products, since the whole-file passes (sidecar linking, prompt-hash linking, agent splicing — 0.1 ms together) must re-run over the concatenated list. The cut is on entries as well as bytes: a final line whose newline hasn't landed — a torn append, or a file simply stored without a trailing one — parses and is returned like any other, but neither its bytes nor its entry is held, so the next tick re-reads that line instead of handing its entry back a second time. Prefixes are charged against the same budget as whole-file entries and evicted alongside them, since a watch store never goes out of scope.
  • The cache write appends. CacheManager.extend_cached_entries inserts only the new rows instead of save_cached_entries' delete-and- rewrite, which re-runs json.dumps + zlib.compress over every entry (310 ms of a tick, for one added line).

The write needs a proof the read doesn't, and it is the subtle part:

A file being append-only does not make its rows append-only. A trunk's cached rows carry its subagents' transcripts, spliced in at their anchors, so a subagent still running — the normal case under watch — grows a block in the middle of the row sequence while the trunk file only gained lines at the end.

So _appended_rows offers rows only when the list is provably just the file's own parsed lines: resumed from a verified prefix, no agent references, no sidecars, nothing spliced, and no length change from the whole-file passes. That covers 136 of the reference archive's 185 trunk files; the 26% that reference subagents take the unchanged full rewrite. Beneath it, extend_cached_entries independently refuses when the table no longer holds the row count the caller thinks it wrote — the guard against another process having rewritten them. With the gates removed the caller offers a wrong 96-entry slice and that check catches it, so the tests assert on the offer rather than only on the write. That count and the insert run inside one BEGIN IMMEDIATE, because Python's sqlite3 opens a transaction on the first write and not on a SELECT: without the explicit lock a second writer sharing the cache could append in between, and the check would let both appends land.

Both cache writers are stamped with the source file's (mtime, size) as captured before the parse — the same discipline as the sidecar fingerprint beside it, and as the entry store's own stamp. A session appended to mid-read would otherwise be recorded at the size it reached while the rows are only what was parsed, marking an incomplete cache current; stamped with what was parsed, the growth invalidates instead.

Steady-state tick on the 803MB reference archive: 0.717s → 0.257s (cumulatively 1.03s → 0.26s). Equivalence is held at three levels — parse output against the text path (162 fixture files whole-file, 90 resumed), cache DB state against a full-rewrite run over 6 ticks with 3 files growing, and rendered HTML throughout. DB state is the bar for the same reason as §2.14: the first bug of this kind is invisible in the rendered bytes.

Resumption only helps a resident loop — a one-shot run, the TUI, and every tick-one still parse whole. Persisting (prefix_len, prefix_hash) in cached_files would extend it across processes; that migration was considered and not needed for the case that motivated it.

2.17 Markdown engine

Markdown is rendered by wenmode (mistune's successor by the same author; the switch is #323). Four pipelines share one rule set, built by markdown_plugins.transcript_rules(): wenmode's github preset (wenmode ≥ 0.15.1) with strikethrough restricted to ~~two~~ through Strikethrough(allow_single_tilde=False) (prose says "~2, ~6 min" all the time), bare-URL autolinks that never link e-mail-shaped tokens (ruff@0.6.0, git@github.com:), wenmode's GFM tag filter off (every raw-HTML node is escaped by the renderer, so a half-escaped &lt;script> would be worse than none), and the definition-list plugin. Everything else is strict GFM as wenmode implements it.

pipeline where what is added
HTML, assistant/tool/web content html/utils.py::_get_markdown_renderer _TranscriptHTMLRenderer(escape=True, soft_break="br") — every soft break as <br />, mistune's hard_wrap; handlers: Pygments on fenced code with a language, escaped block-level raw HTML wrapped in <p>; the SHA-link transform
HTML, user content html/utils.py::_get_user_markdown_renderer the same pipeline as a distinct singleton (the render memo keys on which one rendered)
HTML, whole document html/utils.py::_get_document_markdown_renderer wenmode's frontmatter plugin, loading with PyYAML; used by render_markdown_document only — see Front matter below
Markdown output markdown/renderer.py::_protect_html_tags, markdown_plugins.linkify_shas_in_text no renderer at all — see below

The escape contract is not a preference. Transcript content is untrusted from every source (#245): the assistant echoes arbitrary user, file and web input verbatim. Both HTML singletons render raw HTML as entity-escaped text, and the renderer's URL policy is mistune's denylist (javascript:, vbscript:, data: except images, file:, …) rather than wenmode's allowlist — transcripts link to cci: editor targets and vercel.json:20 file references that no allowlist would anticipate, and none of those can execute script. test/test_xss_browser.py and test/test_markdown_rendering.py pin it.

Attributes need their quotes escaped, and links a fixed start. Transcript values and directory names also land inside attributes. Every link built from a project directory name or a session id goes through utils.relative_href: the index page's project, variant and session links (the rel_href Jinja filter), the recent page's payload, and search.build_link for serve's archive search. It percent-encodes each path segment, so a quote can't close the href, and starts the link with ./, so a directory named javascript:alert(1) can't read as a URL scheme. Leading empty segments are dropped, so no link is absolute or a //host network path, and a backslash is a separator only on Windows: anywhere else it is part of a directory name and is encoded, since a browser would read \\evil.example\x as //evil.example/x. The search pages write result rows as markup with escapeHtml (components/search.html, archive_search.html, whose helper minimal/search_rows.js shares), which escapes & < > " ' by string replacement: the textContent/innerHTML idiom leaves quotes alone, and the index finder reads its links back with getAttribute('href'), which decodes &#34; to ". A CSS class taken from tool input passes an allow-list instead (TodoWrite's status and priority). test/test_xss_attributes.py and test/test_xss_attributes_browser.py pin it.

Front matter is data, and only at the top of a whole body. Read as plain Markdown, the closing --- of a YAML front-matter block is a setext underline, so the block became one heading. A whole body — a message, a recap, the full view of every render_*markdown_collapsible body, a Markdown file's Read/Write content, a plan — goes through render_markdown_document. When the text opens with a block (frontmatter.is_frontmatter_start: wenmode's rule, plus the line after the opening fence must hold something, so --- then a blank line stays a horizontal rule), the document pipeline parses it once, the plugin stores the loaded value in root.data, and render_node renders the rest. A non-empty mapping shows as render_params_table above the body; anything else (a YAML error, a scalar, a list) as a YAML code block, so nothing is lost. Any other text goes to the ordinary pipeline and memo entry unchanged. Inline renders, the collapsed previews (cut from the body after the front matter) and the Markdown inside a params value never parse front matter, so a value that itself starts with --- neither recurses nor turns into a table. Loading is yaml.SafeLoader with aliases refused (they would expand exponentially when walked into a table); dates and other non-JSON scalars become strings. A block over 64 KiB, nested deeper than 32 levels, or deep enough to exhaust PyYAML's recursion is shown raw instead: one message must never fail a project's render. The Markdown output splits the block with split_frontmatter and renders it through _render_params (behind _protect_html_tags) or a yaml fence, but only for user and assistant text — narrower than the HTML side, since most other bodies are code-fenced in .md anyway.

Footnote ids are scoped per message. wenmode gives every rendered body GitHub's ids (user-content-fn-1, user-content-fnref-1, the sr-only heading footnote-label), and a page holds many bodies, so unscoped the second answer's [1] would jump to the first answer's note. The HTML render loop wraps each message's formatting in html/utils.py::footnote_scope, and every render path rewrites the ids after the memo (scope_footnote_ids: user-content-fn-<scope>-1, footnote-label-<scope>, inside the id, href and aria-describedby attributes only, so a body that mentions an id in code keeps it), so the memo stays keyed on the text. The scope is the message's fragment-store key (e<entry ordinal>-<part>), which every tree and pass agrees on, so a fragment reused from the store never repeats a freshly formatted message's ids on one page; without a store it is the message's index in its tree (m<index>). A preview copy of a long body renders in a -preview sub-scope, since the card holds both copies, and a message's second text item in an -i<n> one. The Markdown output has the same collision in its [^1] labels and prefixes them the same way ([^m<index>-1], -i<n> per later item), for user and assistant text, thinking and the heading excerpt (a thinking block's too): only the labels the text defines outside code, and only outside fenced blocks and code spans, so a regex sample [^abc] or a definition shown in a fence stays as written. A fence is read as CommonMark does: three or more backticks or tildes, indented up to three spaces, closed by at least as many of the same character, or running to the end of the text when never closed. test/test_footnote_ids.py pins both.

Extensions are transforms, not inline rules. SHA linkification (#156) runs after parsing, as a RootTransform walking Text and InlineCode nodes and skipping anything under a Link. Nothing about rule ordering, combined-regex group numbering or an in_link state flag survives from the mistune version; the transform links exactly the SHA multiset the two mistune rules did on a 5936-body corpus.

The Markdown output splices; it does not re-render. Both linkify_shas_in_text and _protect_html_tags parse with positions=True and rewrite only the byte ranges of the nodes they care about (a resolvable SHA; a raw-HTML node, or a < in plain text that a lax viewer could take as a tag start). Everything else in the text — escapes, fence characters, autolinks, snake_case — survives byte for byte, which the mistune MarkdownRenderer round-trip did not guarantee and which wenmode's own Markdown renderer would not either (it backslash-escapes _, [, |, * in text: measured at 217 of 531 real bodies touched).

Every Markdown body passes one gate. _render_message runs each formatter's output — built-in or plugin format_markdown — through _gate_body, the body counterpart of the heading gate (safe_markdown_inline), so a formatter that interpolates transcript text without escaping it still cannot leave live markup in the .md (GHSA-3jq4-r9jm-q682: before the gate, escaping was a per-formatter choice that assistant text, thinking and most tool bodies never made). The renderer's own tags — <details>, <summary>, <code>, session anchors, table-cell <br> — are written through _own_tag, which hides them from the gate behind a marker carrying a random per-process token; transcript text cannot forge it. A formatter's return value is therefore only final after the gate. test/test_xss_markdown_surfaces.py taints every text field of every test/test_data fixture and asserts the rendered .md parses with no live payload tag.

The gate judges each body alone, but the .md is read as one document, so the gate then seals the body (_seal_body): it is made to parse in the document exactly as it parsed alone. Two things would otherwise move a body's raw code into prose. A fence the body leaves open would be closed by the next body's opening fence, putting that body's fenced HTML outside it. An indented first line would continue a list item or footnote the previous body ended in (the TodoWrite checklist followed by its result is one such pair). So an open top-level fence is closed with its own character and length, and a body that starts indented gets a <!-- --> line first, the CommonMark idiom for ending a list. Any other body starts at column 0 after a blank line, and that closes every block the previous body could leave open (the gate leaves no HTML block open). The test file checks a matrix of open endings × code-holding starts with wenmode and markdown-it.

wenmode doesn't get the last word on what is code. Everything above trusts the gate's parser to tell code from prose, and viewers' parsers disagree with it, inline code most of all: a GFM table splits a code span at a pipe, a bare-URL autolink (VS Code's preview) swallows its opening backtick, an image's alt text ends it early. So:

  • A code span holding < is rewritten as the renderer's own <code> element with its text entity-encoded (_code_span_as_html): it renders the same in GitHub, VS Code and Obsidian, and no transcript < is left outside fenced or indented code for any parser to misread. The exception is a line opening with three backticks, which the span's backticks keep from being a fence opener: there the span stays, with its < as &lt;.
  • A multi-line HTML block is opened rather than escaped whole (_open_html_blocks): only the < that starts it is escaped and the text parsed again, so a fence inside stays code, a code span inside gets the rewrite above, and inner tags are escaped as tags. Its text then reads as Markdown, as MDX-style content means it to.
  • Line endings are normalised first (_normalize_breaks): wenmode ends lines on \u2028, \x0b, \x85 and the like where CommonMark doesn't. Headings and labels are kept to one line (safe_markdown_label), link labels also get their brackets escaped (safe_markdown_link_label), and a <summary> is HTML-escaped around our own tags.
  • A link or image with a harmful target (the HTML renderer's scheme denylist, html.utils.is_harmful_url) is rewritten as the literal text it was written as, and a reference definition with one is broken where it's written, since its use may sit in another body. WebSearch result URLs go through _markdown_safe_url; index link targets start with ./ and are percent-encoded (_relative_md_target).
  • A second opinion (neutralise_foreign_html): markdown-it in two configurations (CommonMark with tables, and gfm-like with linkify and footnotes) parses each gated body, each label and the finished document. If either finds raw HTML that isn't one of our own tags (_OWN_HTML_RE), or fails to parse, every tag-like < that doesn't start one is escaped, code included. Over a 7.6 GB archive of real transcripts it never fired.

The sweep in test/test_xss_markdown_surfaces.py taints every field in fourteen shapes, each a known disagreement or link trick, and judges the .md with three viewer configurations (one with Obsidian-style plugins the gate doesn't use, with markdown-it's own link filter off). On the same archive, against main: no errors, and the visible text differs only where raw HTML is now shown as text, links and code that were broken now render, and fences inside HTML blocks render as code. Markdown export takes about twice the CPU.

The wenmode pin is deliberate. wenmode>=0.15.1,<0.16: the extensions subclass wenmode rules and renderers, so a minor bump is a re-tested step, not a lockfile refresh. 0.15.1 fixed the five parser bugs found during the migration and added the soft_break and allow_single_tilde options, which replaced three local workarounds; test/test_markdown_rendering.py pins each of those behaviours, and work/wenmode-evaluation.md records the method for re-measuring a bump against real transcripts.

2.18 Recent sessions page

recent.html sits next to index.html and lists the sessions updated in the last WINDOW_DAYS (3) across every project, newest first, at most MAX_SESSIONS (60). It is a separate page rather than a view of the index because it carries per-session turn data and last messages, ticks in the browser, and goes stale on its own schedule; the index only links to it (one line in each theme).

Data. recent.build_recent_payload runs one query over the shared cache — sessions JOIN projects, hidden = 0, not run in a temp dir, newest last_timestamp first — then loads each listed session's entries from the cache (CacheManager.load_session_entries, read-only) and summarises them in summarise_session. No schema change: everything is derived from rows the cache already holds, so archived sessions work too. A turn runs from a prompt you typed (_user_text excludes tool results, meta entries and injected bodies such as task notifications and command output) to the last entry before the next one; a compaction's summary (COMPACTED_SUMMARY_PREFIX) is skipped outright, neither a prompt nor activity, since Claude Code also compacts idle sessions and the summary would otherwise be a turn with no reply (mid-turn) or stretch the last bar across the idle gap. A turn ends ask (the last reply's last line ends with ?, or a call that waits on you has no result yet: AskUserQuestion, whose questions and options _questions_markdown writes out as the last message, who: "question", or ExitPlanMode, whose plan becomes it, who: "plan"; see _waits_on_you), err (a <synthetic> reply or API Error… text), open (the final turn ends on a tool call or result) or asst. The session's state follows its final turn: asked, error, busy or done. Sidechain entries are skipped. Only turns that ended within TURN_HORIZON_HOURS (24) are sent; the rest are counted in earlierTurns. Each sent turn carries SNIPPET_CHARS (200) of its prompt and of how it ended, which the strip's markers show on hover. The last prompt, and the last message when Claude wrote it, carry html in place of text (the data file is reloaded every 3 s, so it holds one form, not both): the clipped text rendered by render_user_markdown / render_markdown, the session pages' escaping pipeline (§ 2.17). Tool lines and errors stay plain text.

These are transcript states, not liveness: nothing here can tell an agent that stopped from one waiting quietly.

Temp-dir sessions. A session whose cwd is a temp dir (utils.is_temp_session: its cwd, else its project folder's decoded name, against the fixed roots in utils._TEMP_ROOTS plus Windows' AppData\Local\Temp; deliberately not $TMPDIR, which tools point at odd places) is test-suite, scratchpad-agent or scripted-run debris. The query leaves it out with ccl_is_temp_session, a Python function registered on the read-only connection (recent._temp_filter), so the filter runs before LIMIT: dropping rows afterwards would let a burst of them crowd real sessions off the page. A date window's candidates are keyed rather than queried, so they are matched against _temp_session_keys (one pass over the sessions table, the same classification) before their MAX_SESSIONS cut. --show-temp-projects (CLAUDE_CODE_LOG_SHOW_TEMP_PROJECTS) turns the filter off; it reaches the page through process_projects_hierarchy → _write_recent_page, and watch's per-tick write_recent_data. The index's side is in renderer.prepare_projects_index: it drops projects with nothing to open (has_nothing_to_open: no message and no listable session) from the rows and the totals, and flags each remaining project is_temporary (utils.is_temp_project: every working dir a temp dir; with none recorded, the folder name decides). The HTML index (both themes, flat list or --expand-paths tree) renders the flagged ones after the list in one collapsed <details class='temp-projects'>, the Markdown index under a Temporary directories line at the end, and the JSON index lists every project as data. With no temp project the markup is byte-identical to before.

Background work. background_work.BackgroundWork collects what a session ran in the background as summarise_session feeds it entries; its module docstring records how each kind shows up in real transcripts. Background commands, async agents and monitors are found by the id their tool result names (toolUseResult.backgroundTaskId / agentId / taskId, or the same id in the result text; Bash by its result, since a command that outlives its timeout is backgrounded without the flag), and end at the <task-notification> naming that id with a final status, a TaskStop/KillShell/KillBash on it, or (a monitor) an expiry event. An agent's "waiting on its own background work" notification is interim, but when that agent later reports by SubagentHandback, the final notification keeps the same summary, so only its <result> (the report "was delivered to you") marks the end. Notifications are found by search, not prefix (some open with a [SYSTEM NOTIFICATION …] preamble), in user entries and in queued_command attachments. Pending wake-ups come from ScheduleWakeup's toolUseResult.scheduledFor (exactly the fire time) and leave at the system entry with subtype scheduled_task_fire nearest them; a {stop: true} call cancels them. Cron jobs are not drawn.

A notification delivered while Claude is idle (a user entry) and a wake-up firing each start a turn (origin task / wake, the turn tuple's sixth field), labelled with what reported or the wake-up's reason; a notification mid-turn (an attachment) only ends its work. Your last prompt stays the last one you typed. The payload carries bg: [[start, end|null, kind, status|null, label, expiresAt|null]], wakes: [[at, label]] and the policy constants bgCapMinutes (60) and wakeGraceMinutes (5). The page applies them against its own clock, so a data file that stops changing still ages: work with no end recorded counts as running until the session's last entry plus the cap (or a monitor's expiry, if sooner), then shows as no end recorded; a wake-up is pending until its time plus the grace.

The process exiting. /exit (or any way out) writes no entry, only a trailing cost-state line: no uuid and no timestamp, so the parser drops it (SILENT_SKIP_TYPES) and the cache never holds it. recent.session_exit reads it from the session file's tail instead, on every build and outside the RecentMemo (the line doesn't move the memo key). The process has exited when a cost-state comes after every entry with a uuid (and every queued notification); only metadata lines follow an exit that stuck, while a resume adds entries. The exit is dated startTime + totalDuration, but never before the session's last entry, because a resumed session's figures can add up to an earlier time. SessionSummary.at(now, exited_at) then settles the row: work with no end ends exited at the exit (the page shows ended with the session), pending wake-ups are dropped, and an open final turn is over (busy becomes done). Only the last exit counts. If a session was resumed after an earlier exit, the work that exit killed keeps the usual cap.

A session whose transcript state is done but which has running work or a pending wake-up is shown as waiting (background), which leaves the your move filter.

Writing. converter._write_recent_page runs after the index on every HTML hierarchy run. It takes each session's link from the index's own sessions[].file entries, so --output, --expand-paths and variant filenames resolve as the index's do, and writes recent-data.js then recent.html. A failure there is reported and never fails the run. Under --combined only the rows get no link: the index still names each session's file, but nothing writes it. The watch's per-tick refresh (recent.write_recent_data) follows the same rule with session_pages.

Self-refresh on file://. A page opened as a file cannot fetch (see live_update.js), but it can add a <script>. So recent.html holds no data at all: it loads recent-data.js with a plain script tag on open, then re-adds <script src="recent-data.js?t=…"> every 3 s (while the tab is visible). A reload costs ~2ms on a real archive's 4.9KB of data and 14–26ms at the 2.16MB the caps allow (60 sessions, each at every cap), headless Chromium/Firefox/WebKit medians, so it reloads unconditionally: under 1% of a core either way, with no change detection to get wrong. (Reading the page through a frame of itself, as a transcript page followed from disk does, measured dearer at every size but the largest, and would put the data in the page.) The file calls window.__cclRecent(payload) (its JSON made by payload_json, which escapes <), and the page redraws its rows in place, keeping open rows, filters and scroll. Keeping data out of the page also makes the page identical from run to run, which the parallel-vs-sequential output test relies on; only the data file carries the time it was written (the page's staleness notice reads it).

The data is encrypted. A script is run, not read, so same-origin rules don't protect it: any page can include recent-data.js and receive what it passes to whatever window.__cclRecent that page defines. Measured on main before this: a page on another site got every recent session from a running serve, and a page saved in ~/Downloads got them from disk by relative path (../.claude/projects/recent-data.js) in Chromium and WebKit. So the file passes ciphertext (recent.recent_data_js, page_key.encrypt_recent), and recent.html carries the key in <meta name='ccl-recent-key'>: page_key.recent_key(), derived from the install key (§ 2.19), so the page is still the same on every run. Another page can run the file but not read the key: an HTML file can't be run as a script, and file:// pages can't read each other. The cipher is the standard library's, since Python has no AES without a dependency: an HKDF-SHA256 keystream (salt: a fresh 16-byte nonce per write, info: the chunk's 4-byte index) in chunks of 8,160 bytes, the longest output HKDF has, XORed in. WebCrypto derives each chunk in one call in every engine (PBKDF2 was the first choice, but Firefox refuses its outputs past 256 bytes). It takes 0.8 ms to encrypt a typical 5 KB payload and 88 ms at the 2.5 MB cap; decrypting the cap takes 7–19 ms. Confidentiality is all it gives, which is the threat: a page that could write the file could do worse. recent.js decrypts a string payload and still applies an object at once (the browser tests drive it that way); loads decrypt asynchronously, so only the newest is drawn, and the empty state waits while one is pending. A page whose key no longer matches (the key file was replaced) logs an error until the next full run rewrites it. test_recent_secrecy_browser.py replays the ~/Downloads page in every engine installed. Row content is built with DOM APIs and textContent: titles and messages are untrusted transcript text. The one exception is the payload's html fields, which go in through a single helper (renderedMarkdown in recent.js) and nowhere else; they carry exactly the trust of a session page's message body, since the same pipeline escaped them. test_recent_page.py pins both halves: one innerHTML, fed only from .html fields. The page includes both Pygments sheets, and its <body> carries theme-minimal so the classic sheet reads the minimal tokens and the dark sheet's scope matches.

Motion. Opening or closing a row, and a refresh or clock tick that moves rows, animate by FLIP (flip in recent.js): measure every row and group heading as drawn, make the change, measure again, then play each part back from where it was with the Web Animations API. A move is a transform (a row moving up is drawn above the rows it passes), a row that grew is revealed by clip-path, and a new row or an open row's new prompt or last message fades in (drawPanel marks those parts; the rest of the redrawn panel doesn't fade). A closing panel goes at once; an inert, aria-hidden copy (.rc-ghost) stays drawn where it was and fades while the rows below slide up over it, which is why rows carry an opaque background (--rc-surface). Rows animate only paint properties; the one layout-driven animation is the list's own height, so the card's edge and the legend move with the rows. Every motion comes from one before/after measurement, so a mid-motion change measures what is drawn (a running reveal's clip included) and carries on from there. Only parts on screen move, the first draw and filter/grouping changes are instant, and prefers-reduced-motion turns it all off. test_recent_browser.py reads document.getAnimations() straight after a synchronous window.__cclRecent(payload) to pin which part animates what.

End to end. test/recent_live_fixture.py (RecentLive) writes sessions in four projects as real JSONL, one in each state the page tells apart, and moves them on stage by stage (a tool call, a finish, a question, a new session, background work reporting back), converting each stage with the full run. test/test_recent_live_browser.py opens the page from disk and checks each stage's order, states and counts; the fixture's wait_for_stage prompts the page to reload its data file with a visibilitychange instead of waiting for its 15 s tick. The same stages are the recent sessions demo chapter and beat and just recent-play.

cli.watch calls recent.write_recent_data after each single-project tick (default layout only: no --output, and the watched project inside the projects directory), since that path never rewrites the index; watch --all-projects gets the page from the hierarchy run. The loop keeps one recent.RecentMemo for its life. A session's SessionSummary (read_session: every turn, its background work, the rendered last prompt and message) is a function of its entries alone, so the memo keeps it keyed on a fingerprint of exactly the cached rows load_session_entries reads — their count and highest id, fetched in the session-rows query through idx_messages_project_session_ts — and a tick re-reads only the sessions whose fingerprint moved. (Not the session row's last_timestamp / message_count: those skip attachments, and an attachment can end background work.) the clock (SessionSummary.at: the turn horizon, which background items and wake-ups are shown) is applied on every build, so a kept summary never serves a stale horizon. Sessions that leave the list are dropped. Reading entries back from the cache is nearly all of a build's cost: on a real archive a tick's rewrite went from 0.53s (9 sessions, 22k entries) to about 10ms.


2.19 The install key

page_key.py holds one random 32-byte key per install, for the two things the output must keep from other local pages: the recent page's data (§ 2.18) and a session page's probe token (§ 2.15). A page opened from file:// can't fetch another file, but it can run one as a script and frame another page, and an HTML file the reader opens locally (a download, an attachment) is all an attacker needs.

The key lives in ~/.claude-code-log/page.key (64 hex digits, mode 0600), or wherever CLAUDE_CODE_LOG_KEY_FILE says. It is made on first use with O_EXCL, so render workers starting at once agree on one; a file that holds no key is an error rather than a reason to make a new one, since every page made with the old key would stop working. It is never written into the output, and a local page can't read it: it is neither script nor page. What the pages carry is derived from it with HMAC-SHA256 under a label per use (probe:<session id>, recent-data), so the pages are the same on every run and what one page holds reveals nothing of the rest. The tests fix the key (test/test_data/page-key.txt, set in conftest.py), so snapshots and the equivalence checks see the same pages in every worker.

Without a key to be had (a read-only home, a damaged file), nothing fails: session pages are written without a token, static from disk like a combined page (probe_token_or_none says so once on stderr), and the recent page's write is reported and skipped, as any failure there is.

Deleting the key file makes a new key on the next run. Pages written since then carry the new key; a session page still open from before gets refused and stops following, and recent.html can't read its data until the next full run rewrites it.

3. Data lifecycle

                 ┌──────────────────┐
                 │  JSONL file(s)   │
                 │ (~/.claude/...)  │
                 └────────┬─────────┘
                          │
                  parser.py + factories/
                          │
                          ▼
              ┌───────────────────────┐
              │ list[TranscriptEntry] │  (typed Pydantic models)
              └───────────┬───────────┘
                          │
                  factories/ dispatch
                          │
                          ▼
            ┌─────────────────────────┐
            │ list[TemplateMessage]   │  (each carrying a typed
            │  with MessageContent    │   MessageContent variant)
            └─────────────┬───────────┘
                          │
              renderer.py (generate_template_messages):
                build DAG → pair → reorder → relocate
                subagent blocks → build hierarchy →
                cleanup sidechain dups → populate caches
                          │
                          ▼
               ┌──────────────────────┐
               │ Tree of TemplateMsg  │
               │  + RenderingContext  │  (caches: teammate_colors,
               │  + nav data          │   task_subjects, etc.)
               └──────────┬───────────┘
                          │
      ┌────────────┬─────────────┴─────────────┬────────────┐
      ▼            ▼                           ▼            ▼
html/renderer.py   markdown/renderer.py    json/renderer.py
      │                  │                      │
      ▼                  ▼                      ▼
 index.html +        *.md                   combined_transcripts.json
 session-*.html      (single file)          session-*.json
                                            all-projects-summary.json
      │                  │                      │
      └──────────────────┼──────────────────────┘
                         │
              ┌──────────┴────────────┐
              ▼                       ▼
          cache.py              image_export.py
          (SQLite)              (HTML / Markdown only —
                                 JSON serialises paths)

Cache reads/writes happen in parallel with the main pipeline: cache.py is consulted before parsing (cache hit → skip parse), after rendering (write the rendered HTML), and during TUI navigation (the TUI never re-parses).

Ids are checked where entries are read. A transcript's sessionId and agentId become file names (session-<id>.html, <id>.jsonl, agent-<id>.jsonl), the claude --resume argument, links and Textual markup, and they are as untrusted as the content. Claude Code writes UUIDs and short hex ids, so transcript_ids.py holds them to [A-Za-z0-9][A-Za-z0-9._-]{0,127}; a session id may also carry the loader's own #agent-<id> suffixes (agents.md), which reach the cache. sanitize_entry_ids replaces an invalid sessionId, agentId, spawnedAgentId or toolUseResult.agentId with quarantined-<hash>: stable, so the bad session's entries still group and render, under a name nothing downstream can misread. It runs in the JSONL parse loop (which warns on stderr with the file and line, never the value) and in create_transcript_entry, which every cache row passes through on load; the Codex provider applies the same rule to a rollout's thread id. The sinks check again, because a cache built elsewhere never meets the parser: session_path and session_file_name refuse a non-plain id, agent-file lookups skip one, the TUI resumes with claude --resume=<id> (attached, so the id can't be read as another option), a cached page path is deleted only when it is a bare combined_transcripts* name, and --expand-paths drops .. from a recorded cwd and skips a project that would still land outside -o. The parse loop's warning is printed even in a silent (--all-projects) run. Caches built before 1.7.1 are rebuilt once (§ 2.3), since their derived rows hold the original ids.

The TUI never splices a transcript or path value into Textual markup: Rich's escape misses tags Textual's own parser accepts ([ @click=…] with a leading space, [$var]), and malformed markup raises. Labelled values go through Content.from_markup("[bold]…[/bold] $value", value=…), and notifications and plain Statics that carry data use markup=False; only DataTable cells, which Rich parses, keep Rich's escaper. A quarantined session is listed as current while a file it came from (the cache's session-to-file map) exists, is shown by its hash with a [QUARANTINED] marker, and can't be resumed, archived or restored: it has no <id>.jsonl of its own. Table rows are keyed by the full session id, so selection never depends on the displayed prefix.


4. Cross-cutting glossary

Terms that appear across multiple subsystems — defined once here.

  • TranscriptEntry: typed Pydantic model for a single line in the source JSONL. Variants: User, Assistant, Summary, System, Passthrough, QueueOperation. See parser.py and models.py.

  • MessageContent: render-time content variant produced by the factories from TranscriptEntry. Many flavours (UserTextMessage, ToolUseMessage, TeammateMessage, …). One TranscriptEntry may yield multiple MessageContents (a single assistant turn with N tool_uses produces N+1 messages). See messages.md for the full taxonomy.

  • TemplateMessage: the render-time wrapper around a MessageContent. Carries message_index, parent/child links, pair_first/pair_middle/pair_last, ancestry, and the renderer-format CSS classes. Defined in renderer.py.

  • RenderingContext: mutable cache attached to one render pass. Holds the message registry plus nested per-session caches (teammate_colors, task_subjects, task_id_for_tool_use, session_first_message, etc.). Caches are session-scoped because combined-transcripts mode merges multiple sessions and per-session identifiers (teammate_id, task_id) aren't globally unique.

  • session_id: the JSONL's sessionId field. Often a UUID string. In some renderer paths a synthetic form is used:

  • {trunk}#agent-{agentId} for sub-agent transcripts (so they form a separate DAG-line attached to their spawning trunk).
  • {trunk}@{first_uuid_prefix} for branch sessions (rewinds / parallel-tool_use forks). See dag.md.

  • render_session_id: the session id that should be used when walking ctx.messages to find content for rendering, accounting for synthetic rewrites.

  • sidechain: a sub-agent's transcript entries are flagged isSidechain: true. The DAG layer integrates them into the parent session's tree under the spawning Task/Agent tool_use anchor. See agents.md, dag.md.

  • agent_id: identifier copied from a Task/Agent tool_result (either toolUseResult.agentId or parsed from the Markdown metadata tail). Used to stitch sub-agent JSONL files into the trunk DAG. See agents.md.

  • workflow run: one execution of the Workflow tool — a JS orchestrator fanning out into phase-grouped side-channel sub-agents, left on disk under <sid>/subagents/workflows/<runId>/. Parsed by workflow.py into a WorkflowRun and spliced into the message tree at the Workflow tool_use site. See workflows.md.

  • fork point / branch: when a session has multiple children with the same parent, the parent is the fork point and each child initiates a branch. Real forks come from /exit rewinds; spurious forks (parallel tool_uses, structural-only siblings) are collapsed by _walk_session_with_forks. See dag.md.

  • SessionHeaderMessage: the synthetic content type produced for every session boundary in the rendered output — the header that appears above each session's first real message. Two flavours: trunk headers for top-level sessions, and branch headers for fork branches (the "branch heading" you'll see referenced in bug reports). Both headers are constructed by _build_trunk_header / _build_branch_header (in renderer.py); the branch header's title is composed by _branch_label in the shape Branch • <uuid8> • <preview>, with the preview computed once by scanning the branch's DAG-line uuids for the first user entry with text (via extract_text_content in parser.py + create_session_preview in utils.py, which calls simplify_command_tags to strip raw <command-name> XML soup down to /cmd). When troubleshooting branch-heading rendering, those are the functions to inspect.

  • pair_first / pair_middle / pair_last: a pair of messages rendered as one logical unit (tool_use + tool_result, Slash + UserSlash, thinking + assistant). pair_middle exists for triples — currently the slash-command (UserSlash → Slash → CommandOutput) shape.

  • depth: see § 2.6.

  • detail-aware tools: the curated set of tools whose I/O survives --depth agent because they convey what the agent did, not what it read (WebSearch, WebFetch, Task, Agent).

  • passthrough: a PassthroughTranscriptEntry is a non-conversation entry (hook callbacks, progress updates, last-prompt markers). The DAG layer keeps them in the structure but the renderer typically hides them.


5. Where to start reading

Common entry questions and their best first stop:

  • "How does a JSONL line become an HTML row?" → rendering-architecture.md.
  • "Why are forks rendered weirdly / what is a branch session?" → dag.md.
  • "What message types exist and what do they look like?" → messages.md plus the samples in messages/.
  • "I want to add support for a new Claude Code tool." → implementing-a-tool-renderer.md.
  • "I want to write a third-party plugin (e.g. for an MCP tool we don't ship)." → plugins.md.
  • "How does folding / collapsible content work?" → message-hierarchy.md.
  • "What CSS classes does a message div get?" → css-classes.md.
  • "How are sub-agent transcripts (sync, async, teammates) integrated?" → agents.md, then teammates.md for the teammates-specific machinery.
  • "How does a dynamic-workflow run (phases, agents, orchestrator script) get rendered?" → workflows.md.
  • "I want to extend the cache / change the schema." → § 2.3, § 2.4 here, then read the migration files in order.
  • "How do I export to JSON for downstream tooling?" → § 2.5 here (and --format json from § 2.1).
  • "claude-code-log is hung — how do I see what it's doing?" → § 2.11 (SIGUSR1 stack dump).
  • "What's planned but not implemented?" → work/ — each .md is an in-flight or proposed plan.