Skip to content
Academy ofAI Learning

~/academy $ claude learn claude-md-project-memory

CLAUDE.md: give your project a memory

Where CLAUDE.md files live, what to put in them, how @ imports work and why a short file beats a long one. 7 min

Watch it done: give a project its CLAUDE.md memory

>

Step 1 of 7

Let Claude write the first draft. You will spend most of your time afterwards deleting lines.

  1. Let Claude write the first draft. You will spend most of your time afterwards deleting lines. Type: /init. Claude looks at the codebase and creates a CLAUDE.md with the build commands, test instructions and conventions it finds. If a CLAUDE.md already exists, it suggests improvements instead of overwriting it.
  2. Trim it to what Claude cannot work out from the code, and aim for under 200 lines. The @docs/release.md line imports that file too. Create CLAUDE.md containing: # Commands - Install: npm install - Run one test file: npx vitest run path/to/file.test.ts - Typecheck: npx tsc --noEmit # Conventions - Dates are stored as ISO strings, never as Date objects - src/old-api/ is still live, but do not copy its patterns # Gotchas - Release steps: @docs/release.md
  3. Personal notes for this project go in CLAUDE.local.md, next to CLAUDE.md. It loads the same way but is only for you. Create CLAUDE.local.md containing: # My notes for this project - My dev server runs on http://localhost:3000 - Use the test user created by scripts/seed.ts
  4. Keep your personal file out of git. The team shares CLAUDE.md through version control, not your local notes. Type: add CLAUDE.local.md to .gitignore. Claude edits .gitignore. In Manual mode it shows the change and asks first.
  5. Check what actually loaded. This is the quickest way to confirm Claude can see your files. Type: /context all. Look at the list under Memory files. If a CLAUDE.md you expected is not there, Claude cannot see it.
  6. Open any memory file without hunting for it. Selecting one that does not exist yet creates it. Type: /memory. Claude Code lists your CLAUDE.md, CLAUDE.local.md and other memory locations. Select one to open it in your editor, or use the toggle to switch auto memory on or off.
  7. Say "remember that" for a note Claude keeps itself. Say "add this to CLAUDE.md" when you want a standing instruction you control. Type: remember that the API tests need a local Redis instance. Claude saves this to auto memory, its own notes for this project, not to CLAUDE.md.

Commands from the official Claude Code docs, checked 18 November 2026. Lines marked Note describe what happens and are not real output.

Step 1 of 6

$ Read

Two kinds of memory

Every Claude Code session starts with an empty conversation. Two things carry knowledge from one session to the next. CLAUDE.md files are plain Markdown notes that you write. Auto memory is notes Claude writes for itself when you correct it or tell it to remember something, kept in ~/.claude/projects/<project>/memory/.

Both are loaded at the start of every session. Both are context, not rules: Claude reads them and usually follows them, but nothing forces it. Anything that must never happen, such as reading a secrets file, belongs in a permission deny rule or a hook, which you will meet in the permission modes lesson.

A handy split: say "add this to CLAUDE.md" when you want a standing instruction you control, and "remember that..." when you are happy for Claude to keep its own note.

