--- url: "https://platform.claude.com/docs/en/managed-agents/memory" titulek: "Using agent memory - Claude Platform Docs" h1: "Using agent memory" popis: "Give your agents persistent memory that survives across sessions using memory stores." jazyk: "en" kanonicka: "https://platform.claude.com/docs/en/managed-agents/memory" drobecky: ["Managed Agents", "Using agent memory"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 12:01:25" znaku: 13403 slov: 1947 kodovani: "utf-8" sha256: "9f98dd4f6195d33ba28afbc3bcbe6987b036720a4f3f6faafc1a8604b680f8d1" --- Each Managed Agents session starts with a fresh context by default. When a session ends, any state the agent built up is gone. Memory stores let the agent carry information across sessions: user preferences, project conventions, prior mistakes, and domain context. ## Overview A **memory store** is a workspace-scoped collection of text documents optimized for Claude. When you attach a store to a session, it is mounted as a directory inside the session's sandbox. The agent reads and writes it with the same file tools it uses for the rest of the filesystem, and a note describing each mount is automatically added to the system prompt, telling the agent where to look. The [agent toolset](/docs/en/managed-agents/tools) is required for these interactions; make sure to enable it during [agent creation](/docs/en/managed-agents/agent-setup). On [self-hosted sandboxes](/docs/en/managed-agents/self-hosted-sandboxes#use-memory-stores), that directory is not a live mount. Instead, the SDK's environment worker downloads each attached store into your sandbox before the agent's tools run and keeps that copy in sync with the store. Each **memory** in a store is addressed by a path and can be read and edited directly through the API or the Claude Console, allowing for tuning, importing, and exporting. Every change to a memory creates an immutable **memory version**, giving you an audit trail and point-in-time recovery for everything the agent writes. ## Create a memory store Give the store a `name` and a `description`. The description is passed to the agent, telling it what the store contains. ``` store_id=$(ant beta:memory-stores create \ --name "User Preferences" \ --description "Per-user preferences and project context." \ --transform id --raw-output) ``` The memory store `id` (`memstore_...`) is what you pass when attaching the store to a session. ### Seed it with content (optional) Pre-load a store with reference material before any agent runs: ``` ant beta:memory-stores:memories create \ --memory-store-id "$store_id" \ --path "/formatting_standards.md" \ --content "All reports use GAAP formatting. Dates are ISO-8601..." \ > /dev/null ``` ## Attach a memory store to a session Memory stores are attached in the session's `resources[]` array when the [session is created](/docs/en/managed-agents/sessions#creating-a-session). Unlike file resources, memory stores can only be attached at session creation time; adding or removing one from a running session is not supported. You attach memory stores the same way for sessions on cloud and [self-hosted environments](/docs/en/managed-agents/self-hosted-sandboxes#use-memory-stores); self-hosted environments accept only `memory_store` resources. Optionally include `instructions` to provide session-specific guidance for how the agent should use this store. It is shown to the agent alongside the store's `name` and `description`, and is capped at 4,096 characters. You can configure `access` as well. It defaults to `read_write` (shown explicitly in the following example), but `read_only` is also supported. ``` ant beta:sessions create < /dev/null ``` See the [Update a memory reference](/docs/en/api/beta/memory_stores/memories/update) for full parameters and response schema. #### Safe content edits (optimistic concurrency) To avoid clobbering a concurrent write, pass a `content_sha256` precondition. The update only applies if the stored content hash still matches the one you read; on mismatch, re-read the memory and retry against the fresh state. ``` ant beta:memory-stores:memories update \ --memory-store-id "$store_id" \ --memory-id "$mem_id" \ --content "CORRECTED: Always use 2-space indentation." \ --precondition "{type: content_sha256, content_sha256: $mem_sha}" \ > /dev/null ``` ### Delete a memory ``` ant beta:memory-stores:memories delete \ --memory-store-id "$store_id" \ --memory-id "$mem_id" \ > /dev/null ``` See the [Delete a memory reference](/docs/en/api/beta/memory_stores/memories/delete) for full parameters and response schema. ## Audit memory changes Every mutation to a memory creates an immutable **memory version** (`memver_...`). Use the version endpoints to audit who changed what and when, to inspect or restore a prior snapshot, and to scrub sensitive content out of history with redact. Versions belong to the store (not the individual memory) and are not deleted when the memory itself is deleted, so the audit trail also covers deleted memories, subject to the retention described below. Versions are retained for 30 days after they are written; however, the recent versions of a live memory are always kept regardless of age, so memories that change infrequently might retain history beyond 30 days. The live `memories.retrieve` call always returns the latest version; the version endpoints give you the retained history. There is no dedicated restore endpoint; to roll back, retrieve the version you want and write its `content` back with `memories.update` (or `memories.create` if the parent memory has been deleted, provided the version you want is still retained). Past memory versions might be deleted after 30 days. To preserve memory history for longer, export versions through the API. ### List versions List version history for a store, newest first. The example filters to a single memory's history: ``` versions=$(ant beta:memory-stores:memory-versions list \ --memory-store-id "$store_id" \ --memory-id "$mem_id" \ --format json) # `list --format json` emits one JSON object per item. jq -r '"\(.id): \(.operation)"' <<< "$versions" version_id=$(jq -rs '.[1].id' <<< "$versions") ``` See the [List memory versions reference](/docs/en/api/beta/memory_stores/memory_versions/list) for full parameters and response schema. ### Retrieve a version Fetching an individual version returns the same fields as the list response plus the full `content` body. ``` ant beta:memory-stores:memory-versions retrieve \ --memory-store-id "$store_id" \ --memory-version-id "$version_id" ``` See the [Retrieve a memory version reference](/docs/en/api/beta/memory_stores/memory_versions/retrieve) for full parameters and response schema. ### Redact a version Redact scrubs content out of a historical version while preserving the audit trail (who did what, when). Use it for compliance workflows such as removing leaked secrets, PII, or user deletion requests. A version that is the current head of a live memory cannot be redacted. Write a new version first (or delete the memory), then redact the old one. ``` ant beta:memory-stores:memory-versions redact \ --memory-store-id "$store_id" \ --memory-version-id "$version_id" ``` See the [Redact a memory version reference](/docs/en/api/beta/memory_stores/memory_versions/redact) for full parameters and response schema. ## Manage memory stores In addition to [`create`](/docs/en/api/beta/memory_stores/create), memory stores support [`retrieve`](/docs/en/api/beta/memory_stores/retrieve), [`update`](/docs/en/api/beta/memory_stores/update), [`list`](/docs/en/api/beta/memory_stores/list), [`archive`](/docs/en/api/beta/memory_stores/archive), and [`delete`](/docs/en/api/beta/memory_stores/delete). ### List stores List stores in the workspace. Archived stores are excluded by default; pass `include_archived: true` to include them. ``` ant beta:memory-stores list --include-archived ``` See the [List memory stores reference](/docs/en/api/beta/memory_stores/list) for full parameters and response schema. ### Archive a store Archiving makes a store read-only and prevents it from being attached to new sessions. Archiving is one-way; there is no unarchive. ``` ant beta:memory-stores archive --memory-store-id "$store_id" ``` See the [Archive a memory store reference](/docs/en/api/beta/memory_stores/archive) for full parameters and response schema. To permanently remove a store along with all of its memories and versions, use [`memory_stores.delete`](/docs/en/api/beta/memory_stores/delete). ## Best practices for memory management When a store reaches its 10,000-memory limit, writes to new memories fail: both direct `memories.create` calls and the agent's file writes to unmapped paths. Existing memories remain readable and editable. The following practices help you stay well under the limit and recover gracefully if you reach it. - **Use focused stores.** Rather than one large general-purpose store, use smaller purpose-built stores: one per user, one for shared domain knowledge, and one for project-specific context. Each store has its own 10,000-memory limit, so keeping stores scoped reduces the chance any single one fills up. - **Condense or prune before the store fills up.** Delete stale or redundant memories with `memories.delete`. You can also run a [dreaming session](/docs/en/managed-agents/dreams), which consolidates fragmented content into a separate new output store rather than modifying the original. Switch your sessions over to that output store, then archive or delete the original. - **Attach a new store when it makes sense.** If a store has grown beyond its useful scope, attach a fresh one for new content and attach the original with `read_only` access. The agent can read from both while only writing to the new one. - **Limit write access where appropriate.** Sessions that only read shared reference material don't need `read_write`. Keeping write access scoped to sessions that actually add new memories makes it easier to track where growth is coming from. Was this page helpful?