Joel Pennell

What my AI loses when it compacts

The short version. If a Claude Code session passes 200,000 tokens and sits idle for about an hour, it may be condensed into a summary to save usage ("idleCompaction": false in settings turns that off). In my sessions the summaries kept my decisions but got the AI's own actions wrong, for example saying a reply hadn't been sent when it had. The full transcript is already on disk, so the fix is to read it back after each compaction. My hook for that is linked at the end.

Written against Claude Code 2.1.316, 1 November 2026. This behavior changes often (idle compaction paused for two days at the end of October, then came back; see below), so check your own version's changelog.

On big projects I keep a Claude Code session going until the work reaches a natural stopping point, which can mean all day, sometimes across days. Then Claude wraps the session up into a hand-off note, and the next session starts fresh from it. In early October my sessions started doing something new. I'd step away for lunch, come back, and find the conversation had been condensed into a summary while I was gone. Picking up again meant pasting a recovery prompt, checking what had been lost, wrapping the session up properly, and starting a fresh one.

I asked Claude whether this was a bug, a feature, or just me. What we found is worth sharing, partly because there's a setting other Claude Code users may want to know about, and partly because of where the gaps in the summaries turned out to be.

It's a feature, and it saves usage

Claude Code sends the whole conversation to the model on every turn. While the conversation is in Anthropic's prompt cache, the repeated part is billed at a much lower rate. On a subscription that cache lasts an hour. The first message after it expires reprocesses everything at full price, which in a very long session takes a real bite out of a weekly usage limit.

So Claude Code now compacts a large session (over 200,000 tokens) once it has sat idle for about 55 minutes, just before the cache expires. The changelog says about 54; my sessions compacted at 54 to 56. Compacting is cheap, and every turn after it carries a summary in place of the full history. The trade is detail for usage.

