50 50. CLAUDE.md and Memory
Every Claude Code session starts with a blank slate: Claude does not remember yesterday’s conversation. This page covers the two ways Claude Code carries knowledge from one session to the next: CLAUDE.md files that you write, and auto memory notes that Claude writes for itself.
50.1 Why Claude needs a memory file
As of Oct 6, 2026 · Official docs: How Claude remembers your project
Each session begins with a fresh context window, Claude’s working memory for one conversation (more on the Context, Models, Effort, and Usage page). Imagine a skilled new teammate who forgets everything every night. You would leave them a short note: how to run the project, the team’s rules, the mistakes to avoid. That note is CLAUDE.md, a plain-text Markdown file that Claude Code loads at the start of every session.
| CLAUDE.md files | Auto memory | |
|---|---|---|
| Who writes it | You | Claude |
| What it holds | Instructions and rules | Learnings: your preferences, corrections you gave, project facts Claude can’t get from the code |
| When it loads | Start of every session | Start of every session (the first 200 lines or 25 KB of its index) |
| Where it lives | In your project (and optionally your home folder) | In your home folder, under ~/.claude/projects/ |
Both are guidance, not guarantees. Claude reads them and tries to follow them, but nothing forces it to. If something must never happen (for example, reading your .env file of secrets), use a permission rule or a hook instead (see Permissions, Modes, and Safety and Hooks).
50.2 Where CLAUDE.md files live
As of Oct 6, 2026 · Official docs: How Claude remembers your project
| Scope | Location | Who it’s for |
|---|---|---|
| Project | CLAUDE.md or .claude/CLAUDE.md in the project folder |
Everyone on the project: commit it to Git |
| Local | CLAUDE.local.md in the project folder |
Only you, only this project: add it to .gitignore |
| User | ~/.claude/CLAUDE.md |
Only you, in every project |
| Managed policy | A system folder set up by an IT department | Everyone in an organization (not needed for this course) |
(~ is your home folder: /Users/maria on Maria’s Mac, /c/Users/sam in Sam’s Git Bash.) How the files load:
- They add up; they don’t replace each other. Claude Code joins all the files that apply. Your user file comes first, then the project files, so the instructions closest to your project are read last.
- Parent folders count. Start
claudeinclub-events/weband Claude Code loads the CLAUDE.md files inclub-events/weband inclub-events(and in any folder above it). - Subfolders load later. A CLAUDE.md inside a subfolder, such as
club-events/web/api/CLAUDE.md, loads only when Claude reads or edits a file in that subfolder. - Edits apply at the next fresh start. Claude Code reads your CLAUDE.md files once, when the session starts. If you edit one mid-session, the change takes effect after
/clear,/compact, or a restart.
50.3 Creating and editing CLAUDE.md
As of Oct 6, 2026 · Official docs: How Claude remembers your project · Commands
The easiest start is the /init command. In a Claude Code session inside your project folder, type:
/init
Claude looks through your project and writes a starter CLAUDE.md with the build commands, test instructions, and conventions it discovers. If a CLAUDE.md already exists, /init suggests improvements instead of overwriting it. Read what it wrote, delete what isn’t useful, and add what Claude couldn’t discover on its own.
| You want to… | Do this |
|---|---|
| Open (or create) a memory file in your editor | Run /memory and pick the file |
| Check which CLAUDE.md files actually loaded | Run /context and look under Memory files |
| Add a rule without leaving the chat | Ask: “add a rule to CLAUDE.md: run npm test before committing” |
| Turn a repeated mistake into a rule | Ask: “you keep forgetting X. Add a rule to CLAUDE.md so this stops happening” |
| Capture lessons at the end of a session | Ask: “summarize what we did this session and suggest what to add to CLAUDE.md” |
CLAUDE.md is plain text, so you can also edit it in any text editor (not a word processor).
50.4 What to put in CLAUDE.md (and what to leave out)
As of Oct 6, 2026 · Official docs: Best practices for Claude Code
Write down what you would otherwise re-explain every session. Good moments to add a line: Claude makes the same mistake twice, you type the same correction you typed last session, or a new teammate would need the same information.
| Include | Leave out |
|---|---|
Commands Claude can’t guess (npm run dev, npm test) |
Anything Claude can figure out by reading the code |
| Style rules that differ from the usual defaults | Standard conventions Claude already knows |
| How to run the tests, and which test tool you use | Long explanations or tutorials |
| Project decisions (“we use Supabase for login”) | Detailed API docs (link to them instead) |
| Gotchas (“the dev server runs on port 3001”) | Information that changes often |
| Team habits (branch names, commit message style) | Vague advice such as “write clean code” |
Three rules of thumb from the official guide:
- Keep it short. Aim for under 200 lines. Long files use more of the context window and Claude follows them less reliably. For each line ask: “Would removing this cause Claude to make mistakes?” If not, cut it.
- Be concrete enough to check. “Use 2-space indentation” beats “format code properly”; “Run
npm testbefore committing” beats “test your changes”. - Avoid contradictions. If two instructions conflict, even in two different CLAUDE.md files, Claude may pick either one.
If Claude keeps skipping one important rule, you can add emphasis such as “IMPORTANT” to that one line. If every line is important, none stands out.
50.5 Example: CLAUDE.md for a student web project
As of Oct 6, 2026 · Official docs: Best practices for Claude Code
Maria and Sam are building a small website where students sign up for club events. This CLAUDE.md sits in the project’s top folder and is committed to Git:
# Club Events
A website where students sign up for club events.
Built with Next.js (TypeScript) and Supabase.
## Commands
- Install packages: `npm install`
- Start the dev server: `npm run dev` (http://localhost:3000)
- Run the tests: `npm test`
- Check code style: `npm run lint`
## Project layout
- Pages live in `src/app/`, reusable components in `src/components/`
- Database changes go in `supabase/migrations/`
## Rules
- Use 2-space indentation and named exports
- Never put API keys in code; read them from `.env.local` (it is git-ignored)
- Run `npm test` and `npm run lint` before saying a task is done
## Working with us
- We are beginners: explain each change in plain English
- Make small commits with clear messagesNotice what is not there: no list of every file, no explanation of what React is, no copy of the Supabase documentation. Claude can read the code, and it already knows popular frameworks.
50.6 AGENTS.md and files from other tools
As of Oct 6, 2026 · Official docs: How Claude remembers your project
Other AI coding tools read a similar file named AGENTS.md. Claude Code (version 2.1.277 or later) reads it too:
- The project has
AGENTS.mdbut noCLAUDE.md: Claude readsAGENTS.md. - The project has both: by default Claude reads only
CLAUDE.md. To share one file between tools, put the line@AGENTS.mdat the top of your CLAUDE.md (an import, see the deeper dive below), or change the Project instructions option in/config.
If a project has rules from Cursor (.cursor/rules/ or .cursorrules) or GitHub Copilot (.github/copilot-instructions.md), /init reads them and carries the relevant parts into the new CLAUDE.md.
50.7 Auto memory: notes Claude writes for itself
As of Oct 6, 2026 · Official docs: How Claude remembers your project
Auto memory is on by default. As you work, Claude decides whether something is worth remembering for future sessions: your preferences (“Maria wants plain-English explanations”), corrections you gave it, or project facts it can’t get from the code (a deadline, where the issue tracker is). It skips anything it can read from the code or that your CLAUDE.md already says. You may see messages such as “Saved 2 memories” or “Recalled 2 memories”.
- Where: on your computer only, in
~/.claude/projects/<project>/memory/. Each project (Git repository) gets its own folder, holding an index file,MEMORY.md, plus one small Markdown file per topic. - What loads: the first 200 lines (or 25 KB) of
MEMORY.mdat the start of every session. Topic files are read only when needed. - How to look: run
/memoryand open the auto memory folder. The files are plain Markdown: you can read, edit, or delete them. - How to turn it off: use the toggle in
/memory(it saves"autoMemoryEnabled": falsein your user settings), or put that same line in one project’s settings file to turn it off only there (see The .claude Folders and Settings Files).
“Remember” and “CLAUDE.md” go to different places. If you say “remember that the API tests need a local database”, Claude saves it to auto memory: private to you and this computer. If you say “add this to CLAUDE.md”, it goes into the file your teammates get through Git.
50.8 When Claude ignores your CLAUDE.md
As of Oct 6, 2026 · Official docs: How Claude remembers your project · Debug your configuration
- Did it load? Run
/contextand look under Memory files. If it is missing, check the file’s name (CLAUDE.md) and which folder it is in. - Did you edit it mid-session? Run
/clearor restart Claude Code. - Is the rule vague, or contradicted elsewhere? Make it specific and remove the conflict.
- Is the file too long? Trim it. The
/doctorcommand can propose cuts of content Claude could work out from the code. - Must it happen every time, no exceptions? Then it doesn’t belong in CLAUDE.md: use a permission rule or a hook, which Claude Code enforces.
Imports. A line such as See @README.md for an overview pulls the whole README into context when the session starts. Paths are relative to the file that contains the import, and imports can nest up to four levels deep. Imports help you organize, but they don’t save context: imported files still load every session. To mention a path without importing it, wrap it in backticks.
Rules. Instead of one big file, a project can keep topic files in .claude/rules/, for example testing.md and api-design.md. A rule without special settings loads every session, like CLAUDE.md. A rule that starts with a paths: block loads only when Claude works on matching files:
---
paths:
- "src/api/**/*.ts"
---
- All API endpoints must validate their inputPersonal rules for every project can go in ~/.claude/rules/. For knowledge Claude needs only sometimes, a skill is often better, because it loads only when used (see Skills).
Comments for humans. HTML comments on their own lines (<!-- note for teammates -->) are removed before Claude sees the file, so they cost no context.
Compaction. When a long conversation is summarized (automatically, or with /compact), the project’s top-level CLAUDE.md and auto memory are reloaded from disk, so their instructions survive. Instructions you only typed in the chat may be lost; if you want them to last, put them in CLAUDE.md.
Practice Questions
Easy
Question 1 · Short answer
What is CLAUDE.md, and when does Claude Code read it?
Question 2 · Multiple choice
Which statement about auto memory is correct?
- You write it by hand, and it is committed to Git with your project.
- Claude writes it, and it is stored on your computer under
~/.claude/projects/. - It is stored on Anthropic’s servers and shared across all your devices.
- It is a section at the bottom of your project’s CLAUDE.md.
Question 3 · Matching
Match each location with who its instructions are for.
| Location | Who it’s for | |
|---|---|---|
1. CLAUDE.md in the project folder |
A. Only you, in every project | |
2. CLAUDE.local.md in the project folder |
B. Notes Claude writes for itself about this project | |
3. ~/.claude/CLAUDE.md |
C. Everyone working on the project (committed to Git) | |
4. ~/.claude/projects/<project>/memory/ |
D. Only you, only this project (git-ignored) |
Question 4 · True or false
If your CLAUDE.md says “Never delete files in the data/ folder”, Claude Code makes it impossible for Claude to delete those files.
Question 5 · Short answer
What does the /init command do? What happens if the project already has a CLAUDE.md?
Question 6 · Multiple choice
Which command shows you which CLAUDE.md files were actually loaded into the current session?
/init/context/clear/compact
Medium
Question 7 · Rewrite
Rewrite each vague CLAUDE.md instruction so it is concrete enough to check.
- “Format code properly.”
- “Test your changes.”
- “Keep files organized.”
Question 8 · Scenario
Where should each of these instructions go? Choose from: project CLAUDE.md, CLAUDE.local.md, ~/.claude/CLAUDE.md.
- “Our tests run with
npm test.” - “I like short answers with a summary at the end.” (true for all of Maria’s projects)
- “My personal test account for this project is maria-test@example.com.”
Question 9 · Predict
Maria starts claude in ~/code/club-events/web. These files exist:
~/.claude/CLAUDE.md~/code/club-events/CLAUDE.md~/code/club-events/web/CLAUDE.md~/code/club-events/web/api/CLAUDE.md~/code/other-project/CLAUDE.md
Which load when the session starts, which may load later, and which never load?
Question 10 · Find the bug
Sam’s CLAUDE.md contains these lines. Name three problems with them.
- Write good code.
- Use tabs for indentation.
- Use 4 spaces for indentation.
- React is a JavaScript library for building user interfaces. It was created
at Facebook in 2013 and uses a virtual DOM. Components are functions that...
(40 more lines explaining React)Question 11 · Scenario
Halfway through a session, Sam adds “Use pnpm, not npm” to the project’s CLAUDE.md and saves it. Claude keeps using npm. Why, and what should Sam do?
Question 12 · Short answer
What is the difference between saying “remember that our API tests need a local database” and “add to CLAUDE.md that our API tests need a local database”?
Question 13 · Multiple choice
A repository has an AGENTS.md file and a CLAUDE.md file in its top folder. With default settings, what does Claude Code read?
- Only
AGENTS.md - Only
CLAUDE.md - Both,
AGENTS.mdfirst - Neither, until you run
/init
Question 14 · Write the JSON
Maria wants auto memory turned off for one project only. Write the setting she should put in that project’s settings file.
Hard
Question 15 · Scenario
Sam’s CLAUDE.md says “Never read the .env file.” Late in a long session, Claude reads .env anyway while debugging. Explain why this can happen and what Sam should use instead.
Question 16 · True or false
Splitting a 500-line CLAUDE.md into five smaller files that it imports with @path lines reduces how much of the context window the instructions use.
Question 17 · Long answer
Your team’s CLAUDE.md has grown to 600 lines and Claude now ignores about half of it. Describe a plan to fix it.
Question 18 · Scenario
At the start of a long session, Maria typed “always explain your changes in plain English.” Three hours later, after the conversation was automatically compacted, Claude stops doing it. Explain what happened and how to make the instruction last.
Question 19 · Long answer
Write a short CLAUDE.md (about 10 to 15 lines) for this project: a Python Flask web app for a campus food pantry. Tests run with pytest. The app starts with flask run. Templates are in templates/. The team wants commit messages that start with a verb and wants Claude to never edit files in migrations/ without asking first.
Question 20 · Compare
For each item, choose the best home: CLAUDE.md, a path-scoped rule in .claude/rules/, or a skill. Explain briefly.
- “Run
npm testbefore committing.” - Twelve conventions that apply only to files in
src/api/. - A 60-line checklist you follow when publishing a new release (about once a month).
Challenge
Question 21 · Hands-on
In a practice project (for example the unzipped Git practice project), start Claude Code and run /init. Then:
- Read the generated CLAUDE.md and cut it down to the lines you think really matter.
- Add two concrete rules of your own.
- Run
/clear, then/context, and confirm the file is listed under Memory files. - Give Claude a small task that should trigger one of your rules and check whether it follows it.
Write down what you cut and why.