Skip to navigation

Claude Code Compaction: What Survives the Save

In short: Claude Code compaction summarizes a session before continuing. Test which facts, decisions and constraints survive that lossy save.

Published 17 min read
On this page

Direct answer

Treat compaction as a lossy save. The useful question is not whether a summary exists. The useful question is which facts, decisions and constraints survive into the resumed session, and whether the agent can still complete the task without a human reconstructing the missing pieces.

Unknown. The frozen evidence does not document Claude Code’s exact compaction trigger, summary format or retention rate. That means a responsible test should model the event as full session, summary, resumed session and score the result. It should not invent a failure percentage or claim that every compaction loses critical data.

Keep a written task brief outside the transcript. Before compaction, record the goal, constraints, decisions and acceptance criteria. After compaction, ask the agent to restate and apply them. If an item disappears, restore it and treat the summary as incomplete.

Why a save can still lose something

A summary is useful because it reduces the amount of material carried forward. That same reduction creates risk. A summary can preserve the general shape of a task while dropping an exact value, a rejected approach or a constraint that only mattered once.

This is not unique to coding agents. Any handoff can lose detail when one person summarizes a long discussion for another. The difference is that an agent may continue with confidence after the handoff. A plausible summary can hide the fact that a requirement is gone.

The context window versus memory discussion separates capacity, retained reasoning and task state. Compaction belongs mainly to the task-state handoff. It can change what the resumed session receives even when the original transcript remains available somewhere.

The historical cache bug is a separate event. Official. Anthropic’s postmortem says older reasoning was cleared after an idle condition in March 2026. That incident should not be used as proof that compaction drops specific items. It is a reminder that different mechanisms can affect what survives a session.

A developer feels compaction as a change in continuity. The agent may repeat a question, forget a decision or produce a result that violates an earlier constraint. The response should be a test, not a blanket claim that the feature is broken.

Model the event before measuring it

For this article, the test model has three stages: a full session, a summary and a resumed session. The full session contains the original instructions, tool output and decisions. The summary is the material carried forward. The resumed session must complete the task using that summary and any external artifacts.

Stage Input Output What to record
Full session Task, code, tools and conversation Decisions, changes and evidence Exact facts and constraints placed in the session
Summary Selected session material Compact handoff What the summary includes and omits
Resumed session Summary plus current workspace Continued work and final result Which items are recalled and applied

This model does not assert a hidden implementation. It gives the team a fair way to compare retention before and after a save. If the client exposes a summary, inspect it. If it does not, score the resumed behavior and mark the internal format as unknown.

The verification proof packet is useful at the final stage. A resumed session should produce changed files, test output and external-state checks. A fluent continuation is not evidence that the task remained intact.

Compaction modeled as a full session becoming a summary and then a resumed session
Editorial test model. The frozen evidence does not specify the exact summary format or trigger, so the diagram shows the evaluation boundary.

What can be lost

The most damaging loss is often not a broad topic. It is a small exact detail: a function name, a forbidden file, a test command, a deadline or a decision not to use a library. A summary can preserve “we discussed the API” while dropping “the API key must stay in the environment.”

Decision rationale is another risk. The resumed agent may remember the chosen approach but forget why alternatives were rejected. Without the rationale, it may reintroduce a rejected pattern or spend time revisiting a settled question.

Tool state can also be lost. A command may have run, a file may have changed and a test may have failed for an environmental reason. If the summary does not carry that state forward, the agent may repeat work or misinterpret the current workspace.

Item Why it matters Loss signal
Exact constraint Prevents a specific unsafe or incorrect action Resumed session violates the rule
Decision rationale Avoids reopening rejected approaches Agent proposes a previously rejected design
Tool result Prevents duplicate or contradictory work Test is rerun without using prior evidence
File state Shows what has already changed Agent edits the wrong version or repeats a patch
Acceptance criterion Defines done Session stops before the real requirement is met

The false-success verification pattern explains why a confident continuation can be misleading. The agent may report that the task is complete while a constraint was lost during the handoff. Inspect the diff and run the acceptance checks.