It arrived with no release note. A commenter on the GitHub issue (anthropics/claude-code #98747) found it was controlled by a switch on Anthropic's side, which would explain why. People objected to it being on by default. Within a few days an Anthropic engineer said a setting was coming, and according to the issue, Claude Code 2.1.290 added one. It's documented now, in the changelog under 2.1.299.

My first reaction was to wonder whether the problem was me. As I put it at the time: "It's really hard for me to think that my process is better than what people inside of Anthropic are considering." Claude's answer was that a default is tuned for the average session, and an opt-out is how a vendor admits a default doesn't fit everyone.

I turned it off. Later the same day I turned it back on. Partly I wanted the usage savings: Anthropic made it the default, and I assumed they had a reason. Partly it's a safety net for the days I forget to wrap a session up and start a fresh one. What I did know was that I didn't want to keep losing detail, so the question became whether we could keep the savings without paying for them in detail.

The obvious fix was the wrong one

Claude's first proposal was to save decisions to a file as we made them, so nothing could be lost.

I pushed back. Things written down in the middle of a session tend to become gospel. A note written at 12:05 can't know what gets overturned at 3:00, and it still reads as settled. The wrap I do at the end of a session is more like translating a whole codebase: re-expressing the session from the full view, once the picture is complete. That same day Claude had recorded one of my quick yes answers, to one thing, as closing a different thing, which is the risk exactly.

What the summaries actually lost

So instead of guessing, Claude had a separate agent study what had really happened. Of the 49 compactions on my disk, I had recovered from 19, in 16 recoveries across 7 projects between 9 and 14 October. The agent read what each of those recoveries had found missing from the summary.

In that sample, none of my decisions or corrections was dropped. Some threads were cut down to bare labels, and one question Claude had asked me disappeared.

The errors that mattered, in 6 of the 16 recoveries, were about the AI's own loose ends. A summary would say a reply hadn't been sent when it had gone out 55 minutes earlier. Another would say a promised task was done when it had never been started. My words came through. The AI's record of its own commitments is where the gaps were.

The full record already existed. Claude Code writes each turn of a session to a transcript file on disk, and compaction doesn't change that file. Saving as you go was already happening. The missing step was reading it back at the right moment.

The fix: read the record back

What we built is small: a Claude Code hook (a SessionStart hook with the matcher compact) that runs when a session resumes after compacting. It reads the transcript and writes a short ledger:

  • everything I typed in that session, word for word, with times (so the ledger files keep what you type, and nothing deletes them unless you do);
  • whether the last turn before the compaction had ended, and when, so "did that reply go out?" has a factual answer;
  • the AI's own open promises, the "I'll do X next" lines, labelled as candidates to check.

The resumed session is told to compare its summary with the ledger and say, in three lines, what the summary dropped, whether the last reply went out, and what's still open. Then it keeps working. During the day there's no forced wrap and no recovery prompt from me.

A reader suggested a step I hadn't tested: a "Compact Instructions" section in CLAUDE.md that tells the summary what to keep. I added one asking it to list every action already taken. In the next six compactions, four summaries carried that list, and the ones I checked were accurate about what had been done. But all six still listed the last reply as something to do, though it had already gone out. Claude Code keeps the last few messages word for word after the summary and, by its own note, writes the summary without seeing them, so the summary has no way to know that reply was sent. The same held for every compaction on my disk that followed a long pause: 136 since August, counted on 2 November. So the section is worth adding, and I'm keeping the hook that reads the transcript back. (Updated 2 November.)

A second reader asked for a note, kept outside the chat, of every action the agent finished. Each one is already in the transcript as a tool call and its result, so the hook now lists them after a compaction: commits, pushes, deploys, messages and posts, each marked as run cleanly, failed, started in the background, or run with its exit status hidden. Two reviews on another model found eleven must-fix problems (and more smaller ones) before it held, the worst being a failed push reported as a success; every one is fixed and now a test. On five real transcripts, its commits and pushes matched a separate count, call by call. It can't recognize an action run through a script of my own, and a click that ran isn't proof that anything posted, so the list is a record to check, not proof. I also checked how often it matters: in 141 compactions after a long pause, counted on 4 November, I found one summary that called an already-finished action pending. The error that keeps happening is still the last reply. (Updated 4 November.)

A second model found what the tests missed

Before I installed it, Claude had a checker on a different model review the design. It found four must-fix problems. The worst was about timing: the hook ran before the current compaction had been written to the transcript, so it described the previous one. The design's own tests had all run on finished transcripts, where everything was already in place, so they couldn't see it.

Another was the gospel problem again. Prompts the AI had scheduled for itself were coming back labelled as my words, including one that read like an authorization I'd never given. After two rounds of fixes, each re-tested, it went in.

How it has gone

The first day wasn't clean. The ledger caught a summary saying a reply hadn't been sent when it had gone out 55 minutes earlier, but that evening it missed one of Claude's promises: the promise was in the ledger file but not in the short notice the session reads. We patched that the next day. In the 10 compactions after that which Claude checked by hand against the full transcript, the ledger's facts were right every time.

The blind spot didn't go away; the ledger just catches it. In 6 of the 8 of those whose summaries we read closely, the summary said a reply was still to be written when it had already gone out. A rough keyword search found the same kind of line in later summaries too. We haven't checked each one.

Over the next ten days my sessions compacted while idle 64 more times, across 8 projects. Those we scored by script: did the session open with the three lines? When I came back and simply typed my next thought, it did in 24 of 27 cases. Two sessions skipped them and went straight to work, and one was woken by a command I typed rather than a message.

The surprise was me. Over nine days at the end of October (22 to 30 October) I kept pasting the old recovery prompt anyway, 22 times: mostly habit (the test routine also asked for it once, at the end of each day). The session then ran the full recovery the hook was meant to replace, and usually skipped the three lines. The fix worked before my habit caught up with it. Now, when the notice appears, I just keep working.

One thing is still open. From 30 October to 1 November none of my sessions compacted while idle, even ones that sat for hours at well over 200,000 tokens. Then on the morning of 1 November two did, each about 55 minutes after my last message, with no Claude Code update since 31 October. It isn't my move to a million-token working window: sessions compacted while idle both before and after that. Nothing in the changelog explains the pause. The feature first arrived through a switch on Anthropic's side, so it may have been switched off and back on. I don't know.

What I'd pass on

  • If you run long Claude Code sessions, idle compaction may be happening to you. "idleCompaction": false in ~/.claude/settings.json turns it off, and CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS changes the size at which it starts. Keeping it on saves usage and costs detail; that choice is yours.
  • The transcript is already on disk. Before building something to save your work as you go, see whether reading back what's already saved does the job.
  • When you check what a summary lost, look first at what the AI said it would do. In our sample that's where the errors were.
  • A SessionStart hook with the matcher compact is the place to put a read-back like this. Have someone other than whoever built it test it the way it will really run.
  • When you change a routine, change the habit too. Mine lagged the fix by two weeks.

When I'd use which setting

There are two knobs, and they trade the same two things: usage and detail.

  • Idle compaction ("idleCompaction" in settings) condenses a big session that has sat for about an hour. Keep it on when usage is tight and your sessions sit idle often (lunch, overnight, a long render). Put a read-back hook beside it, so what it gets wrong is caught. Turn it off when you have usage to spare and would rather pay for the full history than check a summary.
  • The working window (/autocompact) sets how full a session gets while you're working before it compacts. A smaller window keeps every turn cheaper; I ran mine at 400,000 tokens for a while. When I had extra usage in late October I moved it to the full million, because I wanted the detail more than the savings.
  • Either way, wrap at natural stopping points. Compaction only stretches one session. What stops drift from one session to the next is an end-of-session wrap from the full view, and a fresh start. I wrap at the end of the day, or after a session's second compaction, since each compaction summarizes the summary before it.

Why this matters

In the summaries I read, my decisions and corrections came through. What they lost track of was what the AI had already done. In a chat that's an annoyance: a summary says a reply hasn't gone out when it went out 55 minutes ago, and the hook catches it. An agent that acted on that line would send the email twice. As more of the work becomes the agent acting rather than talking, my bet is that the record that counts moves from "what was said" to "what happened": a log the tool keeps, not the agent's own summary of itself, read back before it acts again. The hook is a very small version of that.

One more thing from the last few days: idle compaction stopped on 30 October and came back two days later, and I can't say why. Nothing of mine broke either way, because the record the hook reads was on my own disk all along. Whatever the tools do next, that's the part I'd keep.

The hook is public, with two others I run, at github.com/joelpennell/claude-code-hooks (MIT). Each comes with a note on when to retire it, because models and Claude Code keep changing, and with a prompt that has your own agent read the code and show you every change before installing it.

All writing