Lesson notes: CLAUDE.md: give your project a memory

Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You can write, check and trim a CLAUDE.md that makes every Claude Code session start informed.

  1. Step 1 of 6 · Read

    Two kinds of memory

    Every Claude Code session starts with an empty conversation. Two things carry knowledge from one session to the next. CLAUDE.md files are plain Markdown notes that you write. Auto memory is notes Claude writes for itself when you correct it or tell it to remember something, kept in ~/.claude/projects/<project>/memory/.

    Both are loaded at the start of every session. Both are context, not rules: Claude reads them and usually follows them, but nothing forces it. Anything that must never happen, such as reading a secrets file, belongs in a permission deny rule or a hook, which you will meet in the permission modes lesson.

    A handy split: say "add this to CLAUDE.md" when you want a standing instruction you control, and "remember that..." when you are happy for Claude to keep its own note.

  2. Step 2 of 6 · Read

    Where the files live

    Claude Code reads CLAUDE.md from the folder you start it in and every folder above it, then adds them all together. Files in subfolders load later, once Claude starts working with files in that subfolder.

    The project file is the one you will use most. Commit it to git so the whole team gets the same instructions. Put personal notes, such as your own test account or sandbox URL, in CLAUDE.local.md and add that file to .gitignore.

    Run /memory in a session to see these files listed, open one in your editor (it creates the file if it does not exist yet) and switch auto memory on or off.

    You, every project
    ~/.claude/CLAUDE.md
    The team, this project
    ./CLAUDE.md  or  ./.claude/CLAUDE.md
    You, this project only
    ./CLAUDE.local.md  (add it to .gitignore)
    Your organisation
    A managed file IT deploys, such as C:\Program Files\ClaudeCode\CLAUDE.md on Windows
  3. Step 3 of 6 · Read

    What to write, and how short to keep it

    Claude reads your code at the start of a task and finds the folder layout, frameworks and conventions on its own. So only write what it cannot find, or would waste time rediscovering: the exact test and build commands, places where the code is misleading, decisions made outside the repo, and anything you have had to correct twice.

    Aim for under 200 lines. Every line is read on every task, relevant or not, and long files are followed less reliably. /init writes a first draft from your codebase; your job afterwards is mostly deleting lines.

    To pull another file in, write @ and its path, for example @docs/git-workflow.md. Paths are relative to the CLAUDE.md doing the importing, and imports can chain up to four levels deep. Imports keep things tidy but do not save space, because the imported file loads too. Wrap a path in backticks if you want to mention it without importing it.

    A CLAUDE.md that earns its place
    # Commands
    - Install: pnpm install
    - Run one test file: pnpm vitest run path/to/file.test.ts
    - Typecheck: pnpm tsc --noEmit
    
    # Conventions
    - Use the helpers in src/lib/errors.ts, never throw raw strings
    - src/legacy/ is still live, but do not copy its patterns
    
    # Gotchas
    - Integration tests need DATABASE_URL set, see .env.example
    - Release steps: @docs/release.md
  4. Step 4 of 6 · Sort

    Does it belong in CLAUDE.md?

    Sort each line. Would you put it in the project CLAUDE.md, or leave it out (or put it somewhere better)?

    • Run one test file with: pnpm vitest run path/to/file.test.ts
    • A paragraph describing every folder under src/
    • Integration tests need DATABASE_URL set, see .env.example
    • Never read .env under any circumstances
    • We agreed in a meeting to use the error helpers in src/lib/errors.ts
    • Our 40 step release procedure
    Show the answers
    • Run one test file with: pnpm vitest run path/to/file.test.ts: Put it in CLAUDE.md. The exact command Claude needs to check its own work. This is the single most useful kind of line.
    • A paragraph describing every folder under src/: Leave it out. Claude reads the repo itself and finds the layout faster than you can describe it.
    • Integration tests need DATABASE_URL set, see .env.example: Put it in CLAUDE.md. A gotcha that would cost Claude a failed run to discover. Worth one line.
    • Never read .env under any circumstances: Leave it out. A rule with no exceptions should be enforced, not requested. Use a deny rule such as Read(./.env) in settings.
    • We agreed in a meeting to use the error helpers in src/lib/errors.ts: Put it in CLAUDE.md. A team decision that is not obvious from the code. Exactly what CLAUDE.md is for.
    • Our 40 step release procedure: Leave it out. Long procedures that only matter sometimes belong in a skill, which loads only when needed.
  5. Step 5 of 6 · Try it in the terminal

    Check what actually loaded

    You edited CLAUDE.md and want to confirm Claude Code can see it. Type the command that shows context usage, including the list of memory files, in full.

    Hint: The command is about context. Add the word all to see every memory file.

    Show the command
    $ /context all
    Context usage
    ...
    Memory files
      ~/.claude/CLAUDE.md
      ./CLAUDE.md
      ./CLAUDE.local.md
  6. Step 6 of 6 · Quiz

    Check your understanding

    Claude keeps ignoring one line in your CLAUDE.md. What is the best next step?

    • Rewrite the line in capitals with IMPORTANT in front.
    • Paste the line into every prompt from now on.
    • Check the file is short enough for the line not to get lost, and if the rule can never bend, move it into a deny rule or a hook.
    • Delete CLAUDE.md and run /init again.
    Show the answer

    Check the file is short enough for the line not to get lost, and if the rule can never bend, move it into a deny rule or a hook. Right. Long files dilute every line. Rules with zero exceptions should be enforced by Claude Code, not left to the model.