# Flashback — Claude Code adapter
<!--
ref: @protocol/flashback-claude-code
type: protocol
tags: [flashback, claude-code, hooks, session, transcripts, cost]
triggers: [flashback on claude code, session start hook clear, transcript location claude code]
complements: [@protocol/flashback, @protocol/memento]
version: 7
updated_at: 2026-10-24T21:11:05.744Z
-->
How `@protocol/flashback` is wired into Claude Code — the paths, the hook contract, the flags that make the model pass cheap, and the numbers measured 2026-09-06.
## Where things are
- Transcripts: `~/.claude/projects/<cwd-with-slashes-as-dashes>/<session-id>.jsonl`, one per session, appended per turn, never deleted. Subagent sidechains sit under `<session-id>/subagents/`. Compaction keeps the pre-compaction turns on disk.
- Live registry: `~/.claude/sessions/<pid>.json` — `cwd`, `sessionId` (current; overwritten on clear), `procStart`, `tmux` pane. The prior life is the transcript for that cwd that began after `procStart` and ended at or before the current session's first timestamp, ending closest to it.
- Hooks: `~/.claude/settings.json` → `Stop` (async) and `SessionEnd` (async) spawn a detached index; `SessionStart` with `matcher: "startup|clear"` (sync, timeout 5) prints the flashback screen. `flashback install` writes these idempotently and backs the file up first.
- Store: `~/.flashback/<cwd-slug>/<session-id>/`.
## Record shapes the parser relies on
`type ∈ user | assistant` with `message.content` as a string or blocks (`text`, `tool_use`, `tool_result`, `thinking`); `uuid`, `timestamp`, `cwd`, `isSidechain`, `isMeta`, `isCompactSummary`. Bookkeeping records that carry a free index: `ai-title` (session title), `last-prompt`, `file-history-delta` (`trackingPath` = file touched). Thinking blocks are `{"thinking":"","signature":…}` — empty.
## The stripped model call
```
claude -p --model haiku --tools "" --no-session-persistence --output-format json \
--system-prompt "<prompt file>" --setting-sources= --strict-mcp-config --mcp-config '{"mcpServers":{}}'
env MAX_THINKING_TOKENS=0 FLASHBACK_INDEXING=1
```
| variant | overhead tokens | cost for "OK" |
|---|---|---|
| default `claude -p --tools ""` | 27,756 cached | $0.056 |
| + `--setting-sources= --strict-mcp-config --mcp-config {}` | 237 | $0.0016 |
| `--bare` | — | fails: skips the keychain, OAuth gets "Not logged in" |
Empty setting sources also means no hooks load inside the call — that, plus the env marker, is the recursion guard. Thinking off: a pass went from $0.11 / 200 s / 16.6k output tokens to $0.04 / 35 s / 2.6k with the same 1,100-word result.
## Measured latency (one machine, 129 transcripts, 311 MB in one project)
| path | before | after |
|---|---|---|
| locate prior life (read every transcript fully) | 0.93 s | ~0.03 s (head + tail of each file) |
| SessionStart:clear hook end to end | 0.62 s | 0.07 s |
| `flashback boot` | — | 0.26 s, ≤12 lines |
| parse largest transcript (28 MB) for a card | — | 0.10 s |
| control on the shipped fixture | — | 18 s, $0.025 |
## Gotchas met while building
- Haiku **declines** a long or "in-flight" transcript nondeterministically (two different rationales on the same fixture). The prompt opens with the batch-indexer framing and the reply must begin with the first file marker; the tool retries once on a reply with no files.
- A small model cites `[#N]` as often as `[#N uuid]` and mixes turn numbers with uuids in spans. The tool normalizes both; the prompt asks for integers.
- Assistant prose was cut at 1,500 chars; the final wrap-up turn is the densest prose in a session and the control's dead end sat at char 3,554 of it. Cut is 6,000 now; input grew 20 → 23 KB.
- On a busy machine `Stop` events can run 60–225/day; exclude scheduled engines via `<root>/skip` when they stop every few minutes and keep their own digests.
- The hook must exit 0 always and log errors to a file: it fires in every session on the machine, including the engines.
---
*Related: `@content/web/xinyadu/2026-11-29-claude-code-task-framing-study` · `@integrations/agent-browser` · `@content/web/github/2026-11-27-resume-command-osc-7577-issue-112408` · `@content/web/github/2026-11-26-opus-context-fills-faster-issue-112194` · `@content/web/github/2026-11-26-interactive-session-misclassified-background-issue-112133`*
---
*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*
*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*