The agent harness security boundaries add another reason to preserve constraints. A forgotten rule about credentials, network access or production commands can turn a continuity problem into a security problem.

Potential compaction losses including exact constraints, decision rationale and tool state
Editorial risk map. These are test categories, not a measured list of items that every compaction loses.

Run a constraint-retention test

A constraint-retention test uses a synthetic task with known items. The goal is to see what survives the save and whether the resumed session applies it correctly.

Start with a small repository and a task brief. Include one fact, one decision and one constraint. For example, the project uses a fictional helper name, a particular dependency was rejected, and a test must not contact the network. Keep the items easy to score.

Run enough work to create a realistic session, then trigger compaction using the client’s documented control if one is available. If the trigger is not documented in the frozen record, mark that part unknown and use the client’s observed behavior without inventing a rule.

After compaction, ask the agent to restate the three items. Then give it a small change that requires each one. Score recall and application separately. An agent can repeat a constraint and still violate it in the diff.

Score Recall Application Evidence
2 Exact item is restated Change follows the item Diff and test output agree
1 Item is partly restated Change needs a prompt to comply Human correction is recorded
0 Item is missing or wrong Change violates the item Failure is reproduced

Do not turn this small score into a universal benchmark. Report the client version, model, task fixture and conditions. The model selection guide for coding agents can help choose a model, but the retention test should hold the model constant when comparing compaction behavior.

Constraint-retention scorecard scoring facts, decisions and constraints before and after compaction
Editorial scorecard. It measures specific items under stated conditions and does not claim a population-wide failure rate.

Keep a before-and-after record

A before-and-after scorecard makes the loss visible. Record the exact item before compaction, whether it appears in the summary if available, whether the resumed agent recalls it and whether the final change complies.

The record should also include human effort. If a reviewer has to restate the constraint, that is part of the cost. If the agent repeats an investigation because tool state was lost, record the extra work. The cost per verified change framework provides a place to combine that effort with subscription or API spend.

Use the same fixture across clients or versions. Otherwise, a difference in task difficulty can look like a retention difference. Keep the model and prompt stable when the goal is to test the save itself.

The April 2026 regression postmortem is a useful example of disciplined comparison. It separates three mechanisms instead of treating every symptom as one bug. Apply the same discipline here: distinguish a missing summary item from a model mistake or a workspace problem.

A simple scorecard can live beside the task brief:

Item: exact constraint
Before: present in full session
Summary: present, partial or absent
Recall after save: exact, partial or missing
Application: compliant, corrected or violated
Human effort: minutes or prompts needed
Evidence: diff, test output and notes

This record is more useful than a general statement that compaction “felt fine.” It shows what survived and what the team had to repair.

Decide when to compact deliberately

Compaction is a trade between continuity and a manageable session. The right moment depends on the task, the client and the amount of state that must survive. A deliberate policy is safer than waiting for an automatic event and hoping the summary is complete.

Policy Use when Required preparation
Compact at a natural boundary A phase of work is complete Update task brief and evidence first
Compact before a large context shift Old material is mostly noise Preserve decisions and open questions
Restart with fresh context Session is contradictory or bloated Provide a concise brief and current workspace
Delay compaction Exact tool state is still active Checkpoint commands, outputs and next step

The five-hour and weekly limits can interrupt work before a natural boundary. A checkpoint reduces the damage because the next session can start from a written state rather than a vague memory.

The agent-team token overhead is relevant when several agents share a task. Each agent can carry a different summary. A common task file gives the team one source of truth and makes divergence easier to spot.

The migration context-portability guide belongs in the same policy. If the team changes clients, the task brief and scorecard should move with the workflow. A summary that only makes sense inside one interface is not a portable handoff.

Compaction policy choices to compact early, persist state or restart with clean context
Editorial policy options. The best choice depends on the task and the client’s documented behavior.

What a good continuation looks like

A good continuation does more than produce text. It picks up the task with the right constraints, uses the current workspace and carries forward the evidence needed to finish.

Look for three signals. First, the agent can restate the goal without introducing a new requirement. Second, it preserves the decisions and constraints in the actual change. Third, it can point to the tests or checks that show the result is complete.

