From 2dfc3b20752298e2b5bbd1a30209ad2fe1cc022c Mon Sep 17 00:00:00 2001 From: afterimaginary <126125402+afterimaginary@users.noreply.github.com> Date: Fri, 27 Nov 2026 18:06:24 -0800 Subject: [PATCH 1/2] docs(readme): lead with the plugin, backed by the experiment Closes #115 Co-Authored-By: Claude Opus 5.5 --- README.md | 115 +++++++++++++++++++++---------------- STATE.md | 1 + pyproject.toml | 2 +- src/backread_exp/readme.py | 7 ++- tests/test_readme.py | 2 +- 5 files changed, 72 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 05b1059..c5f797c 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,72 @@ # backread -**When a compacted agent can search the conversation its summary replaced, it gets back much of what the summary dropped: a 1,024-token summary plus search scored 0.80, against 0.53 for the summary alone and 0.72 for a summary four times the size.** That is on `claude-haiku-5-5`, with a capped keyword search that used fewer tokens per question than the bigger summary and cost less per correct answer. +**A Claude Code plugin that lets the agent search its own conversation from before a compaction, so it can get back the details the summary dropped.** + +When a long session fills its context, Claude Code replaces the conversation with a summary and carries on. Summaries lose things: a port number, who owns a key, which ticket a task is waiting on. The full conversation is still on disk, but as a large raw file the agent has no easy way to search. backread gives the agent a keyword search over it, and a line after each compaction telling it the search is there. + +```text +/plugin marketplace add afterimaginary/backread +/plugin install backread@backread +``` + +## Does it help? + +Yes, in a controlled test run before the plugin was built. On 48 long conversations, each compacted five times, an agent answered questions about what had been said earlier. With a 1,024-token summary plus search, it scored 0.80, against 0.53 for the summary alone and 0.72 for a summary four times the size. On `claude-haiku-5-5`, the capped keyword search used fewer tokens per question than the bigger summary and cost less per correct answer. Score against mean tokens per question for each arm on claude-haiku-5-5, with 95% intervals: summary 0.53, summary-big 0.72, search 0.80, search-nudged 0.83, ceiling 0.95, floor 0.00 -This repository is the experiment behind that result and a small Claude Code tool built from it. The full write-up is [REPORT.md](REPORT.md). +The test also found where search doesn't help: the agent searches when the summary is missing something, but rarely when the summary confidently states an outdated value. [The test behind it](#the-test-behind-it) has the method and every hypothesis, and [REPORT.md](REPORT.md) is the full write-up. + +## What it looks like + +In this [real session](docs/trial-session.md), the user asked Claude Code to drop some details when compacting, then asked for them afterwards (trimmed): + +```text +❯ Before I set up the deploy script: which port does staging listen on, and who owns the deploy key? + +⏺ Bash(backread search staging port deploy key owner --transcript ~/.claude/projects/-work-scratch/00000000-0000-4000-8000-000000000001.jsonl) + ⎿ … + [L3] user message, 2026-11-27 08:06 UTC + I'm starting a small static site here. A few things to keep in mind, no need to write them down + anywhere: the staging server listens on port 8437, the deploy key belongs to Ines Okafor, … + +⏺ Staging listens on port 8437, and the deploy key belongs to Ines Okafor. I didn't have either in my + summary, because you asked me to drop those notes when compacting. I found them by searching the + earlier part of the session. +``` + +The plugin has three parts: + +- **The `backread` command.** `backread search ` returns up to 3 excerpts (500 characters max), each with a handle; `backread get ` prints one record in full. It searches the conversation before the last compaction, including tool output and subagents. +- **A hook** that runs after each compaction and adds one line to the agent's context, naming the command and this session's transcript: + + ```text + `backread search --transcript ~/.claude/projects/-work-scratch/.jsonl` searches the original conversation that the summary was written from, by keywords, and returns up to 3 short excerpts with their handles. + ``` -## What was tested + The wording is a plain tool description. In the test, a stronger nudge, warning that the summary might be out of date, cost more without cutting outdated answers. + +- **A short skill** telling the agent when a search is worth it. + +In three trial sessions, the agent searched and answered correctly in two. In the third it said it could search and asked first. + +Claude Code's own summary already points to the raw transcript file near its end, so an agent can read it without this plugin. What `backread` adds is a search over it, instead of a large JSONL file with tool output and subagents mixed in. The test didn't measure the raw-file route. + +### Requirements and limits + +- **Tested on** Claude Code 2.1.327. It runs on macOS and Linux and needs Python 3.13 or later, or uv to fetch one. +- **Claude Code only.** claude.ai and Cowork don't support this kind of plugin. +- **Keyword search only.** +- **One session per folder by default.** Without the hook's `--transcript`, it reads the newest transcript for the working directory, which may be another session's. + +Commands, output and exit codes: [docs/cli.md](docs/cli.md). The plugin and its hook: [docs/plugin.md](docs/plugin.md). + +## The test behind it + +### What was tested When a long agent session runs out of context, the conversation is replaced by a summary and the original stays on disk. The experiment uses the public `practice` suite of [CompactBench](https://github.com/compactbench/compactbench): 48 long synthetic working conversations, each compacted five times, with exact-answer questions about what was said. One compactor writes every summary, and a reader model answers each question, one per request, seeing only what its arm allows: @@ -24,7 +81,7 @@ When a long agent session runs out of context, the conversation is replaced by a A search returns at most 3 excerpts of at most 500 characters, and the reader gets at most 3 searches per question, so a search arm sees at most about 1,200 tokens of the original: less than the 3,072 extra tokens `summary-big` gets. Scoring is CompactBench's own scorer; no judge model is used. The main run asked 1,802 questions in each arm. -## What happened +### What happened Four hypotheses were fixed in [PLAN.md](PLAN.md) before any paid run. Three passed. @@ -37,7 +94,7 @@ Four hypotheses were fixed in [PLAN.md](PLAN.md) before any paid run. Three pass The reader knows when something is missing, not when something is wrong: a summary that states an outdated value gives no hint that it needs checking. Search's lead also grows with compaction: after one compaction `search` and `summary-big` score about the same, and after the fifth `search` is well ahead ([by cycle](REPORT.md#by-cycle-and-by-family)). -## One trace +### One trace Case `…27718baeca50600b`, after the fifth compaction. Excerpts trimmed with `…`: @@ -58,7 +115,7 @@ search same summary, one search: "OPS-3395" The summary kept that OPS-3395 was blocked but dropped what it was waiting on. The [gallery](REPORT.md#gallery) has four more, picked by mechanical rules, including the failures: a search that fetched the old value, a confidently wrong summary the reader never checked, and a question the bigger summary won. -## Rerun it +### Rerun it The traces of every paid run are committed, so the analysis reruns for free, with no API key: @@ -86,7 +143,7 @@ uv run python -m backread_exp run --model claude-haiku-5-5 --arms summary search `run` prints its estimate before the first call, refuses any request that could take it past `--max-usd`, and resumes if run again. Every paid call is logged to `results/ledger.jsonl`, and a project-wide cap of $100 counts that ledger, including the $42 already in it. `make report REPORT_RUNS=data/cache/fresh-runs REPORT_OUT=data/cache/fresh-results` reports a fresh run without touching `REPORT.md`. [CONTRIBUTING.md](CONTRIBUTING.md) lists every command. -## What it cost +### What it cost $42.13 for the whole project, from the spend ledger: @@ -105,49 +162,7 @@ Per 1,000 correct answers on the main run, at Anthropic's published prices: `summary` is cheapest per correct answer, but gets far fewer right. `floor` scores zero yet has a cost per correct answer because questions whose right answer is "not stated" count as correct here but are left out of the score. Among the arms that score higher, `search` is cheapest. -## The tool - -`backread` searches a Claude Code session's transcript from before its last compaction, with the same search module and caps as the experiment. A plugin bundles it with a short skill and a hook that, after each compaction, adds one line naming the command and this session's transcript. - -Install from Claude Code: - -```text -/plugin marketplace add afterimaginary/backread -/plugin install backread@backread -``` - -The hook's line adapts the `search` arm's neutral tool sentence, the arm the report picked; the transcript path is this session's: - -```text -`backread search --transcript ~/.claude/projects/-work-scratch/.jsonl` searches the original conversation that the summary was written from, by keywords, and returns up to 3 short excerpts with their handles. -``` - -In [real compacted sessions](docs/trial-session.md) with this line, the user had told the compaction to drop some details, then asked for them. In two of three sessions the agent searched once and answered from what it found; in the third it said it could search and asked first. From session 1 (trimmed): - -```text -❯ Before I set up the deploy script: which port does staging listen on, and who owns the deploy key? - -⏺ Bash(backread search staging port deploy key owner --transcript ~/.claude/projects/-work-scratch/00000000-0000-4000-8000-000000000001.jsonl) - ⎿ … - [L3] user message, 2026-11-27 08:06 UTC - I'm starting a small static site here. A few things to keep in mind, no need to write them down - anywhere: the staging server listens on port 8437, the deploy key belongs to Ines Okafor, … - -⏺ Staging listens on port 8437, and the deploy key belongs to Ines Okafor. I didn't have either in my - summary, because you asked me to drop those notes when compacting. I found them by searching the - earlier part of the session. -``` - -Claude Code's own summary already includes, near its end, a line pointing at the raw transcript file, so an agent can read that file without the plugin. What `backread` adds is a search over it: up to 3 snippets of at most 500 characters, each with a handle, instead of a large JSONL file with tool output and subagents mixed in. The experiment didn't measure the raw-file route. - -- **Tested on** Claude Code 2.1.327. It runs on macOS and Linux and needs Python 3.13 or later, or uv to fetch one. -- **Claude Code only.** claude.ai and Cowork don't install plugins of this shape. -- **Keyword search only**, over the conversation before the last compaction, subagents included. -- **One session per folder by default.** Without the hook's `--transcript`, it reads the newest transcript for the working directory, which may be another session's. - -Commands, output and exit codes: [docs/cli.md](docs/cli.md). The plugin and its hook: [docs/plugin.md](docs/plugin.md). - -## Limits +### Limits of the test - **Synthetic conversations and direct questions.** A real agent in the middle of a task has to notice on its own that it needs something the summary lost, which is harder than being asked. - **One compactor, one reader model for the verdicts.** Every summary comes from CompactBench's `sectioned-summary` on `claude-haiku-5-5`, and nearly all were cut to fit their budget. A second model, `claude-sonnet-5-5`, ran a smaller grid with the same shape of result but decides nothing. diff --git a/STATE.md b/STATE.md index 36148a2..1226dca 100644 --- a/STATE.md +++ b/STATE.md @@ -17,6 +17,7 @@ The harness is built and runs end to end offline (`make offline`) against fake m ## Recently Done +- [README](README.md) leads with the plugin: what it does and why, install, the headline result and chart as the test behind it, a real session, then the experiment's detail; the repository and package descriptions lead with the plugin too (#115) - Pre-publication check: a [NOTICE](NOTICE) and the Apache 2.0 text in `LICENSES/` for the CompactBench text in the summaries and traces, a contact line in the README, and the `plan-frozen` tag ruleset kept in `.github/rulesets/` (GitHub refuses rulesets on a private free repository) (#35) - The source distribution holds only the tool's source, the tests and the readme and licence files, about 160 KB instead of 33 MB with `results/` and `data/`; a test builds it and checks its files and size (#113) - [README](README.md): the finding and the main chart first, then the six arms, the four hypotheses with their numbers, one gallery trace, how to rerun the analysis for free and the models under a cap, what it cost, and the tool with its install, a real session and its limits (#34) diff --git a/pyproject.toml b/pyproject.toml index 7a83a3a..0e7df88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "backread" version = "0.0.0" -description = "Search the conversation a context summary replaced: an experiment on CompactBench, and a small Claude Code tool" +description = "A Claude Code plugin that lets the agent search its conversation from before the last compaction, tested on CompactBench" readme = "README.md" license = "MIT" # The MIT licence, the NOTICE and the Apache 2.0 text it points at for CompactBench's text. diff --git a/src/backread_exp/readme.py b/src/backread_exp/readme.py index bdc1a71..b65168a 100644 --- a/src/backread_exp/readme.py +++ b/src/backread_exp/readme.py @@ -67,9 +67,10 @@ def score(arm: str, places: int = 2) -> str: memories = parts[labels["memories-"]] total = sum(e.usd for e in ledger) fragments = [ - f"a 1,024-token summary plus search scored {score('search')}, against {score('summary')}" - f" for the summary alone and {score('summary-big')} for a summary four times the size.", - f"That is on `{model}`, with a capped keyword search", + f"With a 1,024-token summary plus search, it scored {score('search')}," + f" against {score('summary')} for the summary alone and {score('summary-big')}" + " for a summary four times the size.", + f"On `{model}`, the capped keyword search used", f"Score against mean tokens per question for each arm on {model}, with 95% intervals: " + ", ".join(f"{arm} {score(arm)}" for arm in CHART_ORDER), f"{len(main['cases'])} long synthetic working conversations", diff --git a/tests/test_readme.py b/tests/test_readme.py index 5c27fb3..9e6c73e 100644 --- a/tests/test_readme.py +++ b/tests/test_readme.py @@ -42,7 +42,7 @@ def test_a_moved_score_is_caught( moved = copy.deepcopy(summary) moved["main"]["arms"]["search"]["score"]["point"] = 0.79 found = readme.problems(text, moved, ledger, PICKS) - assert any("plus search scored 0.79" in p for p in found) + assert any("plus search, it scored 0.79" in p for p in found) assert any("search 0.79, search-nudged" in p for p in found) From 50fc2d9291f67699b37cee42bcf34d812368a26b Mon Sep 17 00:00:00 2001 From: afterimaginary <126125402+afterimaginary@users.noreply.github.com> Date: Fri, 27 Nov 2026 18:10:00 -0800 Subject: [PATCH 2/2] docs(readme): address review: blind-spot wording, test scope, get cap Co-Authored-By: Claude Opus 5.5 --- README.md | 8 ++++---- STATE.md | 2 +- src/backread_exp/readme.py | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c5f797c..aa25b66 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **A Claude Code plugin that lets the agent search its own conversation from before a compaction, so it can get back the details the summary dropped.** -When a long session fills its context, Claude Code replaces the conversation with a summary and carries on. Summaries lose things: a port number, who owns a key, which ticket a task is waiting on. The full conversation is still on disk, but as a large raw file the agent has no easy way to search. backread gives the agent a keyword search over it, and a line after each compaction telling it the search is there. +When a long session fills its context, Claude Code replaces the conversation with a summary and carries on. Summaries lose things: a port number, who owns a key, which ticket a task is waiting on. The full conversation is still on disk, but as a large raw file the agent has no targeted way to search. backread gives the agent a keyword search over it, and a line after each compaction telling it the search is there. ```text /plugin marketplace add afterimaginary/backread @@ -11,14 +11,14 @@ When a long session fills its context, Claude Code replaces the conversation wit ## Does it help? -Yes, in a controlled test run before the plugin was built. On 48 long conversations, each compacted five times, an agent answered questions about what had been said earlier. With a 1,024-token summary plus search, it scored 0.80, against 0.53 for the summary alone and 0.72 for a summary four times the size. On `claude-haiku-5-5`, the capped keyword search used fewer tokens per question than the bigger summary and cost less per correct answer. +Yes, in a controlled test run before the plugin was built, with direct questions rather than a live task. On 48 long conversations, each compacted five times, an agent answered questions about what had been said earlier. With a 1,024-token summary plus search, it scored 0.80, against 0.53 for the summary alone and 0.72 for a summary four times the size. On `claude-haiku-5-5`, the capped keyword search used fewer tokens per question than the bigger summary and cost less per correct answer. Score against mean tokens per question for each arm on claude-haiku-5-5, with 95% intervals: summary 0.53, summary-big 0.72, search 0.80, search-nudged 0.83, ceiling 0.95, floor 0.00 -The test also found where search doesn't help: the agent searches when the summary is missing something, but rarely when the summary confidently states an outdated value. [The test behind it](#the-test-behind-it) has the method and every hypothesis, and [REPORT.md](REPORT.md) is the full write-up. +The test also found a blind spot: the agent nearly always searched when the summary had left something out, but much less often when the summary gave a wrong answer, and seldom fixed those. [The test behind it](#the-test-behind-it) has the method and every hypothesis, and [REPORT.md](REPORT.md) is the full write-up. ## What it looks like @@ -40,7 +40,7 @@ In this [real session](docs/trial-session.md), the user asked Claude Code to dro The plugin has three parts: -- **The `backread` command.** `backread search ` returns up to 3 excerpts (500 characters max), each with a handle; `backread get ` prints one record in full. It searches the conversation before the last compaction, including tool output and subagents. +- **The `backread` command.** `backread search ` returns up to 3 excerpts (500 characters max), each with a handle; `backread get ` prints a record, up to 4,000 characters at a time. It searches the conversation before the last compaction, including tool output and subagents, with the same search code and caps as the test. - **A hook** that runs after each compaction and adds one line to the agent's context, naming the command and this session's transcript: ```text diff --git a/STATE.md b/STATE.md index 1226dca..7030650 100644 --- a/STATE.md +++ b/STATE.md @@ -4,7 +4,7 @@ ## Where We Are -The harness is built and runs end to end offline (`make offline`) against fake models. [PLAN.md](PLAN.md) fixes the hypotheses, prompts, seeds and gates; CI fails if anything above its Deviations section changes after the `plan-frozen` tag. The pilot passed all five gates, the memories exist for all 48 cases at both budgets, and the main run on `claude-haiku-5-5` has all six arms on all 48 cases, with a second `summary` run for the flip rate, and the second-model run on `claude-sonnet-5-5` has four arms on all 48 cases. The `backread` command and the Claude Code plugin are built and were tried in a real compacted session. `make report` regenerates every number, table and chart from the saved runs into `REPORT.md`'s generated blocks, and `verify` fails if they're stale. [REPORT.md](REPORT.md) is written: three of four hypotheses pass (the nudge one fails), and it names `search` as the arm to ship. The README leads with the finding and the main chart. The pre-publication check is done; what's left is making the repository public and then applying the `plan-frozen` tag ruleset. +The harness is built and runs end to end offline (`make offline`) against fake models. [PLAN.md](PLAN.md) fixes the hypotheses, prompts, seeds and gates; CI fails if anything above its Deviations section changes after the `plan-frozen` tag. The pilot passed all five gates, the memories exist for all 48 cases at both budgets, and the main run on `claude-haiku-5-5` has all six arms on all 48 cases, with a second `summary` run for the flip rate, and the second-model run on `claude-sonnet-5-5` has four arms on all 48 cases. The `backread` command and the Claude Code plugin are built and were tried in a real compacted session. `make report` regenerates every number, table and chart from the saved runs into `REPORT.md`'s generated blocks, and `verify` fails if they're stale. [REPORT.md](REPORT.md) is written: three of four hypotheses pass (the nudge one fails), and it names `search` as the arm to ship. The README leads with the plugin, with the finding and the main chart as the test behind it. The pre-publication check is done; what's left is making the repository public and then applying the `plan-frozen` tag ruleset. ## Features diff --git a/src/backread_exp/readme.py b/src/backread_exp/readme.py index b65168a..6de0367 100644 --- a/src/backread_exp/readme.py +++ b/src/backread_exp/readme.py @@ -74,6 +74,7 @@ def score(arm: str, places: int = 2) -> str: f"Score against mean tokens per question for each arm on {model}, with 95% intervals: " + ", ".join(f"{arm} {score(arm)}" for arm in CHART_ORDER), f"{len(main['cases'])} long synthetic working conversations", + f"On {len(main['cases'])} long conversations, each compacted five times", f"The main run asked {' or '.join(f'{n:,}' for n in per_arm)} questions in each arm.", f"{_word(len(h))} hypotheses were fixed in [PLAN.md](PLAN.md) before any paid run." f" {_word(passed)} passed.",