Claude Code context management: when to /clear and when to /compact

opwizardx1 pts0 comments

Claude Code context management: when to /clear and when to /compact | Tim Schipper

Skip to content

Claude Code context management: when to /clear and when to /compact<br>July 31, 2026·7m read time·$ shareCopy link

Claude Code context management: when to /clear and when to /compact<br>Context management in Claude Code got harder when the window got bigger. What /context actually measures, why /compact is a lossy re-encode of your session, and the rule I use for when to clear instead.<br>toolingAI

Run /context in a session that has been going since breakfast. Mine reports a wall of free space. No warning, no compaction notice, nothing red.<br>The session is still worse than it was at nine in the morning. The meter just has no way to say so.<br>Degradation starts long before the window fills ​<br>Chroma's context-rot work tested 18 frontier models and found every one of them gets less reliable as input grows, on tasks as simple as repeating words back. Their LongMemEval run is the cleanest illustration: the same question, answered from a focused ~300-token prompt or from the full ~113k-token conversation it was buried in. Same information present in both. Large gap in the answers.<br>NoLiMa puts a number on where it starts. Across 13 models that all advertise at least 128k of context, 11 dropped below half their short-context baseline at 32k tokens . GPT-4o went from 99.3% to 69.7%.<br>Thirty-two thousand tokens. On a 1M window that is three percent of the way in.<br>Anthropic describes the mechanism as an attention budget: every token attends to every other token, so n tokens means n² pairwise relationships, and each new token you add spends from a finite pool. Their own guidance is to find the smallest set of high-signal tokens that gets the job done. That is a strange thing to publish alongside a million-token window, and it is also correct.<br>What a long session does to the code ​<br>SlopCodeBench (arXiv 2603.24755, March 2026) is the study I have been waiting for on this. Instead of one-shot benchmarks it makes agents extend their own prior code across 93 checkpoints, with evolving specs and no corrected reference implementation handed back between turns. Eleven models, from Sonnet 4.5 up to Opus 4.6 and the GPT-5.x Codex variants.<br>The correctness numbers are grim on their own: no agent solved a single problem end to end, the best checkpoint solve rate was 17.2%, and by the final checkpoint strict solve rates collapsed to 0.5%. Cost grew 2.9× across a problem while correctness did not improve.<br>The quality numbers are the ones that should change your habits:<br>Structural erosion rose in 80% of trajectories. High-complexity functions went from 4.1 to 37.0 per codebase, peak cyclomatic complexity from 27.1 to 68.2.<br>Verbosity rose in 89.8% , with structural duplication up 66% across most trajectories.<br>Human-maintained repositories stay roughly flat on the same measures. Agent trajectories deteriorate with nearly every iteration.<br>Those are the same instruments I wrote about in the dashboard beyond coverage and mutation testing: complexity concentration and clone detection. Point them at a long agent session and they read as a downward slope.<br>The paper also tried the obvious fix. Quality-aware prompting cut initial verbosity by 34.5% on GPT-5.4, and the degradation slopes stayed parallel. You get a better starting point and the same decline. Session length is the lever.<br>The case for long sessions is real ​<br>A March 2026 paper argues that coding agents are effective long-context processors, beating published state of the art by 17.3% on corpora up to three trillion tokens. It is good work and worth reading before you take my side of this.<br>Read how it wins, though. The agents organise the text into a file system and manipulate it with ordinary tools. The corpus stays on disk and the window holds a working set. That result is not evidence that a bloated window is fine, it is evidence that the filesystem is where bulk belongs.<br>Which is the same conclusion from the other direction.<br>What /context actually measures ​<br>/context in Claude Code 2.1.220 breaks your window into named categories: system prompt, system tools, MCP tools, custom agents, memory files, messages, free space, and a line most people scroll past called Autocompact buffer . The status readout tells you the percentage until auto-compact, and there is a "Context low" warning further down the line.<br>That buffer line is the useful one. It is space you cannot spend, reserved so the model still has room to write a summary of itself when the moment comes. Your usable window is smaller than the number on the box, and it always was.<br>The /doctor command audits the other half of this: what your install loads into every session before you type anything. It scopes itself to disk-based estimates and explicitly points you at /context for the live measurement. Install hygiene and session hygiene are separate problems, and only one of them has a linter.<br>/compact is a model summarising itself...

context code window session from compact

Related Articles