Published 30 October 2026. Updated 11 November 2026 with NVIDIA's paper on short-context agents and the Memorilla paper, both read in full, and with Claude Code's current compaction documentation. Prices are Anthropic's list prices, re-read from the Claude pricing page on 11 November 2026 and unchanged since publication. Claude Code, Claude API and OpenAI behaviour comes from each vendor's documentation, read the same day.
Compaction is cheap when the prompt cache is still warm and expensive when it has expired, and retrieving from the full session record beats it whenever the next step depends on an exact error message, file path or number. Alexander Yue, founder of Mainplane, measured both on a real session of roughly 400,000 tokens on Claude Opus 5.5 and posted the results on X on 29 October 2026: compaction took 38 seconds and $1.99 with an expired cache and 29 seconds and $0.17 with a warm one, while a new session told to retrieve from the old session's file took 15 seconds and $0.10 "to get back to work". At Opus 5.5 list prices as of 11 November 2026, reading 400,000 tokens from cache costs $0.08 and processing them uncached costs $1.60 to $2.00, so the input cost of the same summary request swings by twenty to twenty-five times depending on one thing: whether the cache survived the pause.
A week later, NVIDIA researchers published evidence that points the other way on frequency. In You don't need long context (arXiv, 3 November 2026), agents running Claude Opus 4.5 and GPT 5.6 Sol compacted whenever their conversation passed as little as 12,000 tokens on the coding benchmarks, and in one regime threw the conversation away after every single action, with little or no loss of accuracy on SWE-bench Verified and Terminal-Bench. Both results are right, and they fit together once you see what the NVIDIA harness keeps outside the window: the task, verbatim, and a full environment the agent can read from. Aggressive compaction works when the state that matters lives somewhere other than the conversation. That is exactly why the raw record should never be thrown away, and why, once there are fifty session files, an agent also needs something that says which of its facts is current.
Compaction vs retrieval at a glance
| Compaction (summarise and restart) | Retrieval from the session record | Frequent compaction with state outside the window (NVIDIA setup) | |
|---|---|---|---|
| What happens when context fills | The model re-reads the whole session and writes a summary; a new context starts from the summary | A new context starts at once; the agent searches the old session and copies the lines it needs | The context never fills; the agent compacts at a low threshold or after each action, and re-reads files and inputs from its environment |
| Cost driver | Re-reading the full history: cheap from a warm cache, full price from a cold one | The tool calls the agent makes to search, plus whatever it pulls back | More uncached input and more output, less cached input; per-token savings only where price falls with context length |
| What survives | What the summariser chose to keep, in its own words | Everything, verbatim, if the agent thinks to look for it | The task verbatim, a plan, completion criteria and pointers to artifacts; history only as far as the state note records it |
| Typical failure | The exact error string, path or number is gone | The agent does not know a constraint exists, so never searches for it | Information that only ever existed in the conversation is lost by design |
| Best fit | A natural break between tasks, cache warm, discarded work genuinely finished | A cold cache, a resumed session, or work that depends on exact strings | Autonomous single-task runs where the repository or input files hold the ground truth |
| Across many sessions | Each summary stands alone; no record of what changed | Every line is findable; nothing says which line superseded which | Each run starts from the task alone; nothing carries over unless something outside the run keeps it |
What compaction actually does in Claude Code and the APIs
Compaction replaces the message history with a summary. In Claude Code, the summary comes from a separate request that "repeats your conversation's system prompt, tools, and the history being summarized" and ends with a summarisation instruction. Because that request shares the conversation's prefix, it reads the prompt cache when the cache is warm, and the documentation says a mid-session /compact then "costs a fraction of what the context size suggests and spends most of its time generating the summary". After a break longer than the cache lifetime, "the summarization request reprocesses that history as uncached input", and the docs name resuming an old session as the case where /compact costs the most.
Claude Code now also acts on the cold-cache problem by itself. Its idle compaction setting, on by default, compacts a conversation you have stepped away from when it is on the one-hour cache TTL, has reached a context threshold that defaults to 200,000 tokens, and has been idle for about an hour, so the summary is written while the cache can still be read; the terminal then shows a line beginning "Compacted while idle, before the prompt cache expired". Set idleCompaction to false to turn it off. It does not apply on the five-minute TTL that API-key sessions get by default.
What comes back after compaction is a reconstruction, not the old context. Claude Code's context window guide lists it: the system prompt, project-root CLAUDE.md, unscoped rules, auto memory and any plan written in plan mode are re-injected from disk; skill descriptions are rebuilt; up to five recently modified files that Claude read or edited are re-read, and a file over 5,000 tokens comes back only as a path reference; invoked skill bodies return capped at 5,000 tokens each and 25,000 in total; path-scoped rules and nested CLAUDE.md files, which entered the history when their trigger file was touched, are summarised away and reloaded on demand. SessionStart hooks that match the compact source run afterwards and add their output to the compacted context, which is the built-in way to put task state back after every compaction. Everything else in the conversation, every tool result and every error message, exists afterwards only as far as the summary mentions it.
The Claude API does the same on the server. On-demand compaction (beta header compact-2026-09-04) returns a summary block you send back in place of the messages it summarises; threshold compaction runs when input tokens reach a trigger you set, and "the API drops what came before the block", while the most recent turns stay word for word. OpenAI's Responses API offers server-side compaction through compact_threshold and a stateless /responses/compact endpoint, and its encrypted compaction item is, in OpenAI's words, "opaque and not intended to be human-interpretable". On OpenAI you cannot even read what was kept, which is the strongest argument there is for keeping your own copy of the record.
Summarising is not the only way to shrink a context, and the difference decides what you can get back. Some harnesses prune instead: they delete or mask old tool output and leave a pointer, which is reversible as long as the original output is stored somewhere the agent can read. Summaries rewrite the history in the model's words and are lossy by construction. Latent methods such as Memorilla, covered below, compress the history into vectors the model reads but nobody else can, which makes them lossy and unreadable at once. NVIDIA's team tried both summarisation and message pruning before settling on its brief-style compaction, and every option on this list is safer when the raw record is kept beside it.
Compaction costs a fraction of the context when the cache is warm
The arithmetic below uses Claude Opus 5.5 list prices as of 11 November 2026, unchanged since 30 October: $4 per million input tokens, $5 for a five-minute cache write, $8 for a one-hour cache write, $0.20 for a cache read (Opus 5.5 and Sonnet 5.5 read at 0.05 times the input price, against 0.1 times on most other models) and $20 per million output tokens. Anthropic bills the full 1M-token window at standard pricing on these models, so a 400,000-token request pays the same rate per token as a 4,000-token one.
| The summary request reads 400,000 tokens of history as | Price per million | Input cost |
|---|---|---|
| Cache reads (cache still warm) | $0.20 | $0.08 |
| Uncached input, no cache write | $4.00 | $1.60 |
| Uncached input written to a five-minute cache | $5.00 | $2.00 |
| Uncached input written to a one-hour cache | $8.00 | $3.20 |
The summary's output tokens come on top at $20 per million; a 5,000-token summary, for example, adds $0.10. Yue's post does not break his figures down, but his warm $0.17 and cold $1.99 sit inside these brackets, and the $1.82 gap between them is close to the $1.52 to $1.92 difference between reading 400,000 tokens at $0.20 per million and paying $4 to $5 per million for them. On Sonnet 5.5, at $2 input and $0.10 cache read, the same 400,000 tokens cost $0.04 warm and $0.80 to $1.00 cold.
Whether the cache is warm depends on how long you paused and on which time-to-live (TTL) the session uses. Claude Code gives the main conversation a one-hour cache on a Claude subscription within plan usage and five minutes on an API key, usage credits or a cloud provider, and puts compaction requests in its "everything else" bucket, which defaults to five minutes. A pause of more than five minutes on an API key is enough to turn a $0.08 compaction into a $2.00 one. Our guide to prompt caching in coding agents works through the TTL choice and shows how Claude Code and OpenCode build their compaction requests on the parent's prefix so the summary reads the cache before the history is replaced.
When aggressive compaction works: NVIDIA's short-context agents
The strongest case for compaction published so far is an NVIDIA technical report by Peter Belcak and eleven co-authors. Their harness is mini-swe-agent, a minimal loop in which the model issues one Bash action at a time, and they compared three regimes: full-history accumulation, compaction whenever the conversation crosses a threshold, and single-action compaction, where each conversation receives the task and a compact "semantic state", takes exactly one action, updates the state and is discarded.
The single-action results are the surprising ones. On SWE-bench Verified, Claude Opus 4.5 resolved 70.0% of issues with full history and 70.2% when the context was reset after every action; on Terminal-Bench 2.1 it went from 47.2% to 51.8%. GPT 5.6 Sol lost a little, from 84.4% to 82.4% on SWE-bench Verified and from 87.6% to 84.3% on Terminal-Bench. Median peak context fell to 7,000 to 9,000 tokens, and the largest single context fell from 130,000 to 200,000 tokens down to 15,000 to 37,000. Threshold compaction told a similar story across six long-horizon benchmarks: at limits from 48,000 down to 8,000 tokens, no more than 5 of 22 configurations per model lost more than 2 percentage points against the full-history baseline.
What a good compaction contains matters more than how often it runs. The authors found that summaries which faithfully narrate the history are the wrong target; the compactions that kept accuracy were "carefully cherry-picked briefs for further execution", holding a verbatim or near-verbatim copy of the task, the agent's current activity and next steps, a decomposed plan, the criteria for calling the task done, and pointers to the artifacts that matter. Just as important is what the harness keeps outside the window. Every fresh conversation re-sends the original task, the repository and its files sit in the environment where the agent can re-read them, and for long-input tasks the inputs are stored as files the agent reads selectively with sed, awk and head. The paper says plainly that compaction is lossy and that any task needing an old detail can fail, and its answer is "a harness that keeps a record of every message of any agentic conversation, and makes it readily accessible to the agent by the means of a selective reading tool". That is Mainplane's design, arrived at from the other direction.
The cost claim needs its setup attached. The "up to 8.8x" savings in the paper's figures are an "estimated optimized retail cost": the authors measured how decode throughput on open-weight models (GLM 5.2, Kimi K2.6 and Qwen 3 Coder Next on H100s at $3.85 per GPU-hour) rises as the context window shrinks, found that serving at 16,000 rather than 256,000 tokens costs 3.6 to 7 times less per generated token, and applied that ratio to Opus and GPT prices as if a provider charged less for short contexts. The paper also reports nominal retail cost at the published prices, and there the picture is smaller and mixed. On SWE-bench Verified, Opus 4.5 cost $420.00 with full history and $295.75 at the best-scoring 24,000-token setting, about 1.4 times cheaper, while GPT 5.6 Sol cost $167.68 with full history and $184.16 to $203.12 with compaction, because compaction trades cheap cached input for uncached input and extra output. Anthropic's own price list today charges the same per token across the 1M window, so the 8.8x figure describes what short contexts cost to serve, not what an API customer pays.
Read together with Yue's numbers, the practical rule is consistent. Compaction is cheap when it reads from a warm cache, or when it keeps every request short enough that you never build a large cold prefix to begin with; it is expensive when it re-reads a large history from a cold cache. Frequent compaction is safe when the ground truth (the task, the code, the input files) can be re-read from outside the conversation, and risky when the only copy of a fact is a line in the transcript.
Latent memory: what Memorilla adds and what it does not
A different line of work skips text summaries altogether. Memorilla, from a Stanford group including Jure Leskovec (arXiv, version 3 dated 3 November 2026), encodes documents or an agent's past turns once into embeddings and trains a memory module that turns them into 16 query-dependent "memory tokens" placed in the input of a frozen LLM. The LLM itself is never trained; the memory module is, with about 194 million trainable parameters for the Qwen3-8B setup. The headline figures carry specific setups: the 27x speed-up is end-to-end latency with 512 documents on one H100 (0.74 seconds against 19.9 seconds for full-context generation), and the largest compression, 4,212x, is how many more document tokens full context gave the decoder than Memorilla's 16 tokens on NarrativeQA. In a TextWorld game, an agent with RL-trained memory raised its average success rate from 18.6% with full history to 24.2%.
The authors list the limits themselves: Memorilla "can lose fine-grained factual details", was tested only with Qwen encoders and decoders, and "may not carry over directly to domains such as coding". For coding agents, that places it beside compaction, not against it: a compressed view that is fast and good at the gist, alongside a record that still holds the exact line.
Where the summary loses, and why exact lines win
A summary keeps what the summariser judged important at the moment it wrote it. Yue's complaint is the precise one: "The exact error message, the file path, the one number you needed is often gone." Coding work is unusually exposed to this, because so much of what matters is a literal string, such as a stack trace, a flag that has to be passed, a migration name or the port a service actually bound to. The NVIDIA paper makes the same point with a constructed example, an agent that must recall the i-th of many coin tosses, which any fixed-size compaction will eventually fail.
Failure records are the other casualty. A summary tends to keep the goal and the progress and drop what was tried and did not work, so after compaction an agent can retry a write that already failed with a permission error, redo a step that already ran, or forget a constraint it learned halfway through the task. None of these show up as an obvious error; they show up as wasted turns and, occasionally, as a change applied twice.
Mainplane's answer is structural. Its Show HN post describes a Go agent harness in which each session is one append-only state file, and /continue starts a new session that greps the previous state file instead of summarising it. The README puts it as agents that "manage their own context by retrieving key information from other sessions", and the repository is MIT-licensed. Yue calls it "the bitter lesson applied to agent memory": give the model the full record and good tools, and let it decide what to bring back.
Where retrieval from the old session costs you
Retrieval moves the cost from one large summary request to many small tool calls, and the number of those calls is not fixed. A study posted to arXiv in August 2026, What Does Context Compression Cost an Agent? by Shuyu Liu, ran a tool-using agent in a deterministic planning environment with a 24-turn limit, across three models and two task regimes, and split tool calls into retrieval and execution. Compressing the agent's context raised retrieval calls in all six model-regime comparisons while task completion did not change significantly at 5x compression; for GPT-5.5, completion went from 80% to 85% while retrieval calls rose from 21.0 to 63.9. The effect was environment-dependent (ALFWorld showed no surge). NVIDIA checked for the same pathology in its own runs and reports that re-doing work "was generally not the case", though its appendix notes that uncached input generally rises, and output is generally higher, as the compaction threshold drops. An agent that has lost state goes back to fetch it, and completion rates alone will not tell you what that cost.
The harder limit is that retrieval only finds what the agent thinks to look for. A summary at least puts the shape of the previous work in front of the model; a fresh session with "retrieve key context as you go" has to know that a constraint exists before it can search for it. The worst case for retrieval is the negative fact, such as "do not touch the staging database, it is shared with another team", which nobody greps for because nothing in the new task mentions it. NVIDIA's state note handles this inside one run by carrying requirements forward explicitly; it does nothing for the next run.
Dex Horthy, who is building HumanLayer, replying on X to a separate post about answering from primary sources, stated the condition for keeping any summary at all: it is worth having only "if it increases speed without reducing quality", and unless you are building evals specific to your codebase, the "simpler answer is live with a little speed hit and just go from source every time". That is the right default for code, where the source is always available and always current, and it is the same bet the NVIDIA harness makes.
When to compact and when to continue and retrieve
Each approach wins at a different moment in a session, and the cost table and failure modes above decide which moment you are in.
- Compact when the cache is warm and the work is done. Run
/compactat a natural break between tasks, within the TTL, with a focus instruction such as/compact focus on the auth bug fix, and only when the context you are discarding is genuinely finished. Claude Code's own advice is the same: pick the moment yourself, before auto-compaction fires mid-task./autocompactwith a token count, such as/autocompact 500k, sets how full the window gets before the automatic pass runs. - Compact often when the ground truth is on disk. For autonomous runs where the repository, the task file and the inputs hold everything that matters, NVIDIA's results say frequent compaction costs little accuracy. Write the summary as a brief for what comes next (task, plan, done criteria, pointers to files), not as a history, and re-inject it with a SessionStart hook on the
compactsource. - Rewind when you are abandoning a path.
/rewindtruncates back to a prefix that is already cached, so it costs a cache read and no new summary. - Start fresh and retrieve when the cache is cold. After a long break or when resuming an old session, a compaction pays full price to re-read history you may not need; a new session that searches the old transcript pays only for what it pulls back. On a subscription with the one-hour TTL, idle compaction may already have summarised the session while the cache was warm.
- Retrieve when the next step depends on literal strings. Debugging, migrations and anything involving exact configuration values should come from the record, not the summary.
- Check the cache before you choose. Claude Code's
/usageshows whether the main conversation's cache is warm right now, which tells you which row of the cost table you are about to pay. - Keep the transcript either way. Claude Code already writes every session to JSONL at
~/.claude/projects/<project>/<session-id>.jsonland keeps it after compaction, but it deletes transcripts after 30 days by default; raisecleanupPeriodDaysif the record has to outlive that. On OpenAI, where the compaction item is opaque, log the raw turns yourself.
What neither does across fifty sessions
Compaction, retrieval and NVIDIA's single-action loop are all answers to one question: how does an agent keep working once this session's context is full? A different question appears after a month of sessions, and none of them answers it. NVIDIA's result sharpens it rather than settling it. If an agent can drop its conversation after every action and still finish the task, then everything durable it knows has to live outside the conversation, and the quality of that outside store decides what the agent knows next week.
Suppose the record holds fifty session files. Grep for the staging database URL and you may get several values, one from before a migration, one from a test, one that a teammate later changed. Every line is exact and none of them says which is current. Retrieval returns matches, not the order in which facts replaced each other; a compaction summary is worse here, because each summary stands alone with no link to the one before it; and a per-task semantic state is discarded when the task ends.
What the agent needs across sessions is a record of change: this value replaced that one on this date, for this reason, and the old one is still there if you need to know what it used to be. Vectorize made a similar point on 29 October in a Hindsight post on agent memory, arguing that when facts live in a memory store and not in the thread, "compaction costs you the turns and not the knowledge"; the same post cites an OpenBot tracker report that counted 177 memories across 17 agents, 15 of them contradicted and 31 stale. Keeping facts outside the thread is the easy half. Deciding which of two conflicting facts wins, and recording that decision, is the hard half.
Project files cover part of this today. Claude Code's CLAUDE.md and auto memory survive compaction because Claude Code re-injects them from disk, and our comparison of Claude Code, Codex and Cursor memory covers what each one keeps between sessions. A memory layer is the other option. Maximem Synap stores memories as discrete statements rather than transcript chunks, so it can notice when a new statement contradicts an old one, keep the old one linked to its replacement, and show where each memory came from, what it replaced and what it used to say. Whichever you use, the store needs regular maintenance, which is what our piece on agent memory consolidation covers: merging duplicates, superseding replaced facts and checking that the job did not break anything.
Keep the full record, retrieve exact lines within a session, and compact as often as you like once the task and its ground truth live outside the window. Then add the one thing a pile of perfect transcripts and short contexts cannot give you, a record of which fact replaced which, because the shorter each context gets, the more an agent on its fiftieth session depends on that record to know what is true.
Frequently asked questions
Is context compaction a mistake?
No, but it depends on what it re-reads and what it throws away. On a roughly 400,000-token Opus 5.5 session, Mainplane measured 29 seconds and $0.17 to compact with a warm cache against 38 seconds and $1.99 with a cold one, and 15 seconds and $0.10 for a new session that retrieved from the old record. NVIDIA's November 2026 paper found that agents on SWE-bench Verified and Terminal-Bench kept their accuracy even when compacting after every action, because the task and the repository stayed available outside the conversation. Compaction is a poor choice when the cache has expired on a large history or when the next step needs an exact string that only exists in the transcript.
Do coding agents need long context?
Not for the tasks NVIDIA tested. In its November 2026 paper (arXiv 2611.05306), Claude Opus 4.5 resolved 70.0% of SWE-bench Verified issues with full history and 70.2% when the context was reset after every action, with median peak context of 7,000 to 9,000 tokens; GPT 5.6 Sol dropped from 84.4% to 82.4%. The harness re-sent the task in every conversation and kept the repository in the environment, so the agent never relied on the conversation as its only copy of the facts.
Does frequent compaction save money on API prices?
Less than the headline suggests. NVIDIA's "up to 8.8x" is an estimated cost that assumes a provider charges less for short contexts, based on GPU throughput measurements of open-weight models. At published retail prices, the same paper reports Opus 4.5 on SWE-bench Verified falling from $420.00 to $295.75 at the best setting, while GPT 5.6 Sol rose from $167.68 to between $184.16 and $203.12. Anthropic charges the same per-token rate across the full 1M window on Opus 5.5 and Sonnet 5.5 as of 11 November 2026.
What does /compact cost in Claude Code?
The summary request re-sends the whole conversation. With a warm cache, Claude Code's docs say it "costs a fraction of what the context size suggests"; at Opus 5.5 prices as of 11 November 2026, 400,000 tokens read from cache cost $0.08. With a cold cache it reprocesses the history as uncached input, $1.60 at the $4 input price or $2.00 if written to a five-minute cache. Output for the summary adds $20 per million tokens. On the one-hour TTL, idle compaction can run the summary before the cache expires.
Does Claude Code delete the conversation when it compacts?
No. Claude Code stores each session as a JSONL transcript under ~/.claude/projects/ and keeps writing to it as you work. Compaction changes what the model sees; when you resume a compacted session, Claude continues from the last compaction's summary and the messages after it, and the messages the summary covered are not loaded again. Transcripts are deleted after 30 days by default, which cleanupPeriodDays changes.
Is retrieval from the old session always cheaper than compaction?
No. Retrieval is cheaper when it replaces a cold compaction, but its cost scales with how many searches the agent makes, and a study on context compression found retrieval calls rose sharply (21.0 to 63.9 for GPT-5.5 in one setting) once state was lost. It can also miss constraints the agent does not know to look for. With a warm cache, compaction and retrieval cost about the same, and the decision comes down to whether you need exact lines.
Can you read what OpenAI's compaction kept?
No. OpenAI's documentation describes the encrypted compaction item as "opaque and not intended to be human-interpretable". It carries prior state forward in fewer tokens, but you cannot inspect or correct it, so keep your own log of the raw turns if you need an audit trail or exact retrieval later.
What is the difference between compaction, retrieval and memory?
Compaction shrinks one session by summarising it. Retrieval keeps the session record intact and pulls exact lines back when they are needed. Memory works across sessions: it keeps facts after the session ends and records when one fact replaces another, which neither compaction nor single-session retrieval does.
Sources
Retrieved 11 November 2026 unless marked.
- Peter Belcak, Saurav Muralidharan and others (NVIDIA), You don't need long context, arXiv 2611.05306, 3 November 2026 (Table 2, Table 3, Appendix A and Appendix B), found through an alphaXiv post on X.
- Adibvafa Fallahpour, Parsa Idehpour, Vignesh Kothapalli and others (Stanford), Memorilla: Latent Semantic Memory for LLMs, arXiv 2610.21375 v3, 3 November 2026, announced in a post on X.
- Anthropic, Claude pricing, Claude API compaction.
- Claude Code docs: prompt caching, context window, settings reference, sessions.
- OpenAI, compaction guide.
- Alexander Yue, post on X, 29 October 2026 (retrieved 30 October 2026).
- Mainplane, GitHub repository and README (MIT licence) and Show HN post (retrieved 30 October 2026).
- Dex Horthy, post on X, 30 October 2026 (retrieved 30 October 2026).
- Shuyu Liu, What Does Context Compression Cost an Agent?, arXiv 2608.16370, August 2026 (retrieved 30 October 2026).
- Vectorize, Your OpenBot Agents Forget Between Threads, 29 October 2026 (retrieved 30 October 2026).



