Measured on Claude Code 2.1.270 to 2.1.300
Claude Code's compaction doesn't delete your history. It re-roots it.
When Claude Code compacts a session, the model's context is replaced by a summary, but the transcript on disk keeps every record: measured on Claude Code 2.1.270 and 2.1.300, compaction only appends to the file.
What the model carries forward is another matter. In our test, one session each on Opus 5.5 and Sonnet 5.5 kept all 14 planted details through /compact, sessions on Haiku 5.5 kept none, and the file kept every one.
Where Claude Code keeps your conversation history
Claude Code writes each session to one file on your machine: ~/.claude/projects/<project>/<session id>.jsonl, one JSON record per line. A subagent's work goes to its own file under <session id>/subagents/.
The file is append-only. We measured that two ways on Claude Code 2.1.270 (September 2026):
- Snapshots. Every copy of a transcript taken during a session was a byte-for-byte prefix of every later copy, across compactions too.
- System calls. Tracing the process, every time Claude Code opened a transcript to write, it opened it to append: 112 times in the terminal interface, 54 and 54 in two headless runs. There were 0 truncations, 0 positioned writes and 0 renames of a transcript, while the same traces showed Claude Code rewriting other files by write-then-rename.
We repeated the snapshot test in four sessions on 2.1.300 (October 2026), with the same result: the file before a /compact is the first part of the file after it.
So when people say compaction dropped part of a session, it was dropped from the model's context, not from the file.
Compaction never deletes the file, but Claude Code's cleanup does. It deletes transcripts older than cleanupPeriodDays, 30 days by default (Anthropic's documentation). We checked our own machine, which leaves the setting at its default, on October 18, 2026. Every session last written more than 30 days ago was gone from the folder (161 of 161). Every younger one was still there (67 of 67). We had the older ones only because we keep our own copies.
What compaction writes
/compact · two roots (scroll sideways for the whole drawing)The dashed line is the only link from the new root back to the old records.
A first compaction writes two records and changes none. First a compact_boundary record whose parentUuid is null, so the file now holds two trees. Then the summary, as a user record below the boundary.
The boundary carries the way back and a receipt. logicalParentUuid names the last record before it. compactMetadata gives the trigger (manual in every run we made), the token count before and after (39,557 and 2,676 in one of our runs on 2.1.300), and which recent messages were kept verbatim. The model then carries on from the summary and that kept tail, as the summary's own wrapper says; everything before the boundary stays in the file.
Why the history looks cut off after compaction
A transcript is a tree. Each record names its parent in parentUuid, and the conversation is one path through the tree, from the first prompt to the last record.
Compaction appends a compact_boundary record whose parentUuid is null, which makes it a new root, and hangs the summary below it. The conversation continues from the summary. The old records keep their original parents: 818 of 818 across 5 boundaries in our September runs.
So a reader that climbs parentUuid from the end of the file stops at the boundary, as if the session had begun there. The way back is a different field: the boundary's logicalParentUuid names the last record before it. In sessions from the terminal interface, the earlier history hangs off compactMetadata.preservedSegment.headUuid instead. A reader has to follow that field to cross.
Two more traps, both measured on our test sessions:
- The same record can be written twice. Just before every manual
/compactafter the first, Claude Code writes again the history that the earlier compactions summarized: the same uuids, with some fields changed. Count each uuid once, at its first copy. - Claude Code's own interface cannot reach behind a boundary. On 2.1.270 the rewind list said "Nothing to rewind to yet",
--resume-session-atrefused a record from before the compaction, and--fork-sessioncopied only what came after it.
What the summary says, and what it gets wrong
The summary is written into the transcript as a user record marked isCompactSummary, wrapped in fixed text from Claude Code. On 2.1.300 the wrapper reads, in order:
- "This session is being continued from a previous conversation that ran out of context. The summary below covers the earlier portion of the conversation."
- The summary itself.
- "If you need specific details from before compaction (like exact code snippets, error messages, or content you generated), read the full transcript at: <the transcript's path>"
- "Continue the conversation from where it left off without asking the user any further questions. Resume directly — do not acknowledge the summary, do not recap what was happening, do not preface with "I'll continue" or similar. Pick up the last task as if the break never happened."
- "The messages after this summary are the most recent messages from before compaction, kept verbatim. The summary was written without seeing them, so something it says has not happened yet may already have happened in them."
The first sentence gives a cause that can be false. Every summary we have opens with "ran out of context", including manual compactions at 7,116 tokens (2.1.272) and at about 40,000 (2.1.300), when nothing had run out.
On 2.1.272 the summary also quoted Claude Code's own summarizing instruction as if the user had typed it. On 2.1.300, Sonnet 5.5's summary did the same: "That message also asked for this summary, in text only with no tool calls." And the wrapper's third part is the most useful line in the record: it tells the model where the full history still is.
What the model still knows after compaction
It depends on the model that writes the summary, which is the session's own. The /compact call's usage report named only Haiku 5.5 in the Haiku sessions, Opus 5.5 (beside a 23-token Haiku call) in the Opus one, and Sonnet 5.5 (beside a 254-token Haiku call) in the Sonnet one. We planted 14 invented details, ran /compact, and asked for all 14: first from memory, then by reading the transcript the summary names.
| Session (Claude Code 2.1.300) | Last message before /compact | Body of the summary | Details in the summary | Answered from memory | Found by reading the file |
|---|---|---|---|---|---|
| Opus 5.5 | "Explain in about 400 words how an LRU cache decides what to evict." | a structured summary of the session, 5,748 characters | 14 of 14 | 14 of 14 | 14 of 14 |
| Sonnet 5.5 | the same question | a structured summary of the session, 3,462 characters | 14 of 14 | 14 of 14 | 14 of 14 |
| Haiku 5.5, run A | the same question | a new explanation of LRU caches | 0 of 14 | 0 of 14 ("unknown" each time) | 4 of 14 (read 26 of 131 lines) |
| Haiku 5.5, run B | "Four more for later: … Reply with exactly: noted." | "noted." | 0 of 14 | 0 of 14 ("unknown" each time) | 6 of 14 (read 7 of 129 lines) |
| Haiku 5.5, one earlier run | "What word did I ask you to remember? One word." | "The word is PELICAN." | the one word asked for | recalled | not asked |
On Opus and on Sonnet the summary kept every detail, even six the user never asked it to keep: they sat in a build log pasted only for a one-line diagnosis. On Haiku, three times out of three, the "summary" was a reply to the last message before /compact. Our reading, not measured: that reply is kept verbatim after the summary, which "was written without seeing" it, so the summarizer met an open question and answered it.
Two things held throughout. The model did not invent: asked from memory, Haiku said "unknown" for all 14. And the file held all 14 in every run. Reading it raw was slow going on Haiku, which stopped at line 7 of 129 because "the remaining lines are too large for the Read tool to return".
Retrieval, from the computer-science side
A summary is a lossy encoding of the conversation, and nothing downstream can put back what it left out. In information-theory terms, no processing of the summary can add information about the original (the data-processing inequality). Whatever the model does next, it cannot know what the summary does not say.
The loss is also decided at the wrong time. A summary is written before anyone knows the next question, so it has to guess what will matter; but relevance belongs to the question, not to the text. Keeping the raw record moves that decision to read time, when the question is known.
That is why the append-only file matters. It is the one complete copy, and compaction leaves it whole. The open problem is not loss but access: finding the few lines that answer a question among hundreds of long records.
How to keep your history and get details back
- Keep the file past 30 days. Raise
cleanupPeriodDaysin~/.claude/settings.json(the minimum is 1), or copy the files somewhere the cleanup does not reach. Raising it does not bring back files already deleted. - When the model says it does not know, point it at the file. The summary names the transcript's path, and the file still held all 14 details in every run.
- Give it an index, not the raw file. One line of a transcript can be a very long JSON record, and a file reader stalls on those. Long-Term Memory Structure, our free, open-source tool, prints one short line per turn and tool call with the line number where it is written:
npx long-term-memory-structure skeleton <file.jsonl>. Then read just the lines that matter:sed -n 22p <file.jsonl>. - Read across the boundary in your own scripts. At each
compact_boundary, continue fromlogicalParentUuid(orcompactMetadata.preservedSegment.headUuid), and count each uuid once, at its first copy. - Know which model writes the summary. In our runs, one session each on Opus 5.5 and Sonnet 5.5 kept every detail through compaction, and sessions on Haiku 5.5 kept none.
Questions people ask
Does /compact delete my conversation?
No. It replaces the model's context with a summary and appends two records to the transcript. Every earlier record stays in the file (measured on 2.1.270 and 2.1.300).
Where does Claude Code store conversation history?
On your machine, in ~/.claude/projects/<project>/<session id>.jsonl, one JSON record per line. A subagent's work goes under <session id>/subagents/.
Why does Claude Code forget things after compacting?
The model carries on from the summary, not from the file, so whatever the summary leaves out is gone from its context. In our test, Opus 5.5 and Sonnet 5.5 kept all 14 planted details, and Haiku 5.5 kept none.
Can I get back what was compacted?
Yes, from the file. The summary itself names the transcript's path, so the model can read it when you ask. An index such as Long-Term Memory Structure finds the lines that matter.
Does Claude Code delete old conversations?
Yes, after 30 days by default. Compaction does not delete them, but the cleanup removes transcripts older than cleanupPeriodDays.
How we measured
Every claim about compaction here comes from throwaway sessions with invented content, run on our own machine: headless (claude -p), with --resume for each later turn and for /compact. In the October 18 runs, no tools were allowed until the last question, which allowed only the file reader.
| Date | Claude Code | Sessions | What we measured |
|---|---|---|---|
| 2026-10-18 | 2.1.300 | 2 on Haiku 5.5, 1 on Opus 5.5, 1 on Sonnet 5.5 | 14 planted details: in the summary, from memory, from the file |
| 2026-10-18 | 2.1.300 | 228 sessions we had kept copies of | which transcripts the 30-day cleanup had removed from the folder |
| 2026-10-17 | 2.1.300 | 1 on Haiku 5.5 | the file stays a prefix of itself; the boundary; the summary's wrapper |
| 2026-09-30 | 2.1.272 | 3 on Haiku | how /compact can be started; the records it writes; what the summary says |
| 2026-09-15 | 2.1.270 | 6 probes and 1 Haiku session | append-only, by snapshots and by system-call traces; what the interface can reach |
Not tested: automatic compaction at the context limit, /compact with instructions, sessions with tool calls before the compaction, and more than one run on Opus or on Sonnet. The reason for the Haiku summaries is our guess, not a measurement.