The full answer
A model remembers nothing between calls. Everything it "knows" in a run is whatever the application puts in the context window on that call. agent memory is the set of ways to choose what goes in: the recent conversation, summaries of older parts, notes kept in files, and facts fetched from a search index when needed.
1. Short-term: the context window
The conversation so far, tool calls and results included, is sent on every turn. It is exact but bounded, and every token in it is paid for again on each turn. Long tool outputs fill it fastest.
2. Trimming and summaries
- Clearing old tool results. Context editing on the Claude API (the
clear_tool_uses_20250919strategy) replaces the oldest tool results with a placeholder once the input passes a threshold, keeping the latest few. - compaction. When the conversation nears the limit, it is summarised and the summary replaces the history. The Claude Agent SDK does this automatically. The risk is that a detail the summary dropped is gone, which is why rules that must always hold go in a file loaded each run (CLAUDE.md) rather than in the chat.
3. Long-term: files and notes
The agent writes what it learns to files and reads them back later. Anthropic's memory tool gives the model commands to view, create, edit and delete files under /memories. Your application executes them against storage you control, so you can scope them per user. A progress file plus a to-do list lets a new session continue where the last one stopped. A coding agent's CLAUDE.md or AGENTS.md is the same idea, written by people.
4. Retrieval: vector stores and search
For a large body of facts (documents, past tickets), store embeddings in a vector database and fetch the few most relevant passages when they are needed. This is RAG used as memory. It scales to millions of items, but it only finds what the query resembles, so it needs good chunking and sometimes keyword search alongside.
How to choose
| Need | Use |
|---|---|
| The current task's steps | The context window |
| A long run that hits the limit | Clearing tool results, then compaction |
| Rules and preferences that always apply | A file loaded every run |
| What was learned, across sessions | Memory files the agent writes |
| A large library of facts | Retrieval from a search or vector index |
Risks to mention
Memory is an attack surface. An injected instruction saved to memory comes back in every later session. Validate what is written, restrict paths (the memory tool's docs warn about ../ traversal), expire old entries, and never store secrets.
Last updated 16 October 2026
Sources