beckon
Beckon blog

Claude Code Compaction: What /compact Keeps and What It Forgets

ยท Beau Johnson

In shortIn my test, Claude Code kept everything I typed through compaction (20 out of 20 in all six runs) but lost much of what the agent worked out itself (9, 15 and 10 out of 20 with a plain /compact). A focus line, CLAUDE.md and the on-disk transcript bring most of it back.

In this video I take one real Claude Code session, plant 20 facts in it, run /compact six times on the exact same history, and quiz the agent after each one. If you run long sessions with any coding agent, this shows you what the summary keeps, what it drops, and how to protect the parts that matter. These are numbers from my own test, not a guess.

What I cover in this video

  • 0:00 The agent told me 115 invoices were unpaid, then said "I don't know" one compaction later.
  • 0:47 Why compaction exists: the context window, context rot, and when Claude Code compacts.
  • 1:33 The idle timer most people miss, plus when Codex and Gemini CLI compact.
  • 2:19 How compaction works in four steps, including the nine sections of the summary.
  • 3:52 How Codex and Gemini CLI handle the same job.
  • 4:39 The test setup: 20 planted facts, one forked session, six compactions.
  • 5:24 The results: what I typed survives, what the agent figured out often does not.
  • 7:43 Four ways to protect what matters.

Why Claude Code compacts, and when

Every time your agent takes a step, the whole conversation gets sent to the model again: every message, every file it read, every test it ran. That is the context window. On Opus 5.5 and Sonnet 5.5 it is a million tokens, which sounds like a lot until a long session fills it with old tool output.

More context is not automatically better. Anthropic's docs call it context rot: as the token count grows, accuracy and recall go down. Chroma tested 18 models on this, and short focused prompts of about 300 tokens beat the same questions buried in about 113,000 tokens on every model they ran.

Claude Code compacts in three situations:

  • Automatically, at about 967,000 tokens on the million token models (see the model configuration docs).
  • By hand, any time you run /compact.
  • On an idle timer. If a session is past about 200,000 tokens and you leave it alone for about an hour, Claude Code compacts it before the prompt cache runs out. The docs put it this way: "After lunch, you continue from a summary."

Other agents do it too. Codex compacts at 90% of the window by default, and Gemini CLI starts at 50%. Whatever agent you run, at some point it is working from its own notes, not the real conversation.

How compaction works in four steps

  1. The trigger. Automatic at the limit, /compact by hand, or the idle timer.
  2. One separate request. Claude Code repeats your system prompt, your tools and the whole history, and ends with an instruction to summarize. The model is writing notes about its own conversation.
  3. The summary. I pulled the real summaries out of the test, and they had the same nine sections every time: the primary request, key technical concepts, files and code, errors and fixes, problem solving, all user messages, pending tasks, current work, and the next step. Section six, all user messages, quotes every message I typed, word for word.
  4. The swap. The old history is replaced by the summary. Claude Code then reloads a few things from disk: your project CLAUDE.md, your auto memory, your plan if you made one, and up to five files it worked on, newest first. A file over 5,000 tokens only comes back as a path. The last couple of messages stay word for word.

At the very bottom of the summary there is one more line: "If you need specific details from before compaction, read the full transcript at", followed by a file path. The old conversation is still on your disk. The agent just isn't looking at it.

Codex does the same thing with different words. Its fallback prompt is public on GitHub: "You are performing a context checkpoint compaction. Create a handoff summary for another LLM that will resume the task." It keeps your most recent messages, up to 20,000 tokens, and drops the rest. If you log in with OpenAI, that step runs on OpenAI's servers, and OpenAI's docs say the result isn't meant to be human readable. Gemini CLI runs a second pass that asks the model whether it left anything out.

The test: 20 facts, six compactions