A bad continuation may sound competent while repeating settled work or violating a forgotten rule. The proof-of-work packet helps catch that gap. Ask for the changed files, the test output and one independently verified result.

The single points of failure analysis treats model behavior and account access as separate failure domains. Compaction is a continuity risk within the workflow. A fallback plan should preserve the task brief so a new session can recover without reconstructing the entire transcript.

The honest loss

Compaction is useful when it keeps a long session manageable. A summary can remove noise and give the agent a clearer starting point. Removing it entirely would make some workflows harder to continue.

The loss is that the summary is not the original record. Exact details can disappear, and the resumed agent may not know that anything is missing. The honest response is not to claim that every compaction fails. It is to test the items that matter and keep critical state outside the summary.

The evidence gap is significant. The frozen fact pack does not provide a compaction failure rate, an exact trigger or a guaranteed list of preserved fields. Future updates should revisit official documentation and publish a repeatable scorecard with client versions and task fixtures.

The Claude Code data usage documentation and commercial retention policy describe provider-side handling. They do not answer what survives a session summary. Keep those questions separate.

Audit the handoff like a diff

A summary is easier to review when you compare it with a known source. Leave the task brief unchanged before the save, then inspect what the resumed session believes. The goal is to find missing or altered items, not to judge whether the summary sounds polished.

Start with exact strings. Check function names, file paths, environment variable names and forbidden commands. A summary that generalizes a name can send the agent to the wrong place. A summary that drops “do not” can reverse a constraint without changing the rest of the sentence.

Next, check decisions. The chosen approach may survive while the reason disappears. If the team rejected a dependency because it lacks a required license, that rationale belongs in the task brief. The resumed agent should not have to rediscover it from the repository.

Then check state. Which files changed? Which tests ran? Which command failed because of the environment? A summary that says “tests were run” is weaker than one that records the command and result. The proof-of-work packet is a good model for preserving that evidence.

Do not assume the client exposes every field. If the summary is not visible, score the resumed behavior and mark the internal format as unknown. If it is visible, compare it with the brief but do not treat the summary as the authoritative record. The brief remains the source of truth.

Route details deserve the same care. The coding-agent API key compatibility guide explains why client and endpoint compatibility matter. The OpenAI versus Anthropic API format guide shows that a migration can change more than the model. Preserve the route and credential rules in the task brief when they affect the work.

The API reference documents per-key caps, expiry dates and model allowlists. Those controls do not summarize themselves. If a task depends on a key expiry or an allowed-model list, write the constraint down before the save.

Use a reusable compaction worksheet

A worksheet makes the test repeatable and keeps the team from scoring a vague impression. It can be a short section in the task file or a separate test record. The important part is that another person can run the same fixture and understand the result.

Begin with the environment. Record the client version, model, task fixture and the method used to trigger compaction. If the trigger is automatic, record the observed conditions without claiming an undocumented threshold. If the trigger is manual, record the point in the task when it was used.

List the test items before the run. Use a small set: one exact fact, one decision with rationale, one constraint and one acceptance check. Add a tool-state item if the task involves a command whose result must carry forward. Use synthetic items so a failure cannot expose real data.

After the save, score recall and application separately. Recall asks whether the agent can restate the item. Application asks whether the final change follows it. Record any prompt needed to repair the gap. That prompt is part of the human cost.

Worksheet field What to enter
Environment Client version, model and route
Trigger Manual control or observed automatic conditions
Test items Exact fact, decision, constraint and acceptance check
Summary visibility Visible, partial or unavailable
Recall score Exact, partial or missing for each item
Application score Compliant, corrected or violated
Human effort Restatement, investigation or repair needed
Evidence Diff, test output and notes

End with a decision. If a critical item is lost, update the task brief and change when compaction happens. If the summary preserves the item but the agent misapplies it, investigate the model or prompt rather than the save alone. If both recall and application pass, record the conditions and move on.

The exit-plan checklist should include this worksheet. A fallback agent needs the same task state, not just the same API key. The migration inventory helps ensure the brief and evidence move with the workflow.

Verdict that compaction is useful but lossy by design and survival should be verified
Editorial verdict from the test model. Compaction can be useful, but critical state should be persisted and its survival verified.

