Skip to content
zero2vibecodelearn vibe coding
Level 5 · Memory and the team 9 min Reviewed by the author · Oct 22, 2026 Verified against Claude Code v2.1.306 · Oct 22, 2026Official docs: CLAUDE.md memorySomething out of date? Tell us

Project memory, done properly

A long CLAUDE.md loads in full into every session. An @path import splits it into files, and a rule in .claude/rules with a paths field loads only when Claude reads a matching file. /context all and the InstructionsLoaded hook show what actually loaded.

Level 5 · 0 / 4 lessons0%
In this lesson

You already know how to write a . But in a big project it grows fast: commands, conventions, rules for the API, for tests, for markup. And every line loads into every session — even when you are editing the README.

Two tools help you keep it in order: imports and rules.

Imports: @path

A line with @ and a path loads another file along with CLAUDE.md:

# The linkcheck project

@AGENTS.md

- npm commands: @package.json
- Architecture: @docs/architecture.md

An import organises memory, but it does not save context: the imported file always loads, together with the file that imports it.

Two small things that trip people up:

  • the path runs up to the first space — do not put a full stop right after it;
  • the path is relative to the file that contains the import, not to the folder where you started Claude.

Importing a file outside the working folder, such as @~/notes.md, asks for your approval the first time it is used in a project. Decline, and it stays off.

AGENTS.md and CLAUDE.md

Many projects already keep an for other agents. Claude Code reads it on its own — but only while there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your folder or above it. As soon as one of those exists, Claude reads the CLAUDE.md files instead, and AGENTS.md is skipped.

So the day you add a CLAUDE.md for Claude-specific notes, make @AGENTS.md its first line, and the shared rules stay in one place. The other way is /config → Project instructions → claude-md-and-agents-md, which reads both. Note that a personal CLAUDE.local.md counts too: creating one in a project that relies on AGENTS.md switches AGENTS.md off for you.

Rules: .claude/rules

A rule is a Markdown file in the .claude/rules/ folder. Without a paths header, it loads at startup, like an ordinary CLAUDE.md. With the header — only when Claude works with a matching file:

---
paths:
  - "test/**/*.js"
---

# Tests

- Use node:test and node:assert/strict; do not add other libraries.

Patterns are relative to the project root. * does not cross a folder boundary, **/ goes through any number of folders, and braces such as src/**/*.{ts,tsx} work too.

The main subtlety: a rule with paths applies when Claude reads, writes or edits a matching file — with the Read, Write or Edit tool, or with a plain cat, head or tail on that one file in the shell. A command that only lists files, pipes the file into something else or reads several at once does not count. So when you check, ask exactly that: “read test/config.test.js”.

What loads, and when

Instruction fileWhen it loads
CLAUDE.md at the root, and a rule without pathsat session start
AGENTS.md, when there is no CLAUDE.mdat session start
a file pulled in by an @path importalong with the file that imports it
a rule with pathswhen Claude reads, writes or edits a matching file
auto memory — notes Claude keeps itselfat startup: the first 200 lines or 25 KB of the MEMORY.md index

For personal instructions for this project there is CLAUDE.local.md. You create it by hand and do not commit it — that is exactly what the lesson on a shared team kit is about.

Why Claude does not listen

First find out whether the file loaded. Only if it did, work on the wording: make it specific and remove rules that contradict it.

The first way is /context all. Plain /context can collapse the list; all expands it. The Memory files section shows the files loaded at startup. Rules with paths appear there only after a matching file is read.

The second way is the InstructionsLoaded hook. It fires every time a CLAUDE.md, a rule or an import loads. Put it in a separate file, for example .practice/loaded-hook.json:

{
  "hooks": {
    "InstructionsLoaded": [
      { "hooks": [ { "type": "command", "command": "jq -r '[.load_reason, .file_path] | @tsv' >> \"$CLAUDE_PROJECT_DIR/.practice/loaded.txt\"" } ] }
    ]
  }
}