I ran one real Claude Code session on Opus 5.5 in a fresh folder: 14 turns of real work building an invoice tracker for a made-up bakery, in plain Node and SQLite, with 122 passing tests by the end. Along the way I dropped in 20 facts in passing, the way you actually would: decisions (SQLite, because the host is one shared server), numbers (port 4317, a rate limit of 37 requests a minute), names, rules (never touch the legacy folder), three things we tried that failed and why, my preferences, and one do-this-later note.

The session ended at 245,578 tokens. I forked it so every run started from the exact same history, then ran /compact three times plain and three times with a one-line focus instruction. Each run took a minute to a minute and a half and squeezed the session to about 22,000 tokens, roughly 91% gone. Then came a 20-question quiz with every tool turned off and one rule: if you're not sure, say "don't know".

What I typed: 20 out of 20, every time

All six runs scored perfectly on the facts I planted. Every decision, every number, every reason. That is section six doing its job.

What the agent figured out: 9, 15 and 10

The second quiz covered 20 things I never typed: what the agent found when it ran a script on the old export log, its own explanations, decisions it made itself, where it saved a file, which commands got blocked. With no compaction it scored 20 out of 20. With a plain compact it scored 9, then 15, then 10.

In two of the three plain runs, everything from that log analysis was gone, including the 533 entries with floating-point noise and the 115 invoices still open. The agent had told me those numbers in its own reply, but the summary quotes my messages word for word and keeps only a short version of the agent's. Anthropic says the summary keeps architectural decisions, unresolved bugs and implementation details, and drops redundant tool outputs. A side finding from an old log is none of those.

The "why" went too. I told it PDFKit broke on the euro sign, and it worked out the reason: the built-in fonts can't draw it. After all six compactions my sentence was still there and its explanation was gone.

What survived every time were decisions that ended up in the code, like the reminder schedule, the retry rule and the login limit. And across 120 answers, it made up zero. Every miss was "I don't know".

Four ways to protect what matters

  1. Give /compact a focus. I added this one line as the focus instruction, and the same session scored 17, 18 and 15, up from 9, 15 and 10:

    Keep every decision and the reason behind it, every exact number and name, every rule I set, every approach we rejected and why, my preferences, and any open to-dos.

    You can also put that line under a Compact Instructions heading in your CLAUDE.md, or have a PreCompact hook print it.
  2. Put it on disk. Before compacting, I had the agent write what it found into CLAUDE.md (157 lines), then ran a plain compact. The log numbers came right back, because Claude Code reloads that file after every compaction: 16 fully right, 3 partly right. Anthropic's memory docs say the same thing: if it has to survive, put it in CLAUDE.md, not the chat.
  3. Let it look back. When I let the agent read files, the run that scored 9 went to 20 out of 20. It searched its own old transcript, the one the summary points to. If something feels missing, tell it to check the transcript.
  4. Keep the window clean. This one is from Anthropic's best practices. Run /context to see what is filling the window, run /clear between unrelated tasks, and send big reads to a subagent so the file content stays in its context, not yours.

Key takeaways

  • Claude Code doesn't forget what you tell it. It forgets what it learned on its own.
  • The summary quotes your messages word for word but keeps only a short version of the agent's own replies, so side findings and explanations are the first to go.
  • In my test, compaction caused "I don't know", not made-up answers: zero wrong answers out of 120.
  • A one-line focus for /compact and a write-up in CLAUDE.md recovered most of what a plain compact lost.
  • The full transcript stays on disk, and the agent can search it if you ask.

FAQ

When does Claude Code compact a session automatically?

On the million token models it compacts on its own at about 967,000 tokens. It also compacts when you run /compact, and when a session past about 200,000 tokens sits idle for about an hour, before the prompt cache runs out.

What does Claude Code forget after /compact?

In my test, everything I typed survived (20 out of 20 in all six runs) because the summary quotes user messages word for word. What the agent worked out on its own was less safe: a plain compact scored 9, 15 and 10 out of 20, losing things like findings from a script it ran and its own explanations.

How do I keep important details through a Claude Code compaction?

