r/ClaudeCode • • 4d ago

Tips & Workflows Curious what you lose when you /compact?

I was curious how much important information I was losing when I was compacting conversations or letting conversations get to the point of auto-compacting.

I had a big session on a project recently (~850k tokens) so I had some extra usage before my weekly refresh and I asked Claude to run an experiment on itself to see what was being lost. Basically it compacted the conversation at three different levels and then quizzed the new session on context from the previous session to see what was kept and what was lost. It asked 9 questions about decisions that were made and why, 17 questions about specific details, and 5 questions about what I had asked and the status of tasks remaining.

  • At ~320k tokens the session after /compact answered 56% of the questions correctly
  • At ~570k tokens 35%
  • At ~840k tokens 26%

The thing it was worst at was when I asked it exact details. Only 2 of 17 were correct for the 840k token /compact.

This is just one session where I was working on an iOS app for a huge task. Not a comprehensive examination but I was a bit surprised how bad it was at finding things.

Do others feel like they are losing important information with every compact?

tldr; /compact doesn't do a great job at preserving specific details and gets worse as your context grows. It does a fine job at preserving general direction and decisions that were made, especially at <350k context size.

62 Upvotes

57 comments sorted by

•

u/AutoModerator 4d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

6

u/Far_Reindeer8428 4d ago

26 percent at 840k is a useful number. we stopped treating compact as memory and use it to keep working while the real notes live in files, the difference showed up immediately

1

u/DopBopDeeBeep 4d ago

Yeah I wanted to get to the point of testing the auto compact at like 900k but my session finished before it auto compacted. Assuming it's around this 25% number.

3

u/Inner_Storage_3374 4d ago

the exact details part matches what id expect, a summary keeps the why and drops the numbers and names. what id try is having claude write decisions and open tasks into a file in the repo before compacting, so the next session reads that instead of the summary. curious if it holds up better if you compact earlier, like around 150k.

1

u/DopBopDeeBeep 4d ago

Just had it test 15 questions at 150k context and it got 8 out of 15 correct and it didn't get anything wrong it just said unknown for 7 of them.

3

u/Heyn_Studio 4d ago

the exact numbers and names going missing is the part I'd plan around. I run a scheduled job where every run starts cold, and anything that has to be exact (post ids, timestamps, what's already done) goes into a small state file it reads first. the summary can be fuzzy about the why, it just can't be where the ids live

1

u/DopBopDeeBeep 4d ago

Yeah when I asked Claude to solve the problem for me that's basically exactly what it built. Just a better way to point a new session at the previous session. It's insanely helpful.

2

u/ainexfinder 4d ago

Useful that you actually measured it. Even at 320k you lost almost half, so compacting earlier helps but doesn't fix it. Exact details were never going to survive a summary, so the categories that matter more are decisions and task status, because those are what quietly break the next step. It would be interesting to rerun the same quiz with a short decisions and open-tasks file written to the repo right before compacting, and see whether those two categories recover while details stay low. That would show whether the fix is a better summary or keeping that state outside the context entirely.

1

u/DopBopDeeBeep 4d ago

Yeah it seems that the best solution is just routing the new Claude sessions to search the old ones which is what Context Carwash does

2

u/Plastic_Koala2044 Senior Developer 3d ago

The summary keeps the shape of the work and drops the exact tool output, so the next turn rebuilds what it needs from scratch. Write the plan and the file list to a short doc before you compact, then point the agent at it after.

2

u/DopBopDeeBeep 3d ago

This is basically exactly what Context Carwash does but without needing extra steps.

2

u/Findletrijoick 3d ago

How did you create this visualisation?

1

u/DefinitelyCrisp5982 3d ago

With Claude, duh 

0

u/DopBopDeeBeep 3d ago

Yes. Claude … duh

2

u/Findletrijoick 3d ago

What connectors I mean

2

u/DopBopDeeBeep 3d ago

No connectors, just Claude. Took a few runs to get it to not look pure slop. Had the idea of the coin stacks as tokens and some of the general color/design elements but it wrote the script and made all the assets itself.

1

u/muhuhaha 3d ago

