# Memory and session context

> An agent forgets everything when a session ends unless something is written down. This topic covers automatic memory notes, curated context files, compaction of a long session, handing work from one session to the next, and turning work the agent repeats into knowledge it can reuse.

Page: https://schubergphilis.github.io/ai-training/topics/customizing-agents/memory/
License: CC BY-SA 4.0, https://creativecommons.org/licenses/by-sa/4.0/

*Customizing agents* · topic `customizing-agents/memory`

An agent forgets everything when a session ends unless something is written down. This topic covers automatic memory notes, curated context files, compaction of a long session, handing work from one session to the next, and turning work the agent repeats into knowledge it can reuse.

## Concepts

- **Auto-memory**: Notes an agent writes for itself during a session and reads back in later ones: preferences it learned, facts about the project, decisions made. It reduces re-explaining but is unreviewed by default, so it can carry a wrong assumption forward for weeks. Read what the agent remembers now and then, and correct or delete entries that have gone stale. [glossary](https://schubergphilis.github.io/ai-training/glossary/#auto-memory)
- **Context files**: Files a person curates for the agent to read: project instructions, design notes, a plan, a glossary of domain terms. Unlike auto-memory they are deliberate, versioned and reviewed like code. They are the right place for anything the whole team wants every session to know, and the place to move a fact once auto-memory has proven it useful. [glossary](https://schubergphilis.github.io/ai-training/glossary/#context-files)
- **Compaction**: Replacing a long session's history with a summary so work can continue inside the context window. Compaction keeps the goal and recent state and drops the raw detail, so anything not in the summary is lost. Ask for a summary that names open items and decisions before compacting, and save it to a file when the work will span sessions. [glossary](https://schubergphilis.github.io/ai-training/glossary/#compaction)
- **Session handoff**: Ending one session so the next can pick up without loss: a written state of what was done, what remains, what was decided and why, and where the relevant files are, stored in the repository or a plan file. A good handoff lets a fresh session, or a colleague's, start productive in one turn instead of rediscovering the work. [glossary](https://schubergphilis.github.io/ai-training/glossary/#session-handoff)
- **Turning repeated work into reusable knowledge**: Noticing when the agent is explained the same thing or walked through the same steps twice, and moving it somewhere durable: a fact into project instructions, a procedure into a skill, a check into a hook, an example into a context file. Each move removes a future explanation and a future mistake. It is the compounding part of working with agents. [glossary](https://schubergphilis.github.io/ai-training/glossary/#turning-repeated-work-into-reusable-knowledge)
- **Primary and secondary sources**: The code, the tests and the history of a repository are the primary source for what is true about a project now. Notes, handoffs, plans and saved memories are secondary: each records what someone believed at one moment, and it goes stale as the code moves on. An agent treats a secondary source as a lead and checks it against the primary one before acting on it. When the two disagree, the code wins and the note is corrected or deleted. [glossary](https://schubergphilis.github.io/ai-training/glossary/#primary-and-secondary-sources)

## Links

- **Builds on:** [Agent skills](https://schubergphilis.github.io/ai-training/topics/customizing-agents/skills/), [Grounding and memory](https://schubergphilis.github.io/ai-training/topics/concepts/grounding/)
- **Leads to:** nothing yet
- **Competencies drawing on it:** [Configures an agent for a project](https://schubergphilis.github.io/ai-training/competencies/customizing-agents/configures-agent/)

## Lessons

- [Directing the summary before compaction](https://schubergphilis.github.io/ai-training/customizing-agents/compaction/) (tutorial)
- [Reading what the agent remembers](https://schubergphilis.github.io/ai-training/customizing-agents/memory-review/) (tutorial)
- [Notes that go stale](https://schubergphilis.github.io/ai-training/customizing-agents/notes-that-go-stale/) (explanation)
- [Turning repeated work into something the agent keeps](https://schubergphilis.github.io/ai-training/customizing-agents/repeated-work/) (explanation)
- [Handing work to the next session](https://schubergphilis.github.io/ai-training/customizing-agents/session-handoff/) (tutorial)

## Sources

- `AEC-05` [Memory and context: context engineering, memory kinds, memory versus RAG, context rot](https://lsimons.github.io/agent-engineer-course/05-memory-and-context/), Agent Engineer Course (course)
- `Brilliant MEM` Memory (listed under SPC), Brilliant, Coding with AI skills map (reference)
- `Academy claude-code-101` [Claude Code 101](https://academy.claude.com/courses/claude-code-101), Claude Academy (course)
- `Academy claude-code-in-action` [Claude Code in action](https://academy.claude.com/courses/claude-code-in-action), Claude Academy (course)
- `Claude Code memory` [How Claude remembers your project](https://code.claude.com/docs/en/memory), Claude Code documentation (reference)