Give /compact a one-line focus (or put it under a Compact Instructions heading in CLAUDE.md), have the agent write key findings into CLAUDE.md before compacting, and tell it to check the transcript if something seems missing. In my test the focus line raised scores to 17, 18 and 15, and the CLAUDE.md approach got 16 fully right and 3 partly right.

Is the old conversation deleted after Claude Code compacts?

No. The full transcript stays on your disk, and the summary ends with a line pointing to its file path. When I let the agent read files, it searched that transcript and a run that scored 9 went to 20 out of 20.

Run your agents in Beckon

A workspace for your coding agents. Get more work done in less time.

Download BeckonSubscribe on YouTube
Full video transcript

0:005 minutes into a session, my coding agent told me 115 invoices in an old export were still unpaid. One compaction later, I asked it again. It said, "I don't know." But every single fact I typed made it through. 20 out of 20. What it lost was the stuff it figured out on its own. So, in this video, we're breaking down why compaction happens, what the summary actually keeps, our 20 fact test, and how to protect what matters. I ran this on a real claude code session. So these are our numbers, not a guess. Let's jump right into it. So why does an agent summarize itself at all? Every time your agent takes a step, the whole conversation gets sent to the model again. Every message, every file it read, every test it ran. That's the

0:47context window. On Opus 5.5 and Sonnet 5.5, it's a million tokens. That sounds like a lot until a long session fills it up with old tool output. And more isn't automatically better. Anthropic's own docs call it context rot. As the token count grows, accuracy and recall go down. Chroma tested 18 models on this last year. Short focused prompts of about 300 tokens beat the same questions buried in about 113,000 tokens on every model they ran it on. So, Claude Code Compacts on the million token models. It does it on its own at about 967,000 tokens. You can also run it yourself anytime with /compact. And most people skip right past this one. If a session

1:33is passed about 200,000 tokens and you leave it alone for about an hour, Claude Code compacts it before the prompt cache runs out. Their docs literally say, "After lunch, you continue from a summary." Which is kind of wild. Your agent's memory got rewritten while you were eating a sandwich. Cloud code isn't the only one doing this either. Codeex compacts at 90% of the window by default. Gemini CLI starts at 50%. So whatever agent you run, at some point it's working from its own notes, not the real conversation. So what's actually in those notes? What if a new video for your business showed up every morning? Nightcrew learns your business once, then makes a short every night in your own voice. It runs five brands right now. Over half a million views a week.

2:19Nightcrew. Nightcrew.studio. Here's how it actually works in four steps. Step one, the trigger automatic at the limit/compact by hand or that idle timer. Step two, cloud code sends one separate request. It repeats your system prompt, your tools, and the whole history, and it ends with an instruction to summarize. So, the model is writing notes about its own conversation. Step three, the summary. We pulled the real ones out of our test and they had the same nine sections every time. The primary request, key technical concepts, files and code, errors and fixes, problem solving, all user messages, pending tasks, current work, and the next step. Zoom in on section six for a second. All user messages. Every message

3:06I typed quoted word for word. Remember that one because it decides our whole test. Step four, the swap. The old history gets replaced by that summary. Then cloud code puts a few things back from disk. Your projectclaw.md, your automemory, your plan if you made one, and it rereads up to five files it worked on, newest first. A file over 5,000 tokens only comes back as a path. The last couple of messages stay word for word, too. And at the very bottom of the summary, there's one more line. If you need specific details from before compaction, read the full transcript at and then a file path. So the old conversation is still sitting on your disc. The agent just isn't looking at it. Codex does the same thing just with different words. Its fallback prompt is

3:52public on GitHub. You are performing a context checkpoint compaction. Create a handoff summary for another LLM that will resume the task. It keeps your most recent messages up to 20,000 tokens and drops the rest. If you log in with OpenAI, that step runs on OpenAI's servers instead. And OpenAI's docs say the result isn't meant to be human readable. And Gemini CLI even runs a second pass asking the model, did you leave anything out? So, a summary written by the model plus your files on disk. Sounds pretty safe, right? So, we tested it. Here's what we did. One real Cloud Code session on Opus 5.5 in a fresh folder. 14 turns of real work building an invoice tracker for a madeup bakery. Plain node SQ Lite 122 passing

