Lossless Handoff
Claude Code hooks that write a handoff before every compaction, keep a decisions list per project, and search the exact words of earlier chats.
- 50/50 Fair re-test with a hint, against 41/50 for plain Claude Code (2 seeds, a direction, not a proof)
- v0.22.0 Latest release, the 18th since v0.1.0 on 2026-10-20
- 72 Merged pull requests
- 1,768 Code-blind acceptance test functions in a separate repo
lossless-handoff README, Benchmarks, 2026-11-26; lossless-handoff release list, 2026-11-26; lossless-handoff pull request list, 2026-11-26; lossless-handoff-tests at the commit in tests.ref, grep for def test_, 2026-11-26
Change the rule three times
A mock session changes one deploy rule three times, with a compaction after each change. Compare a plain summary with the Lossless Handoff decisions list, then ask the recall question. Fake data only.
Problem
A long Claude Code session ends in a compaction. The chat turns into a short, generic summary. The exact next step, the dead ends, your standing rules and your exact words are gone. The model then does the work again or asks again (lossless-handoff README, 2026-11-26).
I run a 400k context window, so compactions come often. I wanted compaction to lose nothing important, and I wanted Claude to be able to get the exact old text back.
Constraints
- It is an add-on to Claude Code. I do not control the host, so it uses hooks. A hook cannot force Claude Code to run it, and no hook can force the model to search.
- A hook must never block compaction. Both hooks always exit 0, and if anything fails a minimal handoff is still written.
- Python 3 standard library only. It runs on macOS and Linux. Windows is not supported (README).
- A handoff is at most 14,000 characters.
- Claude Code already keeps every message in its
.jsonltranscript files, so the project uses them as the store and never writes to them. - Word search stays on my machine. Meaning search uses a local embedding model (bge-m3 through Ollama) and is optional.
- Public and MIT licensed.
Approach
It is based on the paper "LCM: Lossless Context Management" by Clint Ehrlich and Theodore Blackman (arXiv:2605.04050). The idea: keep every message word for word in a store, and give the model tools to look things up, so a compaction destroys nothing. This is an independent project. The paper authors did not write it and are not affiliated with it (docs/background.md).
Hooks cannot change how Claude Code builds its context. So this project adds to Claude Code's own summary instead of replacing it. There are four parts:
- Handoff. A PreCompact hook writes a handoff before each auto-compaction. It holds the model's own note, a fresh summary and facts that code extracts with no model.
- Inject. A SessionStart hook with the matcher
compactfeeds the handoff and the decisions list back into the new context. - Decisions list. One list per project holds what I decided or approved, and why. It survives every compaction. My latest words win.
- Recall.
recall.pysearches the exact earlier words in the.jsonltranscripts. It uses keyword search, plus optional local meaning search. One line in the new context tells the model to run it when it does not clearly know an earlier value.
The project was called claude-handoff until v0.6.0, when it was renamed Lossless Handoff (README, CHANGELOG).
What shipped
- 18 releases, from v0.1.0 on 2026-10-20 to v0.22.0 on 2026-11-26 (
gh release list). - 72 merged pull requests, and the repo was created on 2026-10-20 (
gh, checked 2026-11-26). - Hooks for handoff, inject, nudge, auto-recall and re-anchor, plus opt-in guards, a local MCP recall tool, nightly index jobs, and install and uninstall scripts with a dry-run mode (README).
- A behaviour contract,
docs/spec.md, and a separate code-blind test repo,lossless-handoff-tests. At the commit pinned intests.ref(41f7b83) it has 1,768 test functions (counted withgrepfordef test_, 2026-11-26; I did not read the tests). - CI on Ubuntu and macOS: static checks, a smoke test and the acceptance tests (docs/testing.md).
- Source: pratikgh0se/lossless-handoff.
Outcome
I ran a small benchmark of my own. It plants facts with random answers early in a long scripted session. Filler turns force compactions. Then the runner asks questions and code grades the answers.
Fair re-test, 2026-11-26. Plain Claude Code was allowed to search its own chat files. Two seeds, Sonnet, 400k window, 10 compactions (README, Benchmarks):
| Questions | Plain Claude Code | Lossless Handoff |
|---|---|---|
| With a hint | 41 of 50 (82%) | 50 of 50 (100%) |
| No hint | 29 of 40 (72%) | 40 of 40 (100%) |
The README calls two seeds "a direction, not a proof". The total cost of that run was about $70 (README).
The limits, from the README:
- One heavy user so far: me. All numbers come from my machine, and nobody has tested whether it helps other workflows.
- Handoffs can be cut. 75 of 283 main-chat handoffs (27%, 2026-10-16 to 2026-11-25) hit the 14,000-character cap and were truncated.
- Misses still happen. 4 of 192 main compactions in the 30-day reconcile had no handoff.
- It is my own synthetic benchmark, graded by code but written by me. It used Sonnet only and one Claude Code version.
- Models wrote and graded the earlier quizzes.
What I learned
My first benchmark run gave 58% for plain Claude Code against 100% for Lossless Handoff, over 4 seeds, on 2026-11-23. That gap was too large. The runner had blocked the plain arm from reading its own chat files (deny_rules in bench/continuity/runner.py), so plain Claude Code could not do what it can do in real use. I re-ran the test fairly, with plain Claude Code allowed to search its chat files, and published the smaller gap. I kept the first run in the README and marked it as the one that overstates the gap (README, Limits).
A hook cannot make Claude Code run it. So the design assumes misses will happen. It writes a handoff early, rebuilds a missing one afterwards, and counts the misses every night, instead of promising none (README, No silent misses).
How AI built this
- Spec first. Behaviour is written in
docs/spec.mdbefore the code, with numbered items (acceptance criteria and F-numbered features). A behaviour change starts as an edit to the spec. - Decision records. Design choices are written as ADRs in
docs/adr/. - Code-blind tests. An agent writes the acceptance tests only from
docs/spec.md, in the separatelossless-handoff-testsrepo. The people and agents who change the hooks never read the tests. They see only the test names and the assertion output (docs/testing.md). - I have no repo record of which model built which part.