How AI Remembers: Context and Compacting

llmsengineeringResearched October 2026

Every AI conversation runs on a working memory called the context window: one shared token budget for the prompt, the whole history, and the answer being written. It fills up as you talk, it costs real money per token, and when it overflows the oldest turns collapse into a summary. The sentence to remember: an AI's memory is a desk, not a hard drive, and whoever controls what stays on the desk controls what the AI knows.

Split illustration of the two AI memories. Left: a vast frozen library of bookshelves with a padlock, the trained weights. Right: a small wooden desk with an open notebook, note cards, and a filling gauge, the live context window.
Two memories: the weights are the frozen library, the context window is the one live desk.

1. The brief

AI looks like it remembers everything. It does not. A model has two kinds of memory. The first is baked into its weights during training: facts, patterns, vibes, frozen at the cutoff date. The second is the context window: the live working memory of this conversation, and the only place new information can go. That window is limited, it is shared by everything including the answer being written, and the infrastructure underneath charges rent by the token.

The last two years turned this from trivia into the central engineering problem of agents. Windows grew to a million tokens. Summarization got automated into an API primitive called compaction. And everyone building long-running agents learned the hard rule: anything that matters goes in a file, because everything else is one summary away from being gone.

2. How it works

Six mechanisms, from the token budget to the summary swap. Tap each card for the plain-language version, one concrete example, and what changed recently. Then fill the bucket yourself.

Compaction in motion: when the bucket fills, the oldest turns collapse into one summary and the session keeps going.

Fill the bucket

A 200,000-token window, one long session. Every tap adds one chunk. When a chunk would overflow the bucket, the oldest turns collapse into a summary and the session continues. One tap, one chunk.

200,000-token window
8,000 / 200,000 tokens used

The session opens with the system prompt and tool definitions already on the desk: 8,000 tokens.

Illustrative, not a real session. Real token counts vary by model and tokenizer, but the shape is right: tool outputs and pasted documents are what fill the bucket fastest, and thinking counts against it too.

What survives the summary, what gets fuzzy

Compaction does not treat all context equally. What survives depends on how it was loaded, not how important it was. Flip the switch.

  • System prompt and output style. Never part of the message history, untouched by every compaction.
  • Files on disk. The project-root CLAUDE.md and auto-memory files are re-injected from disk at session start, summary-proof.
  • Saved memories. ChatGPT stores them separately from chat history and considers them in every future response, even after the chat is deleted.
  • Recent turns. On-demand compaction keeps the last few turns word for word and only summarizes the older ones.
  • Invoked skills. Their bodies are re-injected, capped at 5,000 tokens each and 25,000 total, oldest dropped first.
  • Your summary prompt. You can write your own summarization prompt for when the default drops something a later turn needs.

Survival rules for Claude Code sessions, documented from Anthropic's own docs. The pattern generalizes: disk beats conversation, explicit beats implied, recent beats old.

3. The landmarks

Six moments that built AI memory as we know it, 2017 to 2026. One tap per step, or use the arrow keys.

4. Key voices

Five people and teams who built the machinery or documented it honestly. The real action is at the bottom, where two camps collide.

Diagram of the two camps. Left in red, the parametric camp: a neural network with key-value storage drawers built into its layers. Right in gray, the retrieval camp: a file shelf of documents with an arrow looping into a reading window, a lightning bolt of disagreement between them.
The camps, side by side: memory inside the weights vs files the model re-reads.

The real disagreement

Where should knowledge live: in the weights, or in files the model re-reads? Both camps ship products. Neither has won.

The parametric camp Meta FAIR
put it in the weights

Knowledge belongs in trainable memory layers: dedicated, cheap key-value storage inside the model itself. Files and prompts are a workaround. The architecture should remember, and their paper closes by advocating memory layers in all next-generation architectures.

The explicit camp OpenAI, Anthropic
put it in artifacts

Knowledge belongs in things the model re-reads: saved memories, memory files, CLAUDE.md on disk. Explicit, editable, inspectable, and it survives every compaction because it is re-injected, never summarized. Weights are where knowledge goes to become unverifiable.

The honest 2026 answer is that the best systems use both: memory layers for facts the model always needs, files and saved memories for everything personal, load-bearing, or likely to change.

5. Where leaders think this goes

Where the people building AI memory think this goes: their visions for the next 5-10 years, shown as named camps so you can see who is on which side. These are their views, not conclusions, and predictions go stale; this section is frozen as of October 2026.

Where they agree

OpenAI and Anthropic both point to memory that outlives the window
OpenAI's vision is that every assistant ships explicit saved items plus synthesized recall across past chats, the way ChatGPT has since the April 2025 expansion. The window stays the working memory; the profile becomes the long memory. Anthropic's docs already call compaction "the primary strategy" for long-running conversations; with both flavors in beta as of October 2026, their vision is that every long-running agent gets automatic summarization with recent turns preserved word for word. Raw conversation history stops being the default unit of context; the summary block becomes it.
OpenAI's direction since Apr 2025; OpenAI help center, 2026. Anthropic platform docs, Oct 2026.
Kwon et al. and the vLLM serving stack both point to a shrinking KV tax
The serving stack's direction: fewer KV heads (grouped-query and multi-head latent attention), lower precision, prefix reuse, and sliding windows keep cutting the memory cost of long context. The tax never hits zero, but the serving stack keeps refinancing it.
vLLM KV-cache explainer, 2026; PagedAttention, Kwon et al., SOSP 2023.

Where they split

Where knowledge should live: weights or artifacts
Side A: the parametric camp
Berges et al., Meta FAIR
Trainable key-value memory becomes a standard component, not an experiment: dedicated cheap storage for facts inside the weights, complementing dense layers rather than replacing them.
"Memory Layers at Scale," Dec 2024 (revised Aug 2026).
Side B: the explicit camp
OpenAI and Anthropic
Knowledge belongs in things the model re-reads: saved memories, memory files, re-injected at session start, never summarized. Weights are where knowledge goes to become unverifiable.
OpenAI help center, 2026; Anthropic platform docs, Oct 2026.
Do big windows kill compaction?
Side A: the bigger-window camp
Window enough, summaries become unnecessary
A large enough window makes summarization unnecessary.
Framed as the open fight in Anthropic's platform docs, Oct 2026.
Side B: the compaction-first camp
Context rot wins, summaries stay essential
Context rot makes compaction more important as windows grow, because quality degrades with size.
Framed as the open fight in Anthropic's platform docs, Oct 2026.
Anthropic's tell: they ship both a 1M default and a compaction beta, betting on both.
one person's bet, not a camp
Anthropic's bet: windows keep growing, and curation beats size
Anthropic's vision: 1M-token windows are already the default on current Claude models and keep getting cheaper (Haiku 5.5: $0.10 per million input tokens). But Anthropic's own docs warn of context rot: accuracy and recall degrade as token count grows, so the scarce skill becomes choosing what goes in, not how much fits.
Anthropic platform docs, Oct 2026; Haiku 5.5 pricing, Oct 7, 2026.

Takeaways

The window is working memory: limited, shared by everything including the answer, and rented by the token. When it fills, compaction swaps old turns for a summary, and what survives depends on how it was loaded, not how important it was. Files beat conversation, explicit beats implied, recent beats old. That is the whole game.

Keep exploring

Sources

Every factual claim in sections 2 through 5 traces to one of these.

The window is the desk. Compaction is the filing. Put what matters in files, and the summary can't eat it.