Feature request: lossless context cleanup before auto-compaction
Problem
/compact replaces the entire conversation with a short summary. This is lossy — it destroys reasoning, decision context, and nuance. A 150k-token session where you spent 40 minutes mapping architecture becomes "We discussed the codebase architecture and identified key patterns."
But the majority of a typical session's context isn't conversation at all. From analysis of 33 real Claude Code sessions (full methodology and data):
| Content | % of context | Value on reload |
|---------|-------------|-----------------|
| Tool results (file contents, bash output) | ~60-70% | None — already synthesised by the model |
| Thinking signatures (base64 blobs) | ~15-20% | None — cryptographic verification, not reasoning |
| Actual conversation | ~10-15% | All of it |
Proposal
Before compaction triggers, stub mechanical overhead while preserving every message verbatim:
tool_resultblocks over N chars →[File read: src/auth.ts, 847 lines]tool_useinputs (Write/Edit file contents) →[Trimmed input: ~N chars]- Image blocks (base64 screenshots) → stripped
- Thinking block signatures → stripped
- Pre-compaction dead lines, file-history snapshots, queue operations → skipped
The model's own synthesis stays intact. If it needs a file again, it can re-read it.
Evidence
I built Contextual Memory Virtualisation (CMV) to test this approach. Results from the cache impact analysis across 33 real sessions:
- Benchmark-estimated reduction: 10.5% mean (conservative model that understates by ~2x — see methodology)
- Observed reduction: ~50% when validated against actual
/contextoutput (148k tokens → 74k tokens, documented with screenshots) - 97% context → ~20% on a near-full session using the v1.1.0 trimmer, with no observable quality degradation
- Zero conversation loss — every user message, assistant response, and tool use request is preserved verbatim
For API-key users, the one-time cache miss penalty from trimming ($0.07-0.22) is recovered within 3-45 turns of continued conversation. For subscription users, there is no cost implication at all — it's purely a context window optimization.
The community response suggests this is a widely felt pain point.
Why this matters
Context is the most expensive thing users build. It takes real time and real tokens to get Claude up to speed on a codebase. /compact treats that accumulated understanding as disposable. A lossless cleanup step before (or instead of) lossy compaction would let users keep working in the same session far longer without quality degradation.
The model doesn't struggle after trimming because you're removing inputs to understanding, not the understanding itself. When Claude reads 847 lines and responds "this uses JWT with refresh tokens in httpOnly cookies", that sentence is the knowledge. The 847 lines were consumed to produce it.
This issue has 14 comments on GitHub. Read the full discussion on GitHub ↗