Using Memory Stores for Cross-Session Persistence in Claude Agents
Claude Managed Agents (CMA) achieve cross-session persistence by mounting a CMA Memory Store as a virtual file system, allowing agents to read from and write to a shared, persistent repository across independent chat sessions.
The anthropics/cwc-workshops repository demonstrates this architecture through the Agents that Remember workshop, showing how persistent memory transforms stateless agents into context-aware collaborators. By attaching the same memory store to multiple sessions via resource flags, developers enable agents to recall past interactions, track preferences, and build cumulative knowledge over time.
How Memory Stores Enable Cross-Session Persistence
Memory stores function as durable key-value repositories that behave like virtual file systems attached to Claude Managed Agents. Unlike ephemeral session contexts, these stores survive individual session termination, acting as a shared brain between otherwise isolated conversations.
The Role of Memory Stores
According to the source code in agents-that-remember/README.md, a memory store provides persistent storage that agents can interact with at runtime through standard read/write operations. When mounted on multiple sessions, the store creates a bidirectional data flow: Session A writes information that Session B can later retrieve, effectively eliminating the "goldfish memory" limitation of standard chat interfaces.
Session Resources and Access Control
Sessions connect to memory stores through a resource descriptor injected at creation time. As implemented in the anthropics/cwc-workshops codebase, this resource is a JSON object specifying the store ID, access level, and system prompt guidance.
The resource descriptor supports two access modes:
read_write: Full bidirectional access for active learning and note-takingread_only: Restricted access for consuming distilled knowledge without modification
When a session starts, the system prompt defined in the resource's prompt field automatically instructs the agent on when and how to interact with the store, eliminating the need for hard-coded I/O logic in the agent's core implementation.
Creating and Attaching Memory Stores
The following CLI workflows, derived from agents-that-remember/scripts/bootstrap.sh, demonstrate the complete lifecycle of memory store provisioning.
Create a Memory Store
First, provision the persistent storage entity using the ant CLI:
MEM=$(ant beta:memory-stores create \
--name "cwc-memory" \
--description "Cross-session knowledge for my CwC agent" \
--format json | jq -r .id)
echo "Memory store ID: $MEM"
Mount the Store on a Session
Attach the store to a new session using the --resource flag with a properly formatted JSON descriptor:
MEM_RESOURCE='{
"type":"memory_store",
"memory_store_id":"'"$MEM"'",
"prompt":"Track which CwC sessions I have attended and any follow-up links.",
"access":"read_write"
}'
SES=$(ant beta:sessions create \
--agent "$AGENT" \
--environment-id "$ENV" \
--title "First session with memory" \
--resource "$MEM_RESOURCE" \
--format json | jq -r .id)
Persist and Retrieve Data
Once mounted, the agent automatically writes data based on the system prompt instructions. You can also manually inspect stored memories:
# Store data through natural conversation
ant beta:sessions:events send \
--session-id "$SES" \
--event '{"type":"user.message","content":[{"type":"text","text":"I attended the CMA talk yesterday – notes at https://example.com/notes/cma"}]}'
# Retrieve all stored memories
ant beta:memory-stores:memories list --memory-store-id "$MEM"
The Dreaming Service for Knowledge Distillation
The Dreaming Service provides automated batch processing that compresses raw session transcripts into distilled, curated knowledge stores. As documented in agents-that-remember/README.md, this service runs a Claude model (claude-opus-4-7) over historical data to generate refined memory stores without manual curation.
Running a Dream Job
Create a dream that consumes both a memory store and specific session IDs, outputting a new, optimized store:
DREAM=$(ant beta:dreams create \
--model claude-opus-4-7 \
--input '{"type":"memory_store","memory_store_id":"'"$MEM"'"}' \
--input '{"type":"sessions","session_ids":["'"$HIST1"','"$HIST2"','"$HIST3"','"$SES"']}' \
--instructions "Summarize all session content into a concise knowledge base." \
--format json | jq -r .id)
# Wait for completion, then capture the output store ID
MEM_OUT=$(ant beta:dreams retrieve --dream-id "$DREAM" --format json \
| jq -r '.outputs[] | select(.type=="memory_store") | .memory_store_id')
The distilled store ($MEM_OUT) can then be mounted on fresh sessions, providing agents with compact, relevant context rather than raw chat logs.
Using Distilled Memory in New Sessions
Attach the refined knowledge base to subsequent sessions for improved recall:
ant beta:sessions create \
--agent "$AGENT" \
--environment-id "$ENV" \
--title "Recall after dreaming" \
--resource '{"type":"memory_store","memory_store_id":"'"$MEM_OUT"'"}' \
--format json
Bootstrap Automation
For rapid prototyping, the repository provides agents-that-remember/scripts/bootstrap.sh, which automates the complete setup workflow. This script provisions the Claude Managed Agent, initializes the execution environment, seeds historical sessions, and creates initial memory stores, allowing immediate experimentation with cross-session persistence features.
The bootstrap script also references agents-that-remember/.env.example for required API key configuration (ANTHROPIC_API_KEY).
Summary
- Memory stores provide virtual file system persistence that survives individual session termination, enabling state sharing across independent Claude agent conversations.
- Resource descriptors mount stores onto sessions via the
--resourceflag, specifyingmemory_store_id,accesslevel (read_writeorread_only), and contextualpromptinstructions. - Dreaming automates knowledge compression by running batch jobs over session transcripts to create distilled, refined memory stores optimized for future retrieval.
- The bootstrap.sh script in the
anthropics/cwc-workshopsrepository automates end-to-end provisioning of agents, environments, and memory stores for immediate development.
Frequently Asked Questions
What is a CMA Memory Store?
A CMA Memory Store is a persistent key-value repository exposed as a virtual file system to Claude Managed Agents. According to the anthropics/cwc-workshops source code, it allows agents to write data during one session and read it during another, functioning like a hard drive for the agent that survives chat session boundaries.
How does the dreaming service improve agent memory?
The dreaming service consumes raw session transcripts and existing memory stores as inputs, then uses the claude-opus-4-7 model to generate a new, distilled memory store. This process compresses verbose conversation history into concise knowledge bases, reducing token consumption while improving retrieval accuracy for future sessions.
What access levels are available for memory stores?
Memory stores support two access levels defined in the resource JSON: read_write allows the agent to both store new information and retrieve existing data, while read_only restricts the agent to consumption only. The access level is set when attaching the store via the --resource flag during session creation.
How do I automate memory store setup?
Use the agents-that-remember/scripts/bootstrap.sh script from the anthropics/cwc-workshops repository. This shell script automates the creation of the agent, environment, memory stores, and seed sessions, requiring only the ANTHROPIC_API_KEY environment variable defined in .env.example to be configured.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →