# Flashback
<!--
ref: @protocol/flashback
type: protocol
tags: [flashback, session, context, memory, hand-off, compaction, cost, engines, hooks]
triggers: [flashback, session cleared, new session needs bearings, what was I working on, prior session context, where are the bodies buried, engine context reset]
trigger_prompt: When a session starts after a clear, or any engine needs what an earlier session in the same directory knew, without reloading that session's context.
complements: [@protocol/memento, @protocol/flashback-claude-code, @protocol/orchestrate, @protocol/context-tuning]
version: 8
updated_at: 2026-10-24T21:10:52.925Z
files: [flashback-fixture.jsonl, flashback-prompt.md, flashback.py]
-->

An engine's memory of its previous sessions, indexed cheaply on disk so a fresh context gets its bearings in one call and pulls detail only when the work needs it — so clearing context never makes the engine dumb.

## Why this exists

Every engine has to shed context, and the moment it does it forgets what it was doing, what it decided, and where the bodies are buried. The transcript is still on disk — every human turn, every line of prose, every tool call — but a fresh session does not know which of forty old sessions matters, and loading one whole costs more than the work it would inform.

Three facts shape the design:

- **The transcript is the ceiling.** Resume, salvage, memento — all read the same file. Model *reasoning* is not in it (thinking persists as an empty signature block: measured 0% for opus/sonnet, <1% for fable across 111k blocks). What was never said aloud is gone for every method.
- **The work is on the read side.** Indexing what was said is not hard reasoning; it is cheap-model work that must never land in the live window. What the live session needs is a *decision* — is there anything here for what I am about to do — and that should cost ~80 tokens.
- **A clear is usually a switch.** The operator often clears to do something unrelated. Anything pushed at boot is bloat re-read on every turn; the past must be *pulled*, by the work, when it turns out to touch it.

## The contract

Any engine that implements Flashback provides these seven things. The Claude Code implementation is `@protocol/flashback-claude-code`; Hermes and OpenClaw get their own adapter entries when built.

**1. Every session leaves a card, free.** On every stop, rewrite `card.json`: title, time span, turn counts, files touched, first and last human prompt, engine, pane. No model call. This is what listings read.

**2. A session that ends leaves an index, once.** When the session ends or the pane clears, one cheap model pass over tiers A+B writes four layers:

```
manifest.md     ~80 tokens   is there anything here for me? Always safe to load.
index.md       ~400 tokens   Rulings (verbatim) · Reasoning (decision, why, rejected, TRAPs)
                             · Topics · Open · Dead ends · Where the bodies are buried
topics/*.md    on demand     one topic each
spans.json     addressing    topic -> transcript turn ids, so every claim drills to source
```

Passes are never on a clock. A crash guard fires when 50 turns sit unindexed. A session that stops fifty times pays for one pass.

**3. Tiers decide what is kept.** A = human turns, verbatim. B = assistant prose and tool-call signatures. C = tool results: dropped, never summarized — the repo is a fresher source and a summarized observation is a stale copy. D = reasoning: unrecoverable, so **the engine says its judgment calls aloud**, one line each, at the moment it makes them. That line is the only copy that will ever exist, and the index's Reasoning section is where it lands.

**4. Boot is one call, one screen.** `flashback boot`: the session this pane just left (one line), then the recent sessions in this directory, one line each. Under twelve lines, under a third of a second. Nothing deeper is pushed. A session's line carries its title, unless that title is shared by another session here — a repeated boot prompt (e.g. every scheduled engine booted with the same setup line) names none of them — in which case the line shows what that run did: the gist from its manifest header and the slug of the resume note it wrote, `gist ⇢ hand-off`. On a clear, the hook prints only the first line.

**5. The prior life is located by process identity, never by mtime.** A live sibling session in the same repo is written more recently than the one just cleared; mtime picks the wrong pane and the result is a coherent index of someone else's work with nothing announcing the error (measured 2026-09-03).

**6. Degenerate output is rejected, never published.** A present-but-worthless index reads as "checked, nothing here". Spans must resolve to real turns, the index must cite turns and carry Reasoning, the manifest stays under 140 words; failures land in `.rejected/` with the reason on the card. A **known-answer control** ships with the tool: a synthetic transcript with planted facts (a ruling, a decision with a rejected alternative, a false-lead trap, an abandoned attempt, a file, an issue number) that the real pipeline must recover. Run it after touching the prompt.

**7. The model call is stripped to the bone.** No tools, no settings, no memory, no MCP, no thinking, a small model. Measured on Claude Code: the harness defaults cost 27.7k tokens before the first word; stripped, 237. Thinking was 14k of a 16k-token output. A pass is now ~$0.03–0.13 by session length, 20–70 s, off the critical path.

## Reading a past life

```
flashback boot                       bearings: prior session here + recent sessions in this cwd
flashback explore [--since 30d] [--grep term] [--show ID] [--html]
flashback read [--session ID]        manifest    · --index · <topic> · --span <topic> [--raw] · --list
```

Manifest → index → topic → span. Each step is a decision the work makes, not the boot. `--span` replays the raw turns; `--raw` adds archived tool results, labelled as observations true at a time, never as current state.

