Skip to content

Guide6 min read

Context compaction: why your agent re-proposes what you already rejected

In a long session, Claude Code, Codex and Cursor swap the conversation for a summary. The summary keeps the request and the code, and the reason behind your "no" can fall out. What each harness documents, a 15-minute test and where to keep what has to outlast the summary.

ValorBrain Team
Two dark panels split by a dashed vertical line. The left one has three lines, the last highlighted with a green mark. The right one has the first two lines and, where the third should be, only an empty outline with a red mark.

Three hours into the session, the agent proposes running the migration through the ORM. You turned that down in the first twenty minutes, with a reason: it locks the table for minutes. No error showed up and nothing broke. Somewhere along the way the conversation was compacted. The summary kept the request and the code, and your "no" didn't make it.

This isn't one product's bug. Every coding harness makes this trade, and the three most used ones say in their own docs that the summary loses things.

What the vendors say

When the context window fills up, the harness replaces the conversation so far with a summary and keeps going. In their words, read on November 28, 2026:

  • Claude Code: "The summary keeps your requests and key code snippets, but detailed instructions from early in the conversation may be lost."
  • Cursor: "the agent's knowledge can degrade after summarization since it's a lossy compression of the context."
  • Codex: /compact "replaces earlier turns with a concise summary, freeing context while keeping critical details". The page doesn't say what counts as critical.

It doesn't only happen when you ask. All three compact on their own near the limit. Claude Code also compacts conversations that sit idle: idle compaction is on by default in interactive sessions and summarizes a conversation past 200,000 tokens that has gone about an hour without a prompt, among other conditions. When you come back from lunch, the clue is a line in the terminal starting with Compacted while idle.

Four things that only live in the conversation

Your files are on disk. In Claude Code, the project-root CLAUDE.md and auto memory are reloaded from disk after compaction, and up to five recently read or edited files are re-read. What's at risk is whatever was only said in chat. The guide sorts it into four kinds:

Card titled "Three hours in, the agent brings back the approach you turned down early on." On the left, first 20 minutes, what was said in the chat: the request, the code and you saying "Not the ORM migration, it locks the table for minutes.", rejected with the reason and only said in the chat. In the middle, a dashed line: compaction on the way. On the right, three hours in, what the summary kept: the request, kept; the code, kept; your "no" and the reason, struck through, left out. And the agent proposes, in red, the ORM migration, with no error printed. In the dark strip: write it outside the session, rejected options, verified results, open questions and values said in passing.
Example from the guide, not a real log.

  • Rejected options, with the reason. A discarded option left no code behind, so the summary has little to hold on to.
  • Verified results, with how they were verified. "The three failures in payments were there before our change, checked on main." Without the second half, the next turn either trusts too much or checks everything again.
  • Open questions. A summary is prose that reads like the matter is settled, and a doubt nobody repeats turns into an assumption.
  • Values mentioned in passing. A rate limit, a date, a folder nobody is allowed to touch.

That list is a classification, not a measurement. Only the test tells you what your harness actually keeps.

A 15-minute test

You don't need to fill the window. Claude Code's docs say auto-compaction works the same way as /compact.

  1. Start a fresh session in a scratch repo and give the agent a small, real task, like a function and its test.
  2. In the first few turns, plant five facts in ordinary sentences: a rejected approach with its reason, a number ("this API takes 40 requests per minute"), an instruction ("never edit anything under legacy/"), a result the agent verified itself and an open question.
  3. Do three or four turns of work, so the facts aren't the last thing said.
  4. Compact: /compact in Claude Code or Codex, a manual summary in Cursor.
  5. Ask about each fact. For the rejected approach, don't ask "what did we reject?". Ask for a proposal for the same problem and see whether it comes back.
  6. Grade each one: kept exactly, kept vaguely, lost or contradicted.

In Claude Code you can read the summary instead of guessing: a PostCompact hook gets the text in the compact_summary field.

Where to keep what has to survive

Rules, in the instructions file. The root CLAUDE.md comes back from disk after compaction, so permanent rules live there, not in chat. A "Compact Instructions" section in the same file steers the summary: keep every rejected approach with its reason, every number the user gave, every open question and the next step. That covers rules. State that changes every twenty minutes doesn't belong in a file the whole repo shares.

The reload, in a post-compaction hook. Claude Code and Codex run session-start hooks again, with the compact source. In Cursor, preCompact only observes, and there's no documented hook after the summary. One Claude Code detail: context a hook injected at the start of the session gets summarized with everything else. The conventions it loaded become whatever the summary made of them, unless the hook runs again. And a hook can only print what's already written down somewhere.

State, in a checkpoint outside the session. This is what covers all four kinds, and it has to be written during the work, because nothing tells the agent the next turn will start from a summary. A useful checkpoint has the result and what verified it, each open question with the test that settles it, the rejected options with their reasons and one next action. A file in the repo works for one person on one machine. When another agent, another harness or a teammate takes over, the checkpoint has to live somewhere they all read.

The step by step, the table of what each harness reloads and the hook examples are in the guide: What survives context compaction in a long agent session.

What ValorBrain does and doesn't do

In ValorBrain, that checkpoint is task_state, a per-task ledger on the server that the agent writes over MCP while it works. The server rejects a checkpoint that doesn't say what verified it, and an open question without what would settle it. To read it back, memory_prepare returns the task state along with the rest of the context, in any harness connected to the server, compacted or not. Decisions that matter beyond the task, like "we rejected the ORM migration because it locks the table", go into team memory as a decision, where the next session and the next teammate find them.

@valorbrain/connect 0.13.0 installs two hooks that matter here. The session-start hook runs with an empty matcher in Claude Code and Codex, so it also runs after a compaction, and the server's response includes the open task ledger. The stop hook asks the agent for a short checkpoint every few turns: after at least 3 turns, or 2 turns adding up to 8 minutes, at least 10 minutes apart and at most 6 times per session.

What it doesn't do, today:

  • It doesn't prevent or rewrite compaction. The summary belongs to the harness, and connect installs no pre-compaction hook. What exists afterwards is what was written before.
  • It doesn't write the checkpoint for the agent. The stop hook makes a request to the model, and if the model writes nothing, nothing is saved.
  • It doesn't restore the conversation. The ledger keeps results, questions and a next step, not the exact sentence from turn 12.
  • In Cursor, connect only has the session-start and stop hooks. After a summary, the reload depends on your rules file telling the agent to call memory_prepare.
  • We didn't run a real compaction to write this. On the server side, the response to a session start with the compact source carries the task ledger, and a search that takes longer than 3 seconds comes back with no context. Whether your harness puts that response in front of the model after the summary is what the 15-minute test checks in your setup.

ValorBrain works over MCP, in Claude Code, Codex, Cursor and any compatible client. The free plan doesn't ask for a card: valorbrain.com.br.

Sources, read on November 28, 2026: Claude Code, How Claude Code works, Explore the context window, settings reference, idleCompaction and Hooks reference; Codex, commands and hooks; Cursor, Hooks and Dynamic context discovery. The connect hooks and server responses are described in the guide, based on the @valorbrain/connect 0.13.0 package and the server code.

Next step

Less starting over. More continuity

Bring a real project. In one conversation we map where context gets lost between the people and agents on your team, and where to start.

Start with a project