Claude Code - Figured out why /compact loses so much useful context - and a potential fix
the `/compact` command drives me crazy sometimes - hit it to save context space, then 30 minutes later realize i need to reference something that got summarized away
been using claude code for about 7 months now on some fairly complex projects
the /compact command drives me crazy sometimes - hit it to save context space, then 30 minutes later realize i need to reference something that got summarized away
the problem with current `/compact`:
happens server-side (no local backup of what was summarized)
treats all content equally when summarizing
original content is permanently lost
can’t selectively restore specific tool results later
but here’s the thing - tool results are mostly re-fetchable, files can be re-read, greps can be re-run
why permanently lose them in summarization?
—
research & analysis
spent some time analyzing what actually fills up the context window during long sessions:
- 68% tool results (file reads, grep outputs, etc)
- 23% tool use inputs
- 6% user messages
- 3% assistant responses
the thing is - most of those tool results are re-fetchable, file contents can be re-read, grep outputs can be re-run
but once `/compact` runs, they’re gone from context permanently
(this is when i realized that `/compact` command happens server-side, i thought it would write the JSONL logs of the compacted conversation, but NO)
--
Cursor just published their “dynamic context discovery” approach
which handles this quite differently - instead of truncating long tool responses, they write them to files and let the agent fetch what it needs
got me thinking - what if /compact worked similarly?
write original content to local files before compacting
replace context with summaries + file references
add commands to selectively restore specific messages when needed
i built a quick prototype to test (based on my local JSONL logs):
4.6MB session: 277k tokens → 46k tokens (83% reduction)
900KB session: 47k tokens → 9.6k tokens (79% reduction)
i think it works.
—
so i filed a feature request on github with the full proposal:
https://github.com/anthropics/claude-code/issues/17428
curious if others run into the same frustration or if i’m just using claude code wrong
or if you think it would be helpful, please give it a push to get some attention from Anthropic’s engineers
--
ps.
i’m totally aware of the existing “context editing” feature of claude code:
but i believe the cursor’s approach can be an enhancement of claude code `/compact` command
if this is achieved, it would give us more control on the context engineering part and also help claude code handles long-running tasks better
wdyt?





