The memory tool is currently in beta. To enable it, use the beta header
context-management-2025-06-27
in your API requests.Please reach out through our feedback form to share your feedback on this feature.Use cases
- Maintain project context across multiple agent executions
- Learn from past interactions, decisions, and feedback
- Build knowledge bases over time
- Enable cross-conversation learning where Claude improves at recurring workflows
How it works
When enabled, Claude automatically checks its memory directory before starting tasks. Claude can create, read, update, and delete files in the/memories
directory to store what it learns while working, then reference those memories in future conversations to handle similar tasks more effectively or pick up where it left off.
Since this is a client-side tool, Claude makes tool calls to perform memory operations, and your application executes those operations locally. This gives you complete control over where and how the memory is stored. For security, you should restrict all memory operations to the /memories
directory.
Example: How memory tool calls work
When you ask Claude to help with a task, Claude automatically checks its memory directory first. Here’s what a typical interaction looks like: 1. User request:Supported models
The memory tool is available on:- Claude Sonnet 4.5 (
claude-sonnet-4-5-20250929
) - Claude Sonnet 4 (
claude-sonnet-4-20250514
) - Claude Opus 4.1 (
claude-opus-4-1-20250805
) - Claude Opus 4 (
claude-opus-4-20250514
)
Getting started
To use the memory tool:- Include the beta header
context-management-2025-06-27
in your API requests - Add the memory tool to your request
- Implement client-side handlers for memory operations
To handle memory tool operations in your application, you need to implement handlers for each memory command. Our SDKs provide memory tool helpers that handle the tool interface—you can subclass
BetaAbstractMemoryTool
(Python) or use betaMemoryTool
(TypeScript) to implement your own memory backend (file-based, database, cloud storage, encrypted files, etc.).For working examples, see:- Python: examples/memory/basic.py
- TypeScript: examples/tools-helpers-memory.ts
Basic usage
Tool commands
Your client-side implementation needs to handle these memory tool commands:view
Shows directory contents or file contents with optional line ranges:create
Create or overwrite a file:str_replace
Replace text in a file:insert
Insert text at a specific line:delete
Delete a file or directory:rename
Rename or move a file/directory:Prompting guidance
We automatically include this instruction to the system prompt when the memory tool is included:Note: when editing your memory folder, always try to keep its content up-to-date, coherent and organized. You can rename or delete files that are no longer relevant. Do not create new files unless necessary.You can also guide what Claude writes to memory, e.g., “Only write down information relevant to <topic> in your memory system.”
Security considerations
Here are important security concerns when implementing your memory store:Sensitive information
Claude will usually refuse to write down sensitive information in memory files. However, you may want to implement stricter validation that strips out potentially sensitive information.File storage size
Consider tracking memory file sizes and preventing files from growing too large. Consider adding a maximum number of characters the memory read command can return, and let Claude paginate through contents.Memory expiration
Consider clearing out memory files periodically that haven’t been accessed in an extended time.Path traversal protection
Malicious path inputs could attempt to access files outside the
/memories
directory. Your implementation MUST validate all paths to prevent directory traversal attacks.- Validate that all paths start with
/memories
- Resolve paths to their canonical form and verify they remain within the memory directory
- Reject paths containing sequences like
../
,..\\
, or other traversal patterns - Watch for URL-encoded traversal sequences (
%2e%2e%2f
) - Use your language’s built-in path security utilities (e.g., Python’s
pathlib.Path.resolve()
andrelative_to()
)