How AI Agents Remember Things
An agent starts every session with a blank mind โ memory systems like CLAUDE.md and memory files bridge that gap.
The core problem
Every new session of an AI agent begins with an empty context window. Without extra mechanisms, the agent has no idea what happened yesterday โ which rules apply, what went wrong last time, which library your team uses.
Two kinds of memory
You can roughly split memory into two kinds. Semantic memory is fixed, durable rules and facts โ "we use pnpm, not npm," code style, architecture decisions. That lives in files like CLAUDE.md or AGENTS.md, which you maintain. Episodic memory is notes about specific past events โ "in session X, approach Y failed because Z." Notes like that are often written by the agent itself, in separate memory files.
How this looks technically
CLAUDE.md/AGENTS.md loads in full at every session. Memory files often work differently: a short index file always loads, while more detailed topic files load only on demand โ much like a table of contents pointing to detail pages.
Compaction
When context inside a running session gets too full, the agent automatically summarizes older parts of the conversation to free up room (compaction). That's a different mechanism from persistent files: it works within a session, not across sessions.
EXAMPLE
An example split: CLAUDE.md says 'Tests run with npm test, never use npm run test:ci locally' (semantic, durable). A memory file says 'Session from July 12: migration with db:push failed on a foreign-key violation โ try db:migrate:dry-run first next time' (episodic, tied to a specific event).
QUICK QUIZ
What best distinguishes an episodic memory note from a rule in CLAUDE.md?
SOURCES
- Claude Code docs: CLAUDE.md and auto memory โ code.claude.com
- Anthropic: Effective context engineering for AI agents โ www.anthropic.com
- agents.md: The AGENTS.md standard โ agents.md