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.
Organize project memory and see what loaded
Intermediate · Lesson 2 of 8 · about 20 minutes · Needs: Turn a repeated workflow into a skill · Verified against Claude Code v2.1.308 (stable) on 2026-10-25
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 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 the Intermediate index 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):
- An import, a line such as
@docs/conventions.mdinCLAUDE.md, loads another file along with it. It organizes the file but saves no context. - A rule is a Markdown file in
.claude/rules/. Withpaths: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, writes or edits a matching file, including viewing one with a single-file shell read such as cat or head (Path-specific rules) |
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).
Worked example
In your repository, add an import to
CLAUDE.md. In the practice template, importpackage.json; in your own repository, a document your team keeps, such as@docs/architecture.md:- npm scripts: @package.jsonSave a rule for your test files as
.claude/rules/testing.md. Change the pattern to match where your tests live, and the instruction to name your project's test tools:--- paths: - "test/**/*.js" --- # Testing - Use `node:test` and `node:assert/strict`; no other test libraries.Save this load log to
.practice/i-2-hook.json. It is anInstructionsLoadedhook: each time aCLAUDE.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:{"hooks":{"InstructionsLoaded":[{"hooks":[{ "type":"command","command":"jq -r '[.load_reason,.file_path]|@tsv' >> \"$CLAUDE_PROJECT_DIR/.practice/i-2-loaded.txt\"" }]}]}}End your current Claude session. Start a session with the log,
claude --settings .practice/i-2-hook.json(CLI reference), and run/context all: plain/contextcan collapse its list, andallexpands it (Commands). Under Memory files it lists the instruction files that loaded at the start, such asCLAUDE.md(Set up a project CLAUDE.md). The scoped rule isn't among them: nothing has read a test file yet. The log also has anincludeline for your imported file.Ask Claude to read a test file your rule covers. Replace the example's file with one of yours:
Read test/config.test.js, then tell me in one sentence what it checks.In a terminal in your repository,
cat .practice/i-2-loaded.txtshows every load with its reason:session_startforCLAUDE.md,includeforpackage.json, and nowpath_glob_matchfor the rule. The hook runs asynchronously, so if a line has not appeared yet, wait briefly and read the log again.
Your turn
A teammate's rule never takes effect. Find out why, and fix it.
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:--- paths: - "source/**/*.js" --- # CLI output - Print errors to stderr, starting with `linkcheck:`.End the example's session. Start a logged session,
claude --settings .practice/i-2-hook.json. Ask Claude to readsrc/cli.js, or a file in your folder:Read src/cli.js, then tell me in one sentence what it does.In a terminal in your repository, read
.practice/i-2-loaded.txt. The log appends to earlier attempts: inspect the lines added by this session. Compare its pattern with the files that exist,git ls-files src. Use your own source folder in place ofsrc. Decide whether to change the pattern, the instruction, or the way the file was read. Use the load log and the actual paths as your evidence.Fix the mismatch you found. End the session, start a new logged session and repeat step 2. The log now has a
path_glob_matchline forcli.md.Before you commit, decide where three instructions belong: a command every session needs, a convention for test files only, and a multi-step release procedure. The first goes in
CLAUDE.md, the second in a scoped rule, the third in a skill: keepCLAUDE.mdto facts Claude should hold in every session (When to add to CLAUDE.md). Then commitCLAUDE.mdand.claude/rules/. Delete.practice/i-2-hook.jsonwhen you no longer need the log.
Check
You are done when all of these are true:
- The committed
CLAUDE.mdimports 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. - The log shows the import and a scoped rule loading:
grep -E '^(include|path_glob_match)' .practice/i-2-loaded.txtprints 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 check that the pattern, read from the project root, matches the file Claude read.
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). - Claude Code reads the project's
CLAUDE.mdonce, at the start. An edit to it reaches the session after/clear,/compactor a restart (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). It proposes edits and changes nothing until you ask.
Go further
- Explore the .claude directory: the files you write in
.claude/and~/.claude, and when Claude Code loads each one. - Debug your configuration: what to check when a setting, hook or server doesn't take effect.
- Auto memory: what Claude saves for itself, where, and how to turn it off.
Sources: How Claude remembers your project · Hooks reference · Debug your configuration · How Claude Code uses prompt caching · CLI reference · Commands
← Turn a repeated workflow into a skill · Intermediate index · Pick the model and effort → · Topic: Memory and context · Stuck on this lesson?