Skip to content

Claude Code guide in three levels, Beginner to Advanced: hands-on lessons with checked exercises, every volatile fact cited to its source. Independent community guide.

docs: add the Intermediate lesson on organizing project memory and seeing what loaded (#82)

Wesam Abousaidf496a47b36d9
diff --git a/README.md b/README.md
index 59361bd..142abe5 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ macOS, Linux and WSL. For Windows and other installers, see the [official setup
**Beginner Electives:** [IDE extensions](docs/beginner/electives/ide-extensions.md) · [Screenshots and images](docs/beginner/electives/screenshots-and-images.md) · [The built-in teachers](docs/beginner/electives/built-in-teachers.md)
-**Intermediate** (being rebuilt): [Level index](docs/intermediate/README.md) · [Turn a repeated workflow into a skill](docs/intermediate/01-first-skill.md)
+**Intermediate** (being rebuilt): [Level index](docs/intermediate/README.md) · [Turn a repeated workflow into a skill](docs/intermediate/01-first-skill.md) · [Organize project memory and see what loaded](docs/intermediate/02-organize-memory.md)
**Advanced** (being rebuilt): [Level index](docs/advanced/README.md)
diff --git a/docs/intermediate/01-first-skill.md b/docs/intermediate/01-first-skill.md
index ff0d741..42042ab 100644
--- a/docs/intermediate/01-first-skill.md
+++ b/docs/intermediate/01-first-skill.md
@@ -132,4 +132,4 @@ If the skill isn't committed, run `git check-ignore -v .claude/skills/tdd/SKILL.
<sub>Sources: [Extend Claude with skills](https://code.claude.com/docs/en/skills) · [Advanced setup](https://code.claude.com/docs/en/setup) · [Commands](https://code.claude.com/docs/en/commands) · [Tools reference](https://code.claude.com/docs/en/tools-reference) · [Interactive mode](https://code.claude.com/docs/en/interactive-mode) · [Checkpointing](https://code.claude.com/docs/en/checkpointing)</sub>
-<sub>← [Intermediate index](README.md) · Topic: [Skills](../topics/skills.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=i-1)</sub>
+<sub>← [Intermediate index](README.md) · [Organize project memory and see what loaded](02-organize-memory.md) → · Topic: [Skills](../topics/skills.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=i-1)</sub>
diff --git a/docs/intermediate/02-organize-memory.md b/docs/intermediate/02-organize-memory.md
new file mode 100644
index 0000000..21edcd9
--- /dev/null
+++ b/docs/intermediate/02-organize-memory.md
@@ -0,0 +1,125 @@
+# Organize project memory and see what loaded
+
+<sub>**Intermediate** · Lesson 2 of 8 · about 20 minutes · Needs: [Turn a repeated workflow into a skill](01-first-skill.md) · Verified against Claude Code v2.1.285 (stable) on 2026-10-06</sub>
+
+## Goal
+
+By the end of this lesson you can split a project's instructions into imports and scoped rules, and find out which instruction files loaded when Claude doesn't follow one.
+
+## You need
+
+- One of your own repositories with a committed `CLAUDE.md`, as [Beginner lesson 5](../beginner/05-project-memory.md) leaves it, and your copy of the practice template with Node.js LTS: the check runs from the copy. To practice in the template copy instead, use it for both. Set up the repository's `.practice/` folder as [Beginner lesson 1](../beginner/01-install-and-look-around.md#you-need) describes, if you haven't yet.
+- `jq`, for the load log in the Worked example.
+- Usage: light.
+
+## The idea
+
+A long `CLAUDE.md` is hard to maintain, and every line of it loads into every session. Two tools split it up ([How Claude remembers your project](https://code.claude.com/docs/en/memory)):
+
+- An **import**, a line such as `@docs/conventions.md` in `CLAUDE.md`, loads another file along with it. It organizes the file but saves no context.
+- A **rule** is a Markdown file in `.claude/rules/`. With `paths:` frontmatter it loads only when Claude works on a matching file.
+
+| Instruction file | Loads |
+|---|---|
+| `CLAUDE.md` at the project root, and a rule without `paths:` | When the session starts |
+| A file named in an `@path` import | With the file that imports it |
+| A rule with `paths:` | When Claude reads a matching file with its Read tool |
+| Auto memory, the notes Claude keeps for itself | When the session starts: the first 200 lines or 25KB of its `MEMORY.md` index |
+
+When Claude ignores an instruction, first find out whether its file loaded. If it did, the wording is the likely problem: make it concrete, and remove any instruction that contradicts it ([Debug your configuration](https://code.claude.com/docs/en/debug-your-config#see-what-loaded-into-context)).
+
+## Worked example
+
+1. In your repository, add an import to `CLAUDE.md`. In the practice template, import `package.json`; in your own repository, a document your team keeps, such as `@docs/architecture.md`:
+
+ ```markdown
+ - npm scripts: @package.json
+ ```
+
+ An import's path runs until the first space, so don't put a period right after it.
+2. Save a rule for your test files as `.claude/rules/testing.md`. Change the pattern to match where your tests live:
+
+ ```markdown
+ ---
+ paths:
+ - "test/**/*.js"
+ ---
+
+ # Testing
+
+ - Use `node:test` and `node:assert/strict`; no other test libraries.
+ ```
+
+3. Save this load log to `.practice/i-2-hook.json`. It is an [`InstructionsLoaded` hook](https://code.claude.com/docs/en/hooks#instructionsloaded): each time a `CLAUDE.md`, a rule or an imported file loads, it appends the reason and the file's path to `.practice/i-2-loaded.txt`. It logs nothing else, and runs only in sessions you start with it:
+
+ ```json
+ {
+ "hooks": {
+ "InstructionsLoaded": [
+ { "hooks": [ { "type": "command", "command": "jq -r '[.load_reason, .file_path] | @tsv' >> \"$CLAUDE_PROJECT_DIR/.practice/i-2-loaded.txt\"" } ] }
+ ]
+ }
+ }
+ ```
+
+4. Start a session with the log, `claude --settings .practice/i-2-hook.json` ([CLI reference](https://code.claude.com/docs/en/cli-reference#cli-flags)), and run `/context all`: plain `/context` can collapse its list, and `all` expands it ([Commands](https://code.claude.com/docs/en/commands)). Under **Memory files** it lists the instruction files that loaded at the start, such as `CLAUDE.md` ([Set up a project CLAUDE.md](https://code.claude.com/docs/en/memory#set-up-a-project-claude-md)). The scoped rule isn't among them: nothing has read a test file yet.
+5. Ask Claude to read a test file with its Read tool. Name the tool: Claude sometimes reads a file through a shell command, which doesn't load scoped rules.
+
+ ```text
+ Use your Read tool to read test/config.test.js, then tell me in one sentence what it checks.
+ ```
+
+ In a second terminal, `cat .practice/i-2-loaded.txt` shows every load with its reason: `session_start` for `CLAUDE.md`, `include` for `package.json`, and now `path_glob_match` for the rule.
+
+## Your turn
+
+A teammate's rule never takes effect. Find out why, and fix it.
+
+1. Save this rule as `.claude/rules/cli.md`. In your own repository, write a rule for one of your source folders and misspell the folder's name in its pattern:
+
+ ```markdown
+ ---
+ paths:
+ - "source/**/*.js"
+ ---
+
+ # CLI output
+
+ - Print errors to stderr, starting with `linkcheck:`.
+ ```
+
+2. Start a logged session, `claude --settings .practice/i-2-hook.json`, and ask Claude to use its Read tool on `src/cli.js`, or on a file in your folder.
+3. Read the log: the rule never loaded. Compare its pattern with the files that exist, `git ls-files src`.
+4. Fix the pattern, start a new logged session and repeat step 2. The log now has a `path_glob_match` line for `cli.md`.
+5. Commit `CLAUDE.md` and `.claude/rules/`. Delete `.practice/i-2-hook.json` when you no longer need the log.
+
+## Check
+
+You are done when all of these are true:
+
+- [ ] The committed `CLAUDE.md` imports a file that exists: `git show HEAD:CLAUDE.md | grep '@'` shows the import.
+- [ ] Every committed rule with `paths:` matches a file: for each pattern, `git ls-files ':(glob)<pattern>'` lists at least one file. With the `:(glob)` prefix, git's `*` stays inside one folder and `**/` matches any number of folders, as in rules ([gitglossary: pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec)). Git doesn't expand braces, which rules do ([Path-specific rules](https://code.claude.com/docs/en/memory#path-specific-rules)), so check a pattern such as `src/**/*.{ts,tsx}` one extension at a time.
+- [ ] The log shows the import and a scoped rule loading: `grep -E '^(include|path_glob_match)' .practice/i-2-loaded.txt` prints at least one line of each kind.
+- [ ] Self-check (not tested): you can say which of your instruction files load at the start and which load later, and how you saw each one load.
+
+Run `npm run check -- i-2 --dir <your repo>` from your practice copy, or `npm run check -- i-2` in the copy itself.
+
+If the import check fails, look for punctuation right after the path, or a path written relative to the wrong folder: an import resolves from the file that holds it. If a rule matches no file, its pattern is relative to the project root, so `source/**` matches nothing in a project whose code is in `src/`. If the log has no `path_glob_match` line, start the session with `--settings .practice/i-2-hook.json` and ask for the Read tool by name.
+
+## Watch out
+
+- An import that points outside your working directory, such as `@~/notes.md`, asks for your approval the first time a project uses it; if you decline, it stays off ([Import additional files](https://code.claude.com/docs/en/memory#import-additional-files)).
+- Claude Code reads the project's `CLAUDE.md` once, at the start. An edit to it reaches the session after `/clear`, `/compact` or a restart ([Editing CLAUDE.md mid-session](https://code.claude.com/docs/en/prompt-caching#editing-claude-md-mid-session)).
+- To find instructions that contradict each other or name files that no longer exist, run `/doctor prompt-audit` ([Audit your instruction files](https://code.claude.com/docs/en/memory#audit-your-instruction-files)). It proposes edits and changes nothing until you ask.
+
+## Go further
+
+- [Explore the .claude directory](https://code.claude.com/docs/en/claude-directory): the files you write in `.claude/` and `~/.claude`, and when Claude Code loads each one.
+- [Debug your configuration](https://code.claude.com/docs/en/debug-your-config): what to check when a setting, hook or server doesn't take effect.
+- [Auto memory](https://code.claude.com/docs/en/memory#auto-memory): what Claude saves for itself, where, and how to turn it off.
+
+---
+
+<sub>Sources: [How Claude remembers your project](https://code.claude.com/docs/en/memory) · [Hooks reference](https://code.claude.com/docs/en/hooks) · [Debug your configuration](https://code.claude.com/docs/en/debug-your-config) · [How Claude Code uses prompt caching](https://code.claude.com/docs/en/prompt-caching) · [CLI reference](https://code.claude.com/docs/en/cli-reference) · [Commands](https://code.claude.com/docs/en/commands) · [gitglossary](https://git-scm.com/docs/gitglossary)</sub>
+
+<sub>← [Turn a repeated workflow into a skill](01-first-skill.md) · [Intermediate index](README.md) · Topic: [Memory and context](../topics/memory-and-context.md) · [Stuck on this lesson?](https://github.com/wesammustafa/Claude-Code-Everything-You-Need-to-Know/issues/new?template=lesson-feedback.yml&lesson=i-2)</sub>
diff --git a/docs/intermediate/README.md b/docs/intermediate/README.md
index 09c11c8..9a1a204 100644
--- a/docs/intermediate/README.md
+++ b/docs/intermediate/README.md
@@ -39,7 +39,7 @@ They combine: a [plugin](https://code.claude.com/docs/en/plugins) packages skill
## Lessons
1. [Turn a repeated workflow into a skill](01-first-skill.md)
-2. Organize project memory and see what loaded
+2. [Organize project memory and see what loaded](02-organize-memory.md)
3. Pick the model and effort
4. Permissions, settings scopes and the sandbox
5. Enforce a rule with a hook
diff --git a/docs/reference/commands.md b/docs/reference/commands.md
index b7f4fe9..92a44d7 100644
--- a/docs/reference/commands.md
+++ b/docs/reference/commands.md
@@ -25,7 +25,7 @@ Electives: `/powerup` and `/output-style` ([the built-in teachers](../beginner/e
## Intermediate
- `/skills`: list the skills available in this session. [Turn a repeated workflow into a skill](../intermediate/01-first-skill.md)
-- `/doctor`: check your setup; `/doctor prompt-audit` checks your instruction files. *Organize project memory and see what loaded*
+- `/doctor`: check your setup; `/doctor prompt-audit` checks your instruction files. [Organize project memory and see what loaded](../intermediate/02-organize-memory.md)
- `/model`: switch the model and save it as your default; for models that support it, the left and right arrow keys adjust effort. *Pick the model and effort*
- `/effort`: set the effort level. *Pick the model and effort*
- `/permissions`: manage allow, ask and deny rules. *Permissions, settings scopes and the sandbox*
diff --git a/docs/reference/feature-map.md b/docs/reference/feature-map.md
index e944fde..a4a8112 100644
--- a/docs/reference/feature-map.md
+++ b/docs/reference/feature-map.md
@@ -35,7 +35,7 @@ How to read it:
| [Plan mode](https://code.claude.com/docs/en/permission-modes); taught in [Permission modes and plan mode](../beginner/02-permission-modes-and-plan-mode.md) | – | Every provider |
| [Auto mode](https://code.claude.com/docs/en/permission-modes); taught in [Permission modes and plan mode](../beginner/02-permission-modes-and-plan-mode.md) | – | A Claude subscription, the Console and Claude Platform on AWS; on Bedrock, Agent Platform and Foundry with newer models only. Team and Enterprise admins can turn it off |
| [Checkpointing and rewind](https://code.claude.com/docs/en/checkpointing); taught in [Keep a session on track](../beginner/04-keep-a-session-on-track.md) | – | Every provider |
-| [CLAUDE.md memory](https://code.claude.com/docs/en/memory); taught in [Project memory with CLAUDE.md](../beginner/05-project-memory.md) | – | Every provider |
+| [CLAUDE.md memory](https://code.claude.com/docs/en/memory); taught in [Project memory with CLAUDE.md](../beginner/05-project-memory.md) and [Organize project memory and see what loaded](../intermediate/02-organize-memory.md) | – | Every provider |
| [Sandbox](https://code.claude.com/docs/en/sandboxing) | – | Every provider |
| [Output styles](https://code.claude.com/docs/en/output-styles); taught in [the built-in teachers](../beginner/electives/built-in-teachers.md) | – | Every provider |
| [Status line](https://code.claude.com/docs/en/statusline) | – | Every provider |
diff --git a/docs/topics/memory-and-context.md b/docs/topics/memory-and-context.md
index afdafce..ea2eeb4 100644
--- a/docs/topics/memory-and-context.md
+++ b/docs/topics/memory-and-context.md
@@ -9,6 +9,7 @@ What Claude Code knows at the start of a session and what fills its context as y
- Beginner: [Keep a session on track](../beginner/04-keep-a-session-on-track.md)
- Beginner: [Project memory with CLAUDE.md](../beginner/05-project-memory.md)
- Beginner Electives: [IDE extensions](../beginner/electives/ide-extensions.md), [Screenshots and images](../beginner/electives/screenshots-and-images.md), [The built-in teachers](../beginner/electives/built-in-teachers.md)
+- Intermediate: [Organize project memory and see what loaded](../intermediate/02-organize-memory.md)
Later lessons on this topic are linked here in level order, with its Electives, as they are published.