Every time you close Claude Code, the session dies and the feedback, corrections, and hard-won context from that conversation evaporate. The model restarts from zero next time — re-discovering your preferences, re-learning what you already explained, re-committing the same mistakes. After hundreds of sessions, that ocean of lost learning is the single biggest thing holding your AI agent back from feeling like a genuine co-founder instead of a forgetful temp. A scheduled agent dreaming loop fixes this: every night, a background agent reviews the day's session transcripts, extracts patterns and corrections, prunes stale memories, and writes updated memory files so tomorrow's wake-up is smarter than today's.
Last verified: 2026-08-03
- Claude Code
CLAUDE.mdmemory files are loaded at session start, but only capture what you manually write — they do not learn from patterns across sessions.- Anthropic shipped an official Dreaming feature for Claude Managed Agents (research preview, May 2026) that automates this review-consolidate cycle.
- Enterprise customer Harvey reported ~6x improvement in task completion rates after enabling Dreaming.
- You can build a DIY dreaming loop with Claude Code Routines (scheduled) + a memory-review skill — no enterprise plan needed, just API credits for the nightly run.
What is Claude Code's memory problem?
Claude Code has no persistent learning across sessions by default. Each session boots with zero tokens and must be primed from scratch.
Claude Code's built-in memory system uses CLAUDE.md files — plain-text markdown loaded into the context window at the start of every session. You write project rules, conventions, and preferences there, and Claude reads them. Anthropic's official documentation describes CLAUDE.md files as giving "Claude persistent instructions for a project, your personal workflow, or your entire organization" (Claude Code Docs).
But this system has three big limitations that prevent real learning:
1. Split focus (your agent is doing two jobs at once). While you're actively prompting Claude to complete a task, you're also asking it to simultaneously maintain and update your memory file. It's like a chef trying to cook a dinner service and write a recipe book at the same time — both tasks suffer from the divided attention. The code gets worse because the agent is distracted by memory bookkeeping; the memory gets worse because the agent is rushing through it to get back to the real work.
2. Patterns are obfuscated (each agent only sees its own session). If every individual session writes to the memory file independently, no agent has the wider context window to spot patterns across sessions. It's like an NBA coach evaluating a player based on a single game out of an 82-game season — the roster decisions made from one data point are almost guaranteed to be worse than decisions made from the full season's data.
3. Memories go stale (old context steers you wrong). Notes that were accurate six months ago may now be actively misleading. Duplicate entries disagree with each other. Your memory file becomes confidently wrong, guiding future work in the wrong direction like a GPS routing you on roads from a decade ago.
These three problems are why manually maintaining a CLAUDE.md (or MEMORY.md) file gives diminishing returns. The longer you use it, the more unmaintained cruft accumulates; the more sessions you run, the wider the gap between what the agent has experienced and what the memory file actually captures.
This is where the concept of dreaming comes in — and it has some serious backing.
The neuroscience connection: Why your AI agent needs to "dream"
The idea of an AI agent "dreaming" draws directly from how the human brain consolidates learning. During the day, you accumulate experiences in short-term memory. During sleep, your hippocampus replays those experiences, selects what's worth keeping, strengthens those neural pathways, and discards the rest. You wake up with a consolidated, organized memory — not the chaotic jumble of the day's raw events.
The problem, as AI researchers at Anthropic and elsewhere have pointed out: LLMs have no equivalent. When you boot up a language model, it has zero tokens in the context window and is always restarting from scratch. As senior AI researchers have noted in public commentary on cognitive architectures, the brain achieves a "process of distillation into weights" via sleep, and current LLMs have no equivalent for that consolidation step (TechCrunch coverage).
The key insight: model weights can't change at inference time, but the external memory layer can. The system can improve session-over-session even if the underlying model stays the same — if something sits between sessions to consolidate what was learned.
Anthropic's official dreaming feature (research preview)
Anthropic literally named the feature Dreaming when they shipped it in May 2026 at the Code with Claude developer conference. According to Anthropic's official blog post: "Dreaming is a scheduled process that reviews agent sessions and memory stores to extract patterns and curate memories, enabling agents to improve over time" (Anthropic Blog).
Capabilities (per Anthropic's announcement):
- Surfaces recurring mistakes your agent makes across sessions
- Identifies workflows your agent naturally converges on (so you can formalize them)
- Captures shared team preferences and restructures memory to keep it high-signal as it evolves
How it works:
- A scheduled process runs between sessions in the background
- It reviews the past session transcripts (up to 100 prior sessions) alongside the existing memory store
- It extracts patterns, identifies recurring mistakes, proposes corrections, and merges duplicates
- It can either update memory automatically or require human review before changes are applied
- The next session loads the reorganized memory — already better than the last
Availability and cost:
- Dreaming is currently in research preview — developers need to request access through Anthropic's Claude Platform form (claude.com)
- It runs on Claude Managed Agents, Anthropic's server-side agent runtime (public beta)
- Usage is billed at standard API token rates — the cost depends on the size and number of sessions processed
Customer results: The legal AI company Harvey used Dreaming to help agents "remember filetype workarounds and tool-specific patterns between sessions" for complex long-form legal drafting work. According to Anthropic's official blog post, Harvey's "completion rates went up ~6x in their tests" (Anthropic Blog).
Caveat: Harvey is one data point, and the 6x improvement was "in their tests" — not independently verified. The improvement is specific to long-running, structured work (legal document drafting). If your agent workflow is more varied (different tasks per session), the top-line improvement may be smaller.
The DIY dreaming loop: Schedule Claude Code to learn overnight
If you don't have Claude Managed Agents enterprise access, or you want full control over the memory consolidation process, you can build your own "dreaming loop" using Claude Code Routines plus a custom memory-review skill. Here's how to set it up in four steps.
Step 1: Set up structured memory files
If you haven't already, make sure your Claude Code memory is initialized:
/init
This creates a CLAUDE.md file with your project conventions, build commands, and architecture. Run the /init command, follow the interactive prompts, and Claude will generate a starting memory file by analyzing your codebase (Claude Code Docs).
For a structured memory consolidation loop, you want your memory organized so a dream agent can reason about it:
~/.claude/
└── CLAUDE.md ← Project-level: overrides, gotchas, tool chain
~/.claude/projects/
└── <project-name>/
└── memory/
├── MEMORY.md ← Root memory file (first 200 lines auto-loaded)
├── debugging.md ← Topic file: debugging insights (loaded on demand)
├── api-conventions.md
└── user-preferences.md
If you're coming from an existing setup, you can also read our broader guide on how to give Claude a persistent memory system with Obsidian for the file-organization pattern, and our article on the three layers every AI agent OS needs in 2026 for the memory architecture.
Step 2: Create a "dream" skill that reviews past sessions
Create a Claude Code skill (a markdown file in .claude/skills/) called dream.md that instructs the agent to:
- Read session transcripts from the last 24 hours across your sessions
- Compare them against your current memory files
- Identify four categories of changes:
- Corrections — things you corrected the agent on that aren't in memory yet
- New facts — preferences or workflows repeated across sessions that should be saved
- Stale entries — memories that are now outdated or contradicted by recent sessions
- Duplicates — existing memory entries that conflict or overlap
- Propose each change in a numbered list, with a short quote from the relevant transcript as evidence
- By default: auto-apply only tiny safe fixes (typos, dead-link repairs, index rebuilds)
- Wait for human review on everything else
This is exactly the pattern our Claude skills tutorial for beginners walks through — a skill is a markdown file (sometimes with helper scripts) that Claude Code reads and follows when you invoke it by name.
Here's a skeleton for your dream.md skill:
---
name: dream
description: Review past 24h of session transcripts and propose memory updates
---
# Dream Skill
You are a memory-consolidation agent. Your job is to review
recent Claude Code session transcripts and propose updates to
the long-term memory files.
## What to do
1. Find all session transcripts from the last 24 hours
(search ~/.claude/projects/ recursively for .md files
modified in that window).
2. For each transcript, identify:
- Corrections: user pointed out something the agent did wrong
- New patterns: repeated actions or preferences the user expressed
- Stale context: memories contradicted by what happened in this session
- Duplicates: existing memories that now overlap or conflict
3. Open the memory files (MEMORY.md, topic files) and compare:
- Which corrections should become new memory entries?
- Which existing entries are now stale and should be removed?
- Which entries should be merged because they say the same thing?
4. Write a numbered list of proposed changes. For each change:
- Action: ADD / UPDATE / REMOVE / MERGE
- File (which memory file)
- One-line summary
- Verbatim quote from the transcript as evidence
5. Safe to auto-apply:
- Typo fixes
- Dead link removal
- Index rebuilds
- Removing clearly stale todos that are marked complete
6. Everything else: write the proposal to
`.dream/dream_report_<date>.md` for human review in the morning.
Step 3: Schedule the dream to run nightly
Use Claude Code Routines — Anthropic's cloud-run scheduled agent runner, launched in research preview April 2026 — to fire the skill automatically while you sleep. Routines run on Anthropic's cloud infrastructure without requiring your laptop to be on (Claude Code Docs).
Available triggers:
| Trigger | Use | Example |
|---|---|---|
| Scheduled | Runs hourly, daily, weekly, or at a specific future time | Fire the dream skill at 3 AM local each night |
| API | HTTP POST to a routine-specific endpoint fires it | Trigger the dream on demand from an external script |
| GitHub webhook | Repo events (PR, push, release) trigger it | Fire the dream after every merged PR |
Daily run limits by plan (shared with interactive usage):
| Plan | Daily routine runs |
|---|---|
| Claude Pro | 5 |
| Claude Max | 15 |
| Team / Enterprise | 25 |
To create a nightly dream routine in the Claude Code CLI:
/schedule
Then configure the routine:
- Prompt: "Invoke the dream skill with no arguments. Use the skill tool."
- Schedule: Daily at 03:00 in your local timezone
- Repository: (your repo path)
- Connectors: (any MCP servers the agent should see — e.g., your codebase connector)
If you'd rather not use Routines (or you'd rather not consume your daily routine quota on dreaming), you can also cron it locally. See our article on how to use Google AI Studio managed agents for the same scheduling pattern applied to a different agent framework — the trigger mechanics are identical.
Step 4: Review and approve in the morning
When you wake up, open the dream report — a markdown file the dream skill writes to .dream/dream_report_<date>.md listing each proposed change with evidence. Review and either approve or reject each one. If you want a richer review surface, you can render the report as HTML that lets you click approve/reject per item — the skeleton above shows how.
What this looks like in practice after a few weeks:
- The system adds a note about your preference for a specific file-naming convention after seeing you correct the agent three times in a row
- It flags a memory entry saying "use library X" that's now stale because you migrated to Y last month and the session transcripts show you only use Y now
- It identifies an iCloud folder where you save all media sources — so future sessions can access those files directly instead of you having to upload them every time
- It finds a 105-day-old TODO file whose entries have all been resolved by other memory updates and proposes deletion — removing a file that was slowing down every fresh context boot
The point isn't that any single capture matters. What compounds is the pattern recognition across sessions that no individual in-the-moment agent has the context to do.
When should you use a dreaming loop?
A scheduled memory consolidation loop is most valuable when your agent handles repetitive, structured work over long periods — coding, document drafting, research workflows, anything where you'll run dozens or hundreds of sessions in the same project.
| Use case | Value of dreaming | Notes |
|---|---|---|
| Long-running coding project (same repo for weeks) | High | Conventions and gotchas accumulate - dream loop captures them |
| One-off exploratory sessions | Low | No repetition to learn from |
| Customer support / drafting tasks | Medium-to-high | Patterns of user preferences surface after dozens of reps |
| Varied-request agent (different prompt each session) | Low | The improvement trajectory is less predictable |
| Multi-agent workflows | High | Shared memory helps each specialist agent learn faster |
The Harvey case — long-form legal drafting, the same workflow pattern over many sessions — is exactly the profile that benefits most. A task that changes every session won't compound the same way.
Avoiding the two big traps
Trap 1: Don't put everything in memory. Memory is not "everything that ever happened." It's the small set of durable facts that help the next session operate better. A good dreaming loop prunes as aggressively as it adds — see our guide to stopping AI coding technical debt for the parallel concept: just as scaffolding code built for older models hurts newer ones, stale memory scaffolding actively misleads the agent. Deleting dead memory is a feature.
Trap 2: Don't auto-approve structural changes without a human in the loop. Anthropic themselves made human review the default mode for the official Dreaming feature. The danger isn't that the agent will be malicious; it's that it will confidently reorganize memory in ways that feel right in context but subtly drift. Start with the "auto-apply only safe fixes" mode described above. Only switch to "auto-approve everything" if you have a rollout process and you're sure the structural changes are good.
What this means for you
If you run Claude Code on the same project for more than a week, set up a nightly dreaming loop. The investment is an hour to create the skill and a few API credits per night; the payoff is each day's session starts with the consolidated learning of every session that came before. For teams running agents in production, this is the highest-leverage memory work you can do — and it's strictly harder to replicate with just a bigger CLAUDE.md file or more manual note-taking. The real bottleneck for solo builders and small teams isn't model quality anymore — it's whether your agent gets smarter over time or resets every morning.
FAQ
Q: Is Anthropic's "Dreaming" feature available to all Claude Code users? A: No. As of August 2026, Dreaming is in research preview on Claude Managed Agents (Anthropic's server-side agent runtime). Developers need to request access via the Claude Platform form. The feature also bills at standard API token rates, so you pay for each nightly run.
Q: Can I build a dreaming loop without Claude Managed Agents or enterprise access? A: Yes. You can construct the same pattern using Claude Code Routines (scheduled trigger) plus a custom memory-review skill that you invoke nightly. Routines are available on Pro and Max plans (5 daily runs on Pro, 15 on Max). This is the DIY route most individual developers and small teams should prefer.
Q: Does dreaming change the Claude model itself?
A: No. The underlying model weights do not change — Anthropic's Dreaming and the DIY loop operate on the external memory layer only (your CLAUDE.md files or structured memory store). The system gets session-over-session because the context is curating, not because the model is getting better. This is a meaningful but bounded lens on what "self-learning" really means here.
Q: What's the difference between CLAUDE.md and a structured memory store for dreaming?
A: CLAUDE.md is flat — one markdown file loaded at session start. Auto-memory (Claude Code's automatic note-taking, launched in February 2026) writes topic files on demand at ~/.claude/projects/<project>/memory/ with a root MEMORY.md. A structured store with topic files is more compatible with a dreaming skill because the dream agent can reason about which file each change belongs in.
Q: How much does a nightly dream loop cost? A: It depends on the number and length of session transcripts your agent reviews. Each run requires reading the day's transcripts, comparing them against memory files, and writing proposals — typically a few thousand to tens of thousands of tokens of I/O. At standard Claude API pricing that's a fraction of a cent to a few cents per run, depending on the model you pick for the cron.
Q: What's the "compounding" analogy for memory consolidation? A: Think of it like a skilled co-worker who takes notes after every meeting and reorganizes them at the end of each day. After a year, that person's context — not their brain — is what makes them worth ten new hires. Same with the agent: the model doesn't get smarter, but the context it operates from keeps getting sharper. See our Sakana Fugu inside Claude Code guide for a related pattern on stacking multi-agent smarts.

Discussion
0 comments