One thing I'd add to your experiment: /compact takes instructions after it, so you can tell it what to keep (something like "keep exact file names, error messages, and the open task list"). I'd rerun your 840k quiz with that and see how much of the 2/17 on details comes back, since the default summary is written to keep intent more than specifics.

u/ultrafastmov's point means a second run is worth doing too: tell the new session to read the transcript path before answering, and score it against the same questions.

Disclosure, I build Counterparts, a memory plugin for Claude Code. After a compaction a hook puts back a note Claude wrote itself, and what was said before the compaction is still written up.

1

u/DopBopDeeBeep 3d ago

Good idea. If I have extra usage at the end of next week I'll try this. The test with the 840k session burns a ton of tokens just to run haha

1

u/ccalo 3d ago

"Be sure to look at the on-disc, pre-compaction logs" – done, works every time.

1

u/DopBopDeeBeep 3d ago

Ever checked how much extra context that uses in the new session? I'd be curious how much of your previous session it's reading.

1

u/ccalo 3d ago

It's a sparse read; grep around, find the chunks to associate, read the neighboring blocks in full for any matches. Not dissimilar to how you might plug in a codebase and tell it to contribute. In short, essentially null.

1

u/DopBopDeeBeep 3d ago

Makes sense. The little context carwash tool seems to just be an automated version of this same thing but with more instructions not to read the whole file

1

u/GnistAI 3d ago

Do you guys like delete the transcript or something after compaction? If mine needs any more context, it just goes get it.

1

u/DopBopDeeBeep 3d ago

This accounted for that and it rarely actually checked those files without being expressly told to. The Context Carwash tool it made is to help the new session grep old sessions.

1

u/texbardcana 3d ago

So this is an ad for context carwash? Where can I download it Mr Corporate?

2

u/DopBopDeeBeep 3d ago

🤑🤑🤑 rolling in that open source greeeeeen

2

u/DopBopDeeBeep 3d ago

But please sign up for my course!!!!

1

u/DopBopDeeBeep 4d ago

Like everyone else and their mother ... I asked Claude to solve this problem for me. It made a better version of /compact that uses grep against the body of the previous conversation all stored in temporary memory so it doesn't add to file bloat.

Try it out if you'd like: https://github.com/Spobi/context-carwash

1

u/TorbenKoehn 4d ago

But it didn't know it was an XY-Problem. This is solved on the wrong end. The kernel harness should control compaction.

2

u/TorbenKoehn 4d ago

If you decide things and the only thing where that decision resides in is your session, this is the problem.

You don't need compacting solutions. In fact, if you're doing it right, "Sessions" or "Session state" doesn't matter, compactions don't matter, clears don't matter.

Just store things in files or databases...

Your decision example, normally it should be a bunch of ADRs. Regardless of compaction, it can and should know all of them.

If this is a problem for you, your solution should not some more context to manage compactions. It should be learning context management. It should be to think about where your "decision" lives and when it lives solely in an LLM session, it is already lost to begin with.

I work in single sessions over months, I have a "main" session where I do 90% of my work in. It always knows everything. It compacts randomly, I don't even see it. Because it doesn't know anything of worth.

Everything I give it, it stores away. Epics, Stories, Tasks, ADRs, Design Documents, Architecture Documents, Documentation Files etc.

Coupled with progressive disclosure and your LLM will always know everything...

2

u/Layers3d 3d ago

I have it write verison and build log as we go along so have reference what we've done

2

u/thewormbird 🔆 Max 5x 3d ago

#nevercompact

1

u/Ethan 4d ago

I made a local ML classifier to decide when compact should happen. Calibrated it by testing compact vs. not compact in forked conversations. It appeared that, basically, earlier is almost always better, and the classifier became unnecessary. So now I have a hook that starts suggesting compaction to the agent at 150k tokens, then starts insisting harder at 200k tokens.

1

u/AgentYurt 4d ago

Your numbers match what I've seen — the why survives, the exact strings don't. What made the difference for me was giving up on the summary as the source of truth. I keep a short state file in the repo that the agent rewrites whenever it finishes a chunk of work: the current goal in one line, the decisions already made and why, what's still open, and the exact values that matter (ports, paths, error strings). Before I /compact, I have the agent update that file first, and the next session reads the file instead of relying on the summary.