4:39tests by the end. Along the way, I dropped in 20 facts the way you actually would in passing. Four decisions like we're using SQ Lite because her host is one shared server. Four numbers like port 4317 and a rate limit of 37 requests a minute. A few names, rules like never touch the legacy folder. three things we already tried that failed and why my preferences and one do this later note. By the end, the session was 245,000 tokens. Then we forked it. So every run started from the exact same history and ran / compact. Three times plain and three times with a oneline focus instruction. Each one took a minute to a minute and a half and squeezed the session down to about 22,000 tokens.

5:24That's about 91% gone. Then the quiz, 20 questions, every tool turned off so it can't peek at the files, and one rule. If you're not sure, say don't know. And as a control, the same quiz on the session with no compaction at all. 20 out of 20. So the 20 facts I planted, plain compact, 20 out of 20. Next run, 20 out of 20. All six runs, perfect. Every decision, every number, every reason I gave. And that's section six doing its job. Every message I typed was right there in the summary, word for word. I almost stopped there, but that's only half of a session. The other half is everything the agent figures out by itself. So, we wrote a second quiz, 20

6:10things I never typed, what it found when it ran a script on the old export log, its own explanations, decisions it made on its own, where it saved a file, which commands got blocked, no compaction, 20 out of 20. plane compact nine then 15 then 10. Okay, so this is the sneaky part. In two of the three plane runs, everything from that log analysis was gone. 1,039 of 141 entries with too many decimals. 533 with floatingoint noise. 115 invoices still open. Don't know. Don't know. Don't know. All of that came from one script it ran early in the session. And it even told me those numbers in its reply. But the summary quotes my messages word for word and

6:56only keeps a short version of its own. Anthropic says Claude code summary keeps architectural decisions, unresolved bugs and implementation details and drops redundant tool outputs. A side finding from an old log isn't any of those. So in two of three runs, it got cut. The Y went too. I told it PDF kit broke on the Euro sign. It figured out the reason. The built-in fonts can't draw it. After every single compaction, my sentence was still there. Its explanation was gone. Six out of six. What survived every time were the decisions that ended up in the code. The reminder schedule, the retry rule, the login limit. The summary lists them and it rereads the files it just edited. Across all six runs, 120 answers. It made up zero. Not one wrong

7:43answer. Every miss was, "I don't know." Chroma saw something similar in their report with the clawed models they tested. When the answer was buried, they held back instead of guessing. So, it doesn't forget what you tell it, it forgets what it learned. So, how do you protect the stuff it learns? Four things. And the first three come straight from our test. One, give compact a focus. We added one line. Keep every decision and the reason behind it, every exact number and name, every rule I set, every approach we rejected and why, my preferences, and any open to-dos, same session, 17, 18, and 15 out of 20, up from 9, 15, and 10. You can also put that line under a compact instructions heading in your claw.md or

8:29have a pre-ompact hook print it and claude code uses it for the summary. Two, put it on disk. Before compacting, we had the agent write what it found into claude.mmd. 157 lines, then a plain compact. The log numbers came right back because claude code reloads that file from disk after every compaction. 16 fully write, three partly right. Anthropics docs say the same thing. If it has to survive, put it in claw.md, not in the chat. Three, let it look back. When we let the agent read files, the same run went from 9 to 20 out of 20. It searched its own old transcript, the one the summary points to. So if something feels missing, just tell it. Check the transcript. Four, and

9:14this one's straight from Anthropics docs, keep the window clean. Run / context to see what's actually filling it. Clear between unrelated tasks and send big reads to a sub aent so all that file content stays in its context, not yours. Less noise in there means less to lose. So, here's what I want to know. Has your agent ever lost something after a compact? And did you catch it right away or an hour later? Put it in the comments. And if this one saved you a headache, a thumbs up on the video helps a lot. Have a blessed day.