Marks on the boot and explore screens: ● indexed · ○ card only · ✗ pass rejected (the reason and the retry command are printed beside it) · ◐ indexing now (`read` waits for it, up to 150 s). Two backstops, neither on a clock: `flashback recover` republishes a rejected output that the current parser accepts, with no model call (measured 2026-09-15: 8 of 10 rejections were haiku's closing fence after spans.json, and 11 sessions came back free once the parser tolerated it); `flashback sweep --since 3d` final-passes ended sessions the hooks never saw end — pane kills, jetsam — skipping live sessions by registry identity, and every session startup spawns one with `--limit 3` so the fleet heals itself.

## Invoking a flashback

**You do not call it.** The flashback is printed into the session's context by the engine's session-start hook, on `startup` and on `clear`, before the first prompt: the session this pane just left (one line, clear only), then the recent sessions in this directory, one line each. It is a table of contents, ~300 tokens; a session that is switching topics ignores it at no cost. `/clear` on Claude Code takes no arguments — `/clear flashback` simply clears (verified 2026-09-09) — and none is needed: every clear already flashes back.

On demand, in any session: `flashback boot` (the same screen), then pull by layer — `flashback read --session ID` (manifest) → `--index` → `<topic>` → `--span <topic>`. A typical prompt after a clear is one sentence: *"flashback: continue the X work"* — the session reads the screen it already has, pulls that session's index, and goes.

### Scope is the pane, not the directory

**Read only the pane's own line.** The hook prints two different things and they carry different permissions: `Prior session in this pane: …` is the lineage you resumed, and the dated list below it is *awareness only*. Pull detail on the pane line. Do not `read` or `explore --show` any other row unless the operator names it — a session in another lane is somebody else's thread, and reconstructing it answers a question nobody asked.

**Do not call `read` on a row marked `○` (card only).** It has no manifest and returns nothing. The list already told you which rows are indexed (`●`) and which are not; use `explore --show <id>` for a card. A call whose emptiness was predictable from context you already hold is a caller bug, not a missing feature.

### Pull the cheapest layer that answers the question

`prior_line` (already in the hook, free) → `explore --show <id>` for a card → `read --index` only when the resumed work has deadlines, ledgers, or owed items at stake. The index is the right call for a pane holding time-boxed work; it is overkill for remembering what a session was about.

If the hook says an index is still building, **that read blocks**. Measured: 23.9s. Decide up front whether the work justifies the wait, or take the card and move.

### What the waste actually costs — measure turns, not bytes

A 2026-09-15 audit of one startup pass: **481,791 tokens billed across 8 turns / 101.5s** before the first answer. Four turns touched other lanes. Removing them saves **199,837 tokens — 41.5%**.

The first pass at that audit reported **1%**, because it priced the *content bytes* the out-of-scope calls appended (~700 tokens). That is wrong by 40×. Cost is `turns × carried window`: each extra turn re-bills an already-large window (57–66K by the end), so four cheap-looking calls cost a fifth of a million tokens. **Any context audit reporting bytes-added is reporting the wrong quantity.**

The corollary matters more than the number: the hook itself was already lean (~300 tokens). **100% of the waste was post-hook agent behavior.** Do not tune the emitter when the caller is what is expensive.

## What memento is still for

Everything *said* is indexed before you write a note. Memento carries what only the author knows: the next action, who is owed what, the traps, the three of forty things that matter. A note that restates the transcript is a note the index already has. Write one when you have a judgment to pass on; otherwise clear freely. `@protocol/memento`.

## Engines

| engine | status | adapter |
|---|---|---|
| Claude Code | live 2026-09-06 | `@protocol/flashback-claude-code` |
| Hermes | planned | — |
| OpenClaw | planned | — |

An adapter is one class in the tool: where transcripts live and how to enumerate them for a directory; parse one into turns (A/B/C split); locate the prior life for a process; the hook event → (event, transcript, session, cwd, source) mapping; the stripped summarize call; and `install`, which wires the hook into the engine's settings idempotently. Everything else — cards, passes, validation, explore, read, boot, control — is engine-independent.

## Files

Attached to this entry: `flashback.py` (the tool, single file, Python 3, no dependencies), `flashback-prompt.md` (the extraction prompt the model pass reads), `flashback-fixture.jsonl` (the control transcript). Install on any box with `curly`:

```bash
B=~/bin   # anywhere on PATH
F=/repo/protocol/entry/flashback/file
curly protocol $F/flashback.py            > $B/flashback && chmod +x $B/flashback
curly protocol $F/flashback-prompt.md     > $B/flashback-prompt.md
curly protocol $F/flashback-fixture.jsonl > $B/flashback-fixture.jsonl
flashback install && flashback check     # wires the hooks, then proves the pipeline on the fixture
```

The three files sit side by side; the tool finds its prompt and fixture next to itself. Root defaults to `~/.flashback` (`FLASHBACK_ROOT` to move it); kill switch is removing `<root>/enabled`; `<root>/skip` lists directory globs to ignore; errors go to `<root>/err`, never to the session.

---

*Related: `@integrations/agent-browser` · `@content/web/huggingface/2026-11-27-model-managed-context-nvidia-harness` · `@content/web/github/2026-11-26-opus-context-fills-faster-issue-112194` · `@content/web/github/2026-11-26-autodream-silently-ignored-issue-112310` · `@protocol/bootstrap-core`*

---

*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).*