In short
- Every session starts fresh. In coding agents, memory is files loaded at startup.
- CLAUDE.md: you write it, and it's loaded into every session. Put rules, workflows and project facts there.
- Auto memory: Claude writes it itself, with your preferences and corrections. It stays on your machine, one folder per repository.
- Inside auto memory: an index, MEMORY.md, plus topic files with detailed notes. At startup only the first 200 lines or 25 KB of the index load; topic files are read when needed.
- Memory is context, not a lock. It shapes behavior but doesn't enforce it. To block an action, use permission rules or a hook.
Why your agent forgot
An AI model doesn't learn from your chat. When a session ends, everything in its context window is gone. The next session starts fresh, so yesterday's rules are not there unless something brings them back.
In coding agents, that something is files. At startup, the agent reads certain files into its context. That is its memory.
Memory you write: CLAUDE.md
In Claude Code, CLAUDE.md is a plain text file you write. It is loaded into every session. Put things there that should always be true: how to build and test the project, coding rules, where things live, what to never do.
Keep it short and concrete. Anthropic's docs suggest staying under about 200 lines per file, because longer files use more context and are followed less reliably.
Memory the agent writes: auto memory
Auto memory is written by Claude itself. When you correct it or tell it a preference, it can save a note for next time.
Auto memory is machine-local. Each project gets its own memory folder, and all worktrees of the same git repository share it. It isn't shared across machines or cloud environments.
What's inside the memory folder
This keeps startup light: the index tells the agent what it knows, and the details come in only when they matter.
- MEMORY.md: an index, a short list of what is stored.
- Topic files with detailed notes.
- At startup only the first 200 lines or 25 KB of MEMORY.md load, whichever comes first.
- Topic files are not loaded at startup. Claude reads them only when they are needed.
Pro tip: memory is context, not a lock
Claude treats CLAUDE.md and auto memory as context, not as enforced configuration. A line like “never touch the .env file” makes that much less likely, but it doesn't guarantee it.
If something must never happen, enforce it outside the model: a deny rule in the permission settings (episode 7) or a hook that blocks the action.
Test yourself
5 quick questions. Pick an answer to check it.
Sources
- Claude Code docs: How Claude remembers your project (CLAUDE.md and auto memory)
- Claude Code docs: Configure permissions
Checked November 22, 2026.