Durable Agent State by Name: an Agent SDK Session Id, a /memories Path or a Managed Agents Memory Store
Carla prefers email, and the process that learned it is gone. Durable state is state with an address: a session id brings back a conversation, a /memories path brings back a fact in storage you own, and a memory store (beta) is a shared, versioned folder a new session attaches read_write or read_only.
What you will learn
- Name the three places a Claude agent's durable state can live and the name that reaches each one
- Keep a fact across processes with the memory tool, and refuse paths that leave /memories
- Create a Managed Agents memory store, seed it and attach it to a session read_write or read_only
- Use a what-survives table (crash, another host, model change) to pick the home for each kind of state
Before you start
- Memory and context-window patterns for Claude agents
- Durable agent runs with checkpoints
On Monday, Carla tells the support agent she prefers email, not phone. Then the process ends and the context is gone. On Tuesday, ticket T-302 starts with nothing saved. The agent asks by phone again, and Carla repeats herself.
Now run the same Tuesday with the note saved at /memories/customers/C-77.md. The agent finds the note by its name and emails her. That's the whole idea of this article: durable state is state that has an address. Claude gives you three such places, and each one is reached by its own name.
Three places, three names
- A diary of the whole day, opened again by its number. That's an Agent SDK session, reached by its session id.
- A notebook in your own drawer. Claude writes the notes, but you keep the drawer. That's the memory tool, reached by a path under
/memories. - A shared filing cabinet. Many people open the same folder, and some may only read it. That's a memory store in Claude Managed Agents, in beta, reached by its
memory_store_id.
The memory tool and sessions each have their own article already: memory and context-window patterns covers the memory tool next to context editing and compaction, and Claude Code sessions covers resume, fork and starting fresh. Here we put all three side by side, add memory stores, and ask one question of each: what survives?
1. Agent SDK sessions: resume by id
When you call query() in the Agent SDK, the result message carries a session_id. Keep it, because the id is the name. The options, as the docs page on sessions lists them (the project doesn't run these, because they need the Claude Code runtime):
ClaudeAgentOptions(resume=session_id) # the same conversation, same id
ClaudeAgentOptions(resume=session_id, fork_session=True) # a new id with a copy; the original is unchanged
ClaudeAgentOptions(continue_conversation=True) # the latest session in this folder, no id
Two limits matter for durability:
- The session lives on this machine, as a file under
~/.claude/projects/. Another host needs asession_store, or the moved file. - It saves the conversation, not the files the agent changed.
The SDK resumes by id. The command line resumes by id or by name.
2. The memory tool: a path in storage you own
The project runs on a stand-in (the Anthropic SDK on an httpx mock transport, playing both the Messages API and the Managed Agents API), so no API key is needed and the replies are test replies.
The memory tool is client side: Claude asks for a command, and your code runs it. You turn it on with one entry in tools, {"type": "memory_20250818", "name": "memory"}. The part that matters for durability is the handler, and in particular how it resolves a path:
ROOT = (pathlib.Path(__file__).parent / "memories").resolve()
def resolve(path):
if not path.startswith("/memories"):
raise ValueError("path must start with /memories")
rest = path[len("/memories"):].lstrip("/")
real = (ROOT / rest).resolve()
if ROOT not in (real, *real.parents):
raise ValueError("path leaves /memories")
return real
ROOTis a folder you own./memoriesis only a prefix that maps onto it.- Every path must start with
/memories. - After resolving, the real path must still be inside the folder, so
/memories/../secrets.envis refused.
The rest of run_command handles create (write a file), str_replace (edit it in place) and view (list the folder or read a file). Each conversation in the run is a new process, so the only thing that carries over is the folder:
conversation 1 (one process): Carla's preference is new
memory view /memories
memory create /memories/customers/C-77.md
test model reply: noted for next time.
the process ends. only /memories is left on disk
conversation 2 (a new process): she writes again
memory view /memories
memory view /memories/customers/C-77.md
memory str_replace /memories/customers/C-77.md
test model reply: Carla prefers email, so I will email her.
conversation 3: a path outside /memories
memory view /memories/../secrets.env
test model reply: that path is outside /memories, so I did not open it.
The agent forgot everything. The folder remembered. Conversation 2 found the note by its path, read it and updated the same file. Conversation 3 asked for a path outside the folder and got an error back instead of the file.
3. Managed Agents memory stores: a shared, versioned folder
Memory stores belong to Claude Managed Agents, and they are in beta. A store is a folder that lives in the workspace, outside any one session, and many sessions can attach to it. This is an excerpt of memory_store.py (the unused import and the __main__ guard are left out):
"""Managed Agents memory stores (BETA): create one, seed it, attach it."""
from stand_in import make_client
# made by the Managed Agents setup
AGENT_ID = "agent_supportdesk"
ENVIRONMENT_ID = "env_supportdesk"
def attach(client, store_id, access):
"""a store can only be attached at creation"""
session = client.beta.sessions.create(
agent=AGENT_ID,
environment_id=ENVIRONMENT_ID,
resources=[{"type": "memory_store",
"memory_store_id": store_id,
"access": access}])
mount = session.resources[0].mount_path
print(f" {session.id} | {access} | mounted at {mount}")
return session
def main():
client = make_client()
store = client.beta.memory_stores.create(
name="SupportDesk Customers",
description="What we know about customers.")
print(f"store created | {store.id} | {store.name}")
mem = client.beta.memory_stores.memories.create(
store.id, path="/customers/C-77.md",
content="Carla Gomez prefers email, not phone.")
print(f"memory seeded | {mem.path}")
print("session 1, today:")
attach(client, store.id, "read_write")
print("session 2, next week, same store:")
attach(client, store.id, "read_write")
policies = client.beta.memory_stores.create(
name="SupportDesk Policies",
description="Refund and tone rules.")
print("a reference store the agent must not change:")
attach(client, policies.id, "read_only")
memory_stores.createmakes the store, and the store gets its own id. That id is the name.memories.createseeds a file at a path inside it.- The store is attached through
resourceswhen the session is created. It can only be attached at creation. accessisread_writeorread_only, and the session tells you itsmount_path, where the agent finds the folder.
memory store (BETA), Managed Agents:
store created | memstore_01 | SupportDesk Customers
memory seeded | /customers/C-77.md
session 1, today:
sesn_01 | read_write | mounted at /mnt/memory/supportdesk-customers
session 2, next week, same store:
sesn_02 | read_write | mounted at /mnt/memory/supportdesk-customers
a reference store the agent must not change:
sesn_03 | read_only | mounted at /mnt/memory/supportdesk-policies
The ids here are made up by the stand-in. What to notice: two different sessions, a week apart, see the same customer folder. The policies store is attached read_only, because the agent has no reason to change refund rules. For where Managed Agents sessions run, see Claude Managed Agents hosting.
What survives
Here is the table from the lecture, built from the Claude docs pages on sessions, the memory tool, agent memory and session threads:
| Home (its name) | Crash or restart | Another host | A model change |
|---|---|---|---|
| Agent SDK session (session id) | Kept on disk, same machine | Needs a session_store or the moved file | Not covered: record the model id yourself |
| Memory tool (/memories path) | Kept in your storage; the handler is yours | Kept if the handler serves the same store | Kept: plain text outside the chat |
| Memory store, beta (memory_store_id) | Kept in the workspace; versions track changes | Attach it to a new session when it is created | Kept: it sits outside every session |
| Session threads, beta (session id) | Transcript stays until you delete it | Reached by id through the API | Not stated: pin it yourself |
A name only helps if the thing behind it is still there. So match the home to the state: the session for the chat, memory for the facts, a read-only store for reference. Recording the model id beside a run is covered in resuming on the model the run started with.
Common mistakes
- Resuming by session id on any host. The session file is local to one machine unless you give the SDK a session store.
- Keeping the fact only in the conversation. A trim or a model switch can lose it. Put it in memory.
- Attaching every store read_write. An injected line in a ticket can then become trusted memory for every later session. Give the least write access that works.
- Trusting the path Claude sends. Resolve it and check it stays inside your folder, or
../walks out. - Expecting memory to undo actions. A session or a note brings back what the agent knew. Side effects still need an idempotency key, as in durable agent runs.
Quick recap
| Place | Name | Best for |
|---|---|---|
| Agent SDK session | resume=session_id | Bringing back one conversation on the same machine |
| Memory tool | /memories/... path | Facts in storage you own, across processes |
| Memory store (beta) | memory_store_id | A shared, versioned folder for many sessions, read_only where it should be |
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
Claude Certified Developer - Professional (CCDV-P) Exam Prep
Claude agents in production: reliability, observability, evals, cost, guardrails and fleets.View on Udemy ↗: Claude Certified Developer - Professional (CCDV-P) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.
