agentdream

Agents that dream.

The PokéCenter is north south of the gym.

An agent kept the first version in its notes. In two sessions it walked north of the gym and found nothing. In a third it found the PokéCenter to the south. The note still said north.

agentdream reads an agent's notes and its recent session logs while the agent is idle, and stages a corrected copy: duplicates merged, stale values replaced, wrong notes fixed with the lines that prove it. You review the changes before anything is written.

pip install agentdream

Runs on your machine, with no dependencies and no model required. MIT licensed.

correct-2ec6281c, confidence 0.80 refutes session-01.jsonl:3
Walked north of the gym for 20 steps. No PokéCenter here, only tall grass.
refutes session-02.jsonl:2
Walked north of the gym again. No PokéCenter here, this is a dead end.
supports session-03.jsonl:2
It is just south of the gym, next to the Poké Mart.

One dream, charted

A sleep lab charts a night as a line that steps between stages. This is the same chart for a dream: each step shows where that phase is working. The line touches your files once, to read them, and does not come back until you accept.

your files, read-only a private, redacted copy the engine, rules or model a staging folder load redact limits consolidate verify insights write accept you, awake the dream
  1. loadReads the memory store (markdown, JSON, SQLite) and the transcripts, keeping a file and line reference on every message.
  2. redactScrubs API keys, tokens, passwords and card numbers before anything is analysed or sent to a model.
  3. limitsTrims oversized inputs with a notice, or stops if you asked it to fail instead.
  4. consolidateMerges duplicate notes, keeps the newest of two dated values, resolves reversed preferences.
  5. verifyCompares each note with what the transcripts show and corrects the ones the evidence contradicts.
  6. insightsRecords what recurs across sessions: repeated preferences, repeated mistakes, settled workflows.
  7. writeWrites the new store, a report and a diff into the staging folder.

Review it like a proof

This is the bundled example as a dream stages it. Each change is an operation with its own id, so you can accept some and leave others. Untick one and watch the file.

examples/memory/MEMORY.mddry run, nothing applied
      All four selected.

      Does Claude Code do better work?

      Ten coding tasks, run through Claude Code itself in copies of one project. The copies differ only in CLAUDE.md: notes that have drifted, the same notes after a rule-based dream, and after a model dream. Three models, three runs each, 270 runs, every result checked by code.

      Tasks completed correctly

      Out of 90 runs per memory file: Haiku, Sonnet and Opus, 30 each.

      Drifted notes59 / 90
      After a rule-based dream78 / 90
      After a model dream90 / 90
      0306090
      Passed, out of 30DriftedRulesModel
      claude-haiku-5-5212730
      claude-sonnet-5-5182430
      claude-opus-5-5202730
      What had drifted in the notesDriftedRulesModel
      A preference the user later reversed (2 tasks)0 / 1818 / 1818 / 18
      An outside fact that changed, not in the code0 / 90 / 99 / 9
      A note naming a file nothing reads5 / 96 / 99 / 9
      A dead command, a missing directory, an old value beside the new (4 tasks)36 / 3636 / 3636 / 36
      Nothing: the notes are right (2 control tasks)18 / 1818 / 1818 / 18

      Every model followed a note that stated a preference or an outside fact, in every run, because nothing in the repository contradicts it. Notes about the code were checked against the code and cost no failures. Read the result with these in mind:

      • The tasks were written to run into the drift. This shows which wrong notes cost a task and that a dream removes the cost. It does not say how often your notes are wrong.
      • One small project, written by the same hand as the tool. Real transcripts are messier.
      • A dream did not make the agent faster or cheaper. Turns and cost per task stayed about the same.

      Reproduce it with python evals/claude_code/run.py. The 270 runs cost $15.95. Details are in the write-up.

      Does the memory get better?

      The built-in benchmark writes a store of 130 notes and 50 sessions in which every defect is known: duplicates, stale values, notes the transcripts refute, reversed preferences, paraphrases, and 30 notes that must not change. It holds 80 facts and is scored by code, before and after.

      Facts an agent would read correctly

      The store states exactly one value for the fact, and it is the true one.

      Before the dream50 / 80
      Rules, safe auto-update only60 / 80
      Rules, everything accepted80 / 80
      Model, everything accepted80 / 80
      020406080

      The same, and stated in a single note

      Duplicates count against this one. The gap between rules and model is paraphrased duplicates, which the rules do not find.

      Before the dream20 / 80
      Rules, safe auto-update only50 / 80
      Rules, everything accepted70 / 80
      Model, everything accepted80 / 80
      020406080
      EngineNotes that must not change, intactParaphrases mergedTimeCost
      Rules, the default30 / 300 / 100.12 sNone, offline
      Model, through a Claude Code login30 / 3010 / 10143 sThree model calls

      What these numbers do not show:

      • They score the memory store. Whether an agent then finishes real tasks more often has not been measured.
      • The notes are template-generated plain English, which suits rule-based matching. Expect the rules to find less in notes written the way people write.
      • The model result is one run of one model, and model output varies between runs.

      Run it yourself with agentdream benchmark. The method and per-category results are in the benchmark write-up.

      From Claude Code

      Three ways in. Each one starts as a dry run.

      Ask for a dream

      Install the skill, then type /dream. Claude runs a dry-run dream, walks you through the report and applies only what you approve.

      agentdream install-claude-skill

      Let it run after sessions

      A background dream after every third session. With --safe, merges and stale-value replacements are applied with a backup. Corrections wait for you.

      agentdream install-claude-hook --every 3 --safe

      Give Claude the tools

      An MCP server with dream, show_report and accept. The same server works in Cursor.

      claude mcp add agentdream -- agentdream serve-mcp

      Or by hand, on any agent's memory

      agentdream dream --memory ./memory --sessions "./logs/*.jsonl"   # dry run
      agentdream show <job-id>                                          # what changed and why
      agentdream accept <job-id> --only correct-2ec6281c                # apply some of it
      agentdream restore <job-id>                                       # undo an accept

      The default engine is rule-based and offline. --backend switches to Anthropic, any OpenAI-compatible server, Ollama, LM Studio, vLLM or your Claude Code login.

      Struck from the design

      • Changes your memory while you are awayA dream never writes to the store it read. Nothing is applied until you accept, or until you opt in to automatic updates.
      • Leaves no way backEvery accept backs up the store first and refuses to run if the store changed since the dream. One command restores it.
      • Sends your secrets to a modelKeys, tokens and passwords are redacted before analysis, again over every prompt, and again over every quote in the report.
      • Takes a model's word for itA proposal that names a note or a transcript line that does not exist is dropped. A correction without verifiable evidence is downgraded to a flag.