The components of agent memory
# Dreaming: How Claude Builds and Maintains Agent Memory Anthropic's post argues that agent memory works best when split into two processes, like the human brain's division between fast encoding and offline consolidation. Claude captures salient events during work, and a separate "dreaming" phase later replays logs, corrects mistakes, and reorganizes memory into representations that future sessions can use. The authors report that dreaming improves memory accuracy, that stronger models judge what is worth saving better when given freedom rather than fixed rules, and that the value of structures like wikis depends on the task. ### Memory as Prediction - Agent memory is defined as knowledge Claude gains from experience and retains across sessions, excluding weight updates, in-context learning, and compaction. - Writing a memory note is a prediction that the pattern will be relevant later. - On the CL-Bench 1.0 database task, models differed in how well they closed a learning loop: recording failures, testing theories, and turning results into rules. Sonnet 4.6 only generated untested guesses, while Opus 5 was the first to consistently write validated rules, answers, and warnings about traps. Opus 5.5 and Sonnet 5.5 also closed the loop, scoring about the same as Opus 5 with memory. ### Judging Salience - In a Pokémon Red evaluation, Sonnet 3.7 wrote 413 memory files across 225 folders, earned one badge, and wasted steps reorganizing outdated records. - Fable 5 wrote nine files in two folders plus a single `global.md` dashboard, and earned four badges. - The better approach stored information that couldn't be read from the screen, such as strategy, plans, and tested rules. One example was a note that varying the timing of inputs helped catch a Magikarp after repeated failures. ### Steering Memory Writes - Telling Claude what memory is for works better than prescribing how to use it. General guidance was enough for Opus 4.7 and Opus 5 to gain a noticeable performance boost. - Fixed rules such as "record only failures" removed much of the benefit for stronger models. - Older models benefit more from steering. Prompting Sonnet 4.6 to read memory and explicitly test its theories nearly doubled its benchmark score. Sonnet 5 reads memory on its own in 9 of 10 cases, compared with fewer than half for Sonnet 4.6. ### Correcting Memory Through Dreaming - Because notes are written from in-session judgment, errors can persist and be trusted later. - In a Mt. Moon navigation case, Claude recorded the Pokémon Center's location incorrectly, leading it to walk off a one-way ledge three times. Dreaming checked the note against the transcript, fixed it, and let Claude reach Cerulean City. The uncorrected run never got there. ### Building New Representations - Wikis are linked collections of pages Claude writes about a subject, acting as a navigable map of its memory. - On a 350,000-file internal corpus, 128 dreaming sessions raised accuracy on 25 questions from 13% to 48%. - Wiki plus search reached 61%, compared with 53% for search alone and 48% for the wiki alone, while saving about 20,000 tokens per question. - On merger questions requiring multi-document reasoning, the wiki raised scores from 73% to 87%. For tasks where a single-document text search was enough, the wiki gave no clear gain. In one case the wiki grew larger than the source documents and abstracted nothing. ### Promoting Notes and Focusing Goals - Dreaming can promote important notes to a small top layer that is loaded into every session. That layer must stay compact, since injected memories consume tokens and incorrect notes propagate. Claude Code's `MEMORY.md` loads only its first 200 lines or 25 KB for this reason. - Instructions for dreaming can be tuned to a task. In a contract-analysis benchmark, concurrent agents overwrote a shared table and the brief covered only 72% of facts. After the instructions were revised to give each contract its own page with verbatim terms, all criteria could be met. - Dreaming across sessions can also fill gaps. A second pass resolved nine broken links and added three pages, including an index. ### Open Questions - When to write memory is a tradeoff. Writing in the moment captures salience at the source but distracts from the task, while dreaming moves the work to the background but may not be immediately accessible. - Keeping memory current requires compute. The authors suggest focusing dreaming on information likely to change, or tuning its cadence based on access frequency. - Transcript search may serve as a foundation, with representations layered on top, but maintaining those representations requires ongoing effort to prevent errors from accumulating. The authors conclude that dreaming lets Claude look backward, organize memory, and correct mistakes, while acknowledging that much about memory system design remains to be learned.