hotai.news
← Back to AI WikiAI Wiki / Core concepts

What is context compaction? Shortening history while preserving task state

Understand compaction through a long coding conversation, distinguishing summaries, deletion, and caching, with checks for constraints, provenance, and provider-specific forms.

HotAI.news · Sources checked with CodexPublished on 2026-10-20Sources checked on 2026-10-20
Our take

Understand the concept

Context compaction converts history into a shorter representation to continue a task within capacity. Summarization is common, but services can return opaque compacted states. It changes the information available later and does not preserve every original word. It differs from prompt caching and is not permanent storage of all details.

01

Preserve constraints that still govern the task

A long coding conversation may still need the target branch and prohibited paths. A summary saying only that several issues were fixed can lose these constraints. Preserve the goal, outstanding work, and which version passed each check.

This is a state-design example, not a compaction experiment. Paths and document sections enable recovery of detail. Do not promote earlier guesses into confirmed facts or equate a summary saying complete with verified artifacts.

02

Handle provider-specific compaction outputs correctly

OpenAI can return a context window containing an encrypted compaction item and instructs callers to reuse that window without pruning. Anthropic exposes several modes and summary configurations. Neither should be reduced to deleting all earlier messages and retaining the latest request.

Recent content may remain verbatim depending on mode. Inspect returned objects and roles, avoid treating internal state as new user instructions, and do not translate or rewrite opaque items. Recheck compatibility after version changes.

03

Shorter context and cache reuse solve different problems

Compaction reduces carried information, while caching reuses computation for unchanged input. Rewriting history can reduce cache hits, so compare actual latency and usage as well as token counts. Test earlier constraints for behavioral regressions.

Recover important dates or parameters from originals instead of asking the model to guess from a lossy summary. Long tasks also need external evidence storage. This explanation does not promise lossless summaries or a universal compression ratio.

Checked sources

These sources support the concepts and methods described here. Examples and test scope are labeled separately; check the version of the tools you use.

Back to AI Wiki ↗