Encode now, consolidate later
Søren Kierkegaard wrote that life can only be understood backward, but it must be lived forward.
People encode memory constantly, but much consolidation seems to happen offline: during sleep the hippocampus replays recent experience and integrates it into the neocortex. Agents can split the work the same way — capture work in logs as it happens, then reflect on those logs to fix mistakes or build new notes. Building on the sleep-time compute idea from Letta and UC Berkeley, that reflection is what the post calls dreaming.
“Agent memory” here means knowledge Claude gains from experience and keeps between sessions as context it can read later. It excludes weight updates, in-context learning within one conversation, and compaction.
Memory is a prediction
Writing down a rule predicts the pattern will matter again. On a CL-Bench 1.0 database task — answer, see the correct solution, write memory, start the next question in a fresh session — models differed in how far they got with that learning loop:
- Claude Sonnet 4.6 got as far as theories about why an answer was wrong: scattered files of untested guesses.
- Claude Opus 4.7 consolidated notes into one reference document and marked which facts were checked.
- Claude Sonnet 5 marked answers as confirmed after grading and wrote corrections when wrong.
- Claude Opus 5 was the first to close the loop: rules plus how it knew they were true, earlier answers, and warnings about traps. Opus 5.5 and Sonnet 5.5 also closed it.
Judging what's worth remembering
In Pokémon Red, about 10,000 steps in, the difference was what each model thought was worth saving:
Sonnet 3.7 recorded everything, including things it could read off the screen every turn, so its notes kept going stale; around step 10,000 it spent 17 steps creating six files and deleting nine without making a move. Fable 5 kept only what the game doesn't tell you — strategy, plans and tested rules — with global.md as a dashboard. Opus 5.5 kept a similarly small folder and beat the game.
Say what memory is for, not how to use it
Telling Opus 5 and Opus 4.7 to “record only failures” cost them much of their gain from memory. Steering helps older models most: prompting Sonnet 4.6 to read its memory before answering and to test its theories nearly doubled its score. Sonnet 5 read its memory before answering 9 times out of 10 unprompted; Sonnet 4.6 did so less than half the time.
Five things dreaming does
1 · Correct memory
Claude wrongly noted that the PokéCenter at Mt. Moon was on the east side, declared “Mt Moon DONE”, and kept dropping off a one-way ledge back onto the earlier route. Dreaming checked the note against the transcript and rewrote it; with the corrected note Claude went back into the cave and reached Cerulean City. With the uncorrected note it fell back three times and never got past the mountain.
2 · Build new representations
A wiki — linked pages Claude writes and maintains — gives it a map of its own knowledge. On about 350,000 internal Stainless files (roughly 420M tokens) and 25 questions, Opus 5 agents built a wiki over successive sessions:
The wiki helped most on questions that needed several documents, judgment or math. On a Harvey LAB task where most criteria came from a single document, it showed no clear gain; on another, the wiki grew larger than the documents themselves — like the map in Borges's “On Exactitude in Science”.
3 · Promote notes up the hierarchy
Dreaming can float notes to the top layer that the harness loads into every session. That layer must stay small: injected notes cost tokens, a wrong note reaches every session, and longer instruction files reduce adherence. Claude Code's auto memory, for instance, loads only the first 200 lines or 25 KB of MEMORY.md, which works as an index.
4 · Focus memory on a goal
On a LAB acquisition task, several agents writing one shared table of contract terms overwrote each other, and a brief from that wiki met only 41 of 57 graded facts (72%). After a loop in which Claude reflected on its failures and rewrote the instructions — one agent per contract, quoting terms word for word — it met 57 of 57.
5 · Fill gaps a session leaves
A session sees only its own context; dreaming looks across many. A second dreaming pass over one wiki found nine links to a missing page and repointed them to an existing one, and added three new pages, including an index.
Open questions
- When to write memory: in-session notes capture salience at the source but distract from the task; dreaming moves the work to the background, but its output isn't available right away.
- How to keep memory current: dreaming fixes mistakes but costs compute, so it may be better focused on information likely to change, or on a cadence tuned to how often memories are read.
- Whether transcript search should be the foundation: wikis plus search can work well, but representations need compute to keep free of accumulated errors.