Improve agent memory with dreaming in Claude Managed Agents
Use dreaming in Claude Managed Agents to turn past agent sessions into a cleaner memory store, so your agent learns from its own work over time.

What you need
Dreams run on the Claude API only while they're in research preview. Managed Agents sessions aren't eligible for zero data retention.
Step 1: Install the CLI and sign in
3 minThe CLI handles sign-in and beta headers for you, so every later command stays short.
- Request dreaming access on Anthropic's form and wait for approval.
- On a Mac, run the commands below. On Linux, get the binary from the anthropic-cli releases page.
- Sign in to your Claude Console account when
ant auth loginasks.
Run thisbrew install anthropics/tap/ant ant auth login
You should see a finished sign-in in the terminal, with no error.
Dream commands fail with an access error?
Access to Managed Agents doesn't include dreams. Request the research preview on the form, then use the CLI or an SDK so the
dreaming-2026-04-21header is sent for you.If you use an API key instead, keep it in the
ANTHROPIC_API_KEYvariable. Never put it in YAML files you share or commit.Step 2: Create a memory store
3 minThe store is where your agent keeps what it learns, and it's the input a dream later cleans up.
- Save the text below as
memory_store.yaml. Change the name and description to fit your agent. - Run
ant apply memory_store.yaml. - Copy the store ID, which starts with
memstore_.
Your memory_store.yamlname: Support notes description: What the support agent has learned about [YOUR PRODUCT]: fixes that worked, customer preferences and mistakes to avoid.
You should see a new memory store ID that starts with
memstore_.The request comes back with a 400 error?
Memory store calls use the
agent-memory-2026-07-22beta header. Sending it together withmanaged-agents-2026-04-01fails, so swap one for the other if you set headers yourself.The agent reads the description, so say what belongs in the store. Each memory holds up to 100 kB, and a store holds up to 10,000 memories.
- Save the text below as
Step 3: Give each session the store
5 minA store attaches only when a session starts, and each session that writes to it gives the dream more to work with.
- Start a session with the command below, with your IDs and task filled in.
- Send the session its task from your app or the SDK, as you do now.
- Run at least 3 sessions on the same kind of task, and note each session ID.
Run thisant beta:sessions create <<YAML agent: [YOUR AGENT ID] environment_id: [YOUR ENVIRONMENT ID] resources: - type: memory_store memory_store_id: [YOUR MEMSTORE ID] access: read_write instructions: Check these notes before you start. Save what you learn about [YOUR TASK]. YAMLYou should see a session ID that starts with
sesn_, and new memories in the store after each run.The agent never reads or writes its notes?
Check that the agent has the
agent_toolset_20260401tools. The store is mounted under/mnt/memory/, and the session'smount_pathfield shows the exact folder.With
read_writeaccess, a prompt injection in untrusted input can plant false notes. Attach a storeread_onlywhen the agent only needs to read it.Step 4: Start a dream
3 minA dream reads the store and the transcripts, then writes a new store with duplicates merged and stale notes replaced.
- Fill in the store ID and 3 or more session IDs. A dream takes up to 100 sessions.
- In
instructions, say what the agent should get better at. - Run the command, then copy the dream ID, which starts with
drm_.
Run thisant beta:dreams create <<YAML inputs: - type: memory_store memory_store_id: [YOUR MEMSTORE ID] - type: sessions session_ids: - [SESSION ID 1] - [SESSION ID 2] - [SESSION ID 3] model: claude-opus-5-5 instructions: Focus on [WHAT THE AGENT SHOULD GET BETTER AT]. Ignore one-off notes. YAMLYou should see a dream with the status
pending, which moves torunningonce the work starts.The dream fails with
input_session_unavailable?An input session was deleted after the dream started. Leave the input store and sessions alone until the dream ends, then start a new dream.
Only some models run dreams, such as Claude Opus 5.5, Claude Sonnet 5.5 and Claude Fable 5.1. Your input store is never changed.
Step 5: Review the new store
5 minThe dream writes a separate store, so you decide if its version of memory is better.
- Run the first command until the status reads
completed. A dream takes minutes to a few hours. - Copy the
memory_store_idlisted underoutputs. - Run the second command to list the new store's memories, then read a few of them.
Run thisant beta:dreams retrieve --dream-id [YOUR DREAM ID] ant beta:memory-stores:memories list --memory-store-id [OUTPUT MEMSTORE ID] --path-prefix "/"
You should see fewer, tidier memories, with duplicates merged and old facts replaced by the latest ones.
The output store looks half finished?
A
failedorcanceleddream leaves a partial store behind. Read the dream'serrorfield, delete that store, and try again with fewer sessions.To fix a single memory by hand, use
ant beta:memory-stores:memories updateon the output store. Dream instructions steer the whole pass, not single lines.- Run the first command until the status reads
Step 6: Switch to the curated store
2 minNew sessions only benefit from the cleaner memory once you attach it.
- Start new sessions with the output store's ID in place of the old one.
- Once you trust the new store, archive the old one with the command below.
Run thisant beta:memory-stores archive --memory-store-id [OLD MEMSTORE ID]
You should see new sessions working from the curated store, and the old store marked as archived.
Archiving can't be undone. An archived store becomes read-only and can't be attached to new sessions.
You get
An agent that starts each session from a cleaned-up memory, built from its own past work
Try next
Did this guide work for you?
Thanks. It helps us fix the steps.