And start a session with it: claude --settings .practice/loaded-hook.json. One gap: the hook does not fire for an AGENTS.md that Claude reads directly, only for one that a CLAUDE.md imports. Every line in the log has a reason:

  • session_start — loaded at startup, like CLAUDE.md;
  • include — pulled in by an import;
  • path_glob_match — a rule applied through its pattern.

If there is no path_glob_match line for your rule, compare the pattern with the real files. Git helps:

git ls-files ':(glob)src/api/**/*.js'

Empty output means the pattern matches no file. The classic: a rule for source/** in a project where the code lives in src/.

Editing mid-session

Claude Code reads the project’s CLAUDE.md once, at startup. Edit the file, and the change reaches the session after /clear, /compact or a restart.

And to find instructions that contradict each other or point to deleted files, run /doctor prompt-audit. It suggests edits and changes nothing until you ask.

Quick check

/context all does not show the .claude/rules/api.md rule. So far Claude has only searched the folder with grep -r. What do you do?

Careful

Practice in the terminal

Check your CLAUDE.md

Paste the file and notes appear right away. The text never leaves your browser.

  • Important: Almost empty

    Start with the essentials: how to build the project, how to run the tests, what not to touch. /init drafts it for you.

Full review with AI →

Check your understanding

Answered 0/3
Mode:

A rule in .claude/rules/testing.md with a paths field for test/**/*.js did not apply. So far Claude has only run ls test and npm test. Why?

The project has both CLAUDE.md and AGENTS.md. What does Claude Code read?

You edited CLAUDE.md in the middle of a session. When does Claude see the change?

Finish the task in the terminal and answer the questions to complete the lesson.

📝 My notes

Saved automatically in this browser · shows up on the Notes page.

Task

The project keeps its rules in AGENTS.md, which Claude Code reads on its own while there is no CLAUDE.md. You need a CLAUDE.md for Claude-only notes, and the moment it exists AGENTS.md stops loading, so create a CLAUDE.md that imports AGENTS.md. Then, of the two drafts in the drafts folder, pick the rule whose pattern matches the real files (look at ls src) and put it in .claude/rules/api.md.

Tab complete · ↑ history · Ctrl+L clear · help commands

  • Not done: CLAUDE.md imports AGENTS.md
  • Not done: A rule with a paths field is in .claude/rules
  • Not done: The rule's pattern matches the real code folder

Lesson Q&A

A rule in .claude/rules/testing.md with a paths field for test/**/*.js did not apply. So far Claude has only run ls test and npm test. Why?

A rule with paths loads when Claude reads, writes or edits a matching file; listing a folder or running the tests reads no file — A rule with paths waits until Claude touches a matching file: the Read, Write or Edit tool, or a plain single-file cat or head in the shell. ls, a pipe or a test run does not count. Ask Claude to read one of the test files.

The project has both CLAUDE.md and AGENTS.md. What does Claude Code read?

Only CLAUDE.md — for AGENTS.md to load too, import it with the line @AGENTS.md — Claude reads AGENTS.md on its own only when there is no CLAUDE.md. With one present, an @AGENTS.md line at the top of CLAUDE.md pulls in the second file, or set Project instructions in /config to claude-md-and-agents-md.

You edited CLAUDE.md in the middle of a session. When does Claude see the change?

After /clear, /compact or a restart — CLAUDE.md is read at startup — Claude Code reads the project's CLAUDE.md once, at startup. The new version reaches the session after /clear, /compact or a fresh start.

/context all does not show the .claude/rules/api.md rule. So far Claude has only searched the folder with grep -r. What do you do?

A search across a folder reads no single file, so the rule has not had a chance to load. Once a matching file is read and it is still missing, the pattern does not match the files — check it with git ls-files.

Commands in this lesson

Terms in this lesson

Move between lessons with ← → · search with ⌘K

Written and reviewed by Mikhail Kuzmitskii