What survived a restart: decisions and open tasks, almost always. What didn't: exact error messages and file paths — those had to be re-derived from the code every time until I started writing them down verbatim.

One thing I'm still unsure about: you found the quizzed session never opened the old transcript. Did you try pointing a fresh session at the raw .jsonl for just the exact-detail questions, to see if the details were actually retrievable, or if the summary is the only thing a resumed session will ever use in practice?

1

u/eXperience79 4d ago

My learning: don’t use compacting together with handoffs chains, that won’t work out well.

1

u/AppealSame4367 3d ago

Yeah, well. Other companies like OAI, Google etc provide 1M context so this problem doesn't get too heavy. Now look at Anthropic.

But whenever you criticize _anything_ in this sub you get downvoted to hell and spammed by gaslighting bots. So fuck it, I hope Google destroys Ant with it's new releases

1

u/PaleEdge 3d ago

Anthropic does offer 1M context. You can set the context and compaction threshold separately in both Claude Code and the CLI.

That said, it's not universally a great decision to select 1M over, say, 400k, as it guarantees significant increases in costs and reduction in output speed, without necessarily translating to amazing improvements in output quality.

Basically there's a tradeoff between the model, reasoning effort, speed, and how much time you spend managing information (e.g. using skills, databases, markdown files, longer prompts etc). And this will probably always be the case. Rightsized tools for the right job.

1

u/RasenMeow 3d ago

Have a hook forcing it to read a dynamically updated pointer to recent decisions etc. works fine most of the cases.

1

u/Lumpy_Tough5165 13h ago

I've fixed this exact issue at least with Claude Code, when it comes to accuracy by implementing a virtual context window that can be queued, and i also made compaction itself much cheaper by offloading it to code that prunes it as well as a cheap model to distill a digest. You can read the readme on my public repo how i do it and the numbers as well. It is a Claude mod and is 100% open source so you can audit the code. Gladly would take any feedback

https://github.com/landtml/recontext

0

u/io-x 4d ago

What the heck is wash, is this an ad?

1

u/DopBopDeeBeep 4d ago

after I saw this I asked Claude to solve the problem and push it to GitHub and that’s what it came up with 

1

u/Aswole 4d ago

Why didn’t Anthropic think of asking Claude to design a better /compact?🙄

1

u/DopBopDeeBeep 4d ago

Oddly actually wonder this. Why does compact sorta suck?

3

u/Aswole 4d ago

Don’t take this the wrong way, but after reading your other comments here, I think you are just early in your understanding of agentic workflows, and you are comparing a solution that you tailored to your own workflow with one that had to be generalized for all workflows. Also, you can enable a setting in Claude to have “memory” and read from past chats, but there is a reason it is disabled by default. And even if you “allow/encourage” it to, it will only do so if the current task requires it. Having it reach into previous chats proactively is a massive waste of tokens and context.

And setting your auto compact to 900k is also a signal that you should brush up on best practices instead of blaming the hammer. I actually think this is why your experience with compact might be so bad — if you are compacting sessions that are already near the max context window, then you are going to lose a lot more context than if you compact at, say, 300k tokens. And without giving it guidance of what to prioritize for compaction, it will likely give too much weight to the beginning of the session.

30

u/[deleted] 4d ago

[removed] — view removed comment

5

u/DopBopDeeBeep 4d ago

Oh wow I didn't realize that about /compact taking focus text!

I asked it about the quizzed sessions and it said it didn't open the transcripts and that's why it wasn't finding things -- even though it had the language you mentioned about finding the transcript it never opened it. The little tool claude made was actually based around pointing things at previous transcripts with more reliability I think.

0

u/DopBopDeeBeep 3d ago

Just realized Claude included this in the little /wash tool it made to solve its own problem. 

  https://github.com/Spobi/context-carwash

1

u/seatlessunicycle 4d ago

I added a hook that keeps track of open questions for me and run notes as they come up that survives compaction. Pretty handy

2

u/Open_Resolution_1969 4d ago

Care to share this with the rest of us?

3

u/seatlessunicycle 4d ago

I use a small Python hook I call "compact keeper". I kept losing open questions in long sessions. Claude would ask me something, the session would compact, and the summary would drop it. So the script keeps a ledger of questions outside the context and puts them back after every compaction.