When a constraint disappears

A lost constraint is a signal to stop and repair the handoff. Do not let the resumed session continue on the assumption that the summary was complete. Restore the missing item, explain where it came from and ask the agent to apply it to the current work.

Then inspect the damage. Did the agent already change a file, run a command or contact a service? If the constraint concerned credentials or network access, treat the event as a security issue and review the relevant logs. The agent harness security boundaries provide the trust model for that review.

Update the task brief so the constraint is easier to preserve next time. Place it near the acceptance criteria rather than burying it in a long transcript. If the same item is lost repeatedly, change the compaction policy or start a fresh session with a shorter brief.

Record the repair in the scorecard. Note what was missing, how it was detected and what evidence confirmed the final result. This turns a failure into a workflow improvement instead of an informal complaint.

The goal is not to make the summary perfect. The goal is to make critical state visible, recoverable and verifiable. A team that can detect a missing constraint quickly can use compaction without treating every save as a leap of faith.

Ask five questions after a save

A short review after compaction can catch a bad handoff before the agent does more work. Ask what the goal is, which constraints apply, which decisions are settled, what has already changed and what evidence remains. The answers should match the task brief.

If the agent gives a vague answer, ask for the exact item. “We discussed the API” is not enough when the task depends on a specific endpoint or credential rule. If the answer conflicts with the brief, stop and resolve the conflict before continuing.

Then ask the agent to name the next action and the check that will prove it worked. This tests whether the resumed session has a plan, not just a summary of the past. A continuation that cannot state the next verification step is not ready to run.

Finally, inspect the workspace. The agent’s description of changed files should match the actual diff. If it claims a test passed, ask for the command and output. The proof-of-work packet keeps those answers together.

These questions take little time and make the save visible. They also give the team a habit that transfers to a new client or model: confirm the state before trusting the continuation.

If an answer is missing, do not fill the gap with an assumption. Return to the task brief, the diff or the test output. When the source of truth is unclear, pause the task and resolve it before the agent makes another change. A short pause is cheaper than repairing a confident mistake.

Make the review part of the handoff rather than an optional extra. The person who accepts the resumed work should confirm that the critical items survived. That check also creates a clear point for recording a failure and improving the next save. Store the confirmation with the task evidence so a later reviewer can see what was checked.

Practical response: test a portable route

If you want to compare continuation quality across agents, use the same task brief and scorecard on each one. One AI API Key lists 46 live free model IDs for OpenAI-format agents. The quickstart shows the /v1 endpoint, and the prepaid pricing page explains billing.

Those free IDs do not work inside Claude Code. Claude Code’s Anthropic-format route is documented, but all four Claude IDs were unavailable on 2026-11-27, so it is not an active fallback. Use an OpenAI-format agent for the free lane and preserve the task brief across the comparison.

The current model catalogue shows availability, while the live status page provides operational context. The monthly API cost worksheet and cost calculator can track spend, but neither measures retention. Score the known items directly.

Use a disposable key with an expiry and a narrow model allowlist from the API reference. Read the privacy and retention policy, then create the evaluation account through the sign-up route. Run the same task brief and scorecard with synthetic data on each client.

Leave the fixture and the known items unchanged. After the save, record recall, application and human repair effort. Save the diff and test output with the scorecard, then revoke the test key when the comparison is complete.

FAQ

Does every compaction lose critical data?

No. The available evidence does not establish a failure rate. Test the specific facts, decisions and constraints that matter for your task.

What should be saved before compaction?

Save the goal, constraints, decisions, progress and acceptance criteria in a short task file. Add the current diff, test output and next action when the work is in progress.

How do you score retention?

Score recall and application separately for each known item. An agent can restate a constraint and still violate it in the final change.

Is compaction the same as the April 2026 cache bug?

No. The cache bug cleared older reasoning after an idle condition. Compaction is a summary handoff. Both can affect continuity, but they are different mechanisms.

Sources

More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
  • 100requests
    per day
  • 3Mtokens
    per day
  • 47free
    models
  • $0per
    token
  • No card
  • No end date
Claim $10 credit →