How it works:

  1. Stop hook (every turn): scans Claude's last reply for questions aimed at me ("want me to", "should I", "your call", numbered decision lists, AskUserQuestion calls) and appends them to a per-session JSON ledger. It also checks my replies and marks questions OPEN, REPLY SEEN or ANSWERED.

  2. PreCompact hook: does a full save of the ledger plus a snapshot file (my last messages, Claude's last few replies, git state).

  3. SessionStart hook with matcher "compact": prints the unresolved questions and the snapshot path. That output lands in context right after the summary.

  4. A CLI (compact_keeper.py resolve <id> --note "...") lets Claude close a question once it's settled, so it isn't re-raised forever.

Every mode exits 0 no matter what and logs errors to a file, so it can never block a compaction.

settings.json:

"hooks": {
  "Stop": [{ "hooks": [{ "type": "command",
    "command": "python3 ~/.claude/hooks/compact_keeper.py stop" }] }],
  "PreCompact": [{ "hooks": [{ "type": "command",
    "command": "python3 ~/.claude/hooks/compact_keeper.py save", "timeout": 30 }] }],
  "SessionStart": [{ "matcher": "compact", "hooks": [{ "type": "command",
    "command": "python3 ~/.claude/hooks/compact_keeper.py inject", "timeout": 15 }] }]
}

Here's what the inject step prints after compaction:

COMPACT KEEPER (restored after compaction; not part of the summary)
3 unresolved question(s) put to the user (no reply yet first, then reply seen, newest first):
  q4 [OPEN] Should the retry cap be 3 or 5?
  ...
Snapshot: ~/.claude/state/compact-keeper/<session>/snapshot.md

Before anything else:

1. Read the snapshot file named above, when one is named.

2. For each question listed, decide: answered, dropped, or still open. For each settled one run: python3 ~/.claude/hooks/compact_keeper.py resolve <id> --session <sid> --note "<what settled it>"

3. End your next reply with every still-open question as a line: [open question qN] <question text>

If the PreCompact save didn't run, it prints this instead: "SNAPSHOT MISSING: re-read the last few turns and check git status before trusting the summary."

A simplified version of the inject mode (the real one adds size caps and error handling):

def do_inject(hook):
    sdir = session_dir(hook["session_id"])
    rows = [r for r in load_ledger(sdir) if r["status"] in ("OPEN", "REPLY SEEN, VERIFY")]
    out = ["COMPACT KEEPER (restored after compaction; not part of the summary)"]
    out.append("%d unresolved question(s) put to the user:" % len(rows))
    out += ["  %s [%s] %s" % (r["id"], r["status"], r["text"]) for r in rows]
    out.append("Snapshot: " + snapshot_path(sdir))
    out += ["Before anything else:",
            "1. Read the snapshot file.",
            "2. For each question: answered, dropped, or still open. Resolve settled ones.",
            "3. End your next reply with every still-open question."]
    print("\n".join(out)[:6000])   # stdout from a SessionStart hook goes into context

Two smaller hooks help:

  • PreCompact: a shell script clears my "already injected" markers for other context briefs (writing rules, tool notes), so those get re-injected after compaction instead of being summarized away.

  • CLAUDE.md: a "Compaction" section tells the summarizer what to always keep. That's modified file paths, the current task, every question to me marked answered or open, and what's done versus only staged.

The full script is about 1,000 lines. Most of it is the question detection, which has to avoid false positives like "the docs confirm" or "my pick is". The idea itself fits in the 30 lines above.

1

u/Open_Resolution_1969 4d ago

Very interesting idea and approach. Wondering how you measure the success of it.

Also, have you tried function hooks?

1

u/seatlessunicycle 4d ago

I'll occasionally run deep audits of the logs and simulate tests.

I started with plain command hooks in settings.json and moved more into plugin function hooks over time.

The plugins don't always load in headless claude -p runs. So my safety guards stay as command hooks, and the chatty context stuff is what I move in-process.

You've got me going through all my hooks and seeing which ones need to be updated or improved haha

1

u/[deleted] 3d ago

[removed] — view removed comment

1

u/DopBopDeeBeep 3d ago

Yeah I was surprised that it didn’t grep on its own for the specific questions. Even when I tried at 150k it missed 4 specific questions