GrepBoard/Manuals
605 manuals ·

Check why Claude Code is not following your CLAUDE.md

·Tested on Claude Code 2.1.302 · Ubuntu 24.04 · 2026-10·Test scope ↓·8 steps

When CLAUDE.md rules seem ignored, check that the file loaded first. Then test lazy loading of subdirectory files and claudeMdExcludes with claude -p.

You wrote a rule and Claude Code ignores it. Split the problem in two: did the file load, and is the instruction written so it can be followed?

[1] Run /context in the session and look for the CLAUDE.md under Memory files. If it is not listed, Claude cannot see it. /memory opens the same locations for editing.

[2] Check where you started. Per the docs, Claude Code loads CLAUDE.md from the launch directory and every directory above it, concatenated from the filesystem root down to the launch directory. Try it in a scratch folder. The values are test data.

console
$ cd /srv/app$ cat CLAUDE.md sub/CLAUDE.md# Project rules - End every reply with the line `ROOT-RULE-OK`.# Sub rules - When you mention this folder, add the line `SUB-RULE-OK`.

Launch from /srv/app and ask for the rules without tools. -p runs one prompt and exits.

console
$ claude -p 'List the project instruction lines you were given, verbatim, one per line. If none, say NONE. Do not use tools.'- End every reply with the line `ROOT-RULE-OK`. ROOT-RULE-OK

Only the root rule appears. The rule in sub/CLAUDE.md is missing.

[3] Subdirectory rules attach after Claude touches a file in that folder. The docs say a subdirectory CLAUDE.md loads once Claude reads, writes, or edits another file there.

console
$ claude -p 'Read sub/notes.txt. Then list every project instruction line you were given, verbatim, one per line.'`sub/notes.txt` contains one line: `hello`. Here is every project instruction line I was given, verbatim: - End every reply with the line `ROOT-RULE-OK`.- When you mention this folder, add the line `SUB-RULE-OK`.…

Both lines appear now. If a subdirectory rule seems dead, the session may never have read a file in that folder. When testing a new one, create the CLAUDE.md from your shell instead of asking Claude to write it, then have Claude read a file there. The docs recommend the same.

[4] Start in the subdirectory and the parent's rules arrive at launch.

console
$ cd /srv/app/sub$ claude -p 'List the project instruction lines you were given, verbatim, one per line. If none, say NONE. Do not use tools.'- End every reply with the line `ROOT-RULE-OK`.- When you mention this folder, add the line `SUB-RULE-OK`.…

Files below the launch directory load on read; files above it load at launch. In a monorepo, check which directory you ran claude from first.

[5] Exclude rules you do not want with claudeMdExcludes. It takes globs matched against absolute paths, works in user, project, local, or managed settings, and arrays merge across layers.

.claude/settings.local.json
{"claudeMdExcludes": [  "**/monorepo/CLAUDE.md"]}

To test it once, pass the setting with --settings. Excluding the project CLAUDE.md and asking the same question gave:

console
$ claude -p 'List the project instruction lines you were given, verbatim, one per line. If none, say NONE. Do not use tools.' --settings '{"claudeMdExcludes":["**/app/CLAUDE.md"]}'NONE

[6] If the file loaded and Claude still breaks the rule, look at the instruction. The causes the docs list:

CauseFix
A sentence open to several readingsBe specific: "Use 2-space indentation"
Two files give different instructionsDelete the conflicting one
A file over 200 linesMove partial-scope rules to .claude/rules/
Commit or PR rules overlap built-in guidanceTurn the built-in off with includeGitInstructions
Explore and Plan subagentsThey skip CLAUDE.md at startup — repeat the rule in the delegating prompt

CLAUDE.md is delivered as a user message after the system prompt, not as part of it, and the docs say strict compliance is not guaranteed.

[7] Move anything that must always hold out of CLAUDE.md. A hook runs at a fixed point such as before a commit or after an edit; a permission rule blocks. See Block dangerous commands with Claude Code hooks and Block .env reads with deny rules in Claude Code.

[8] To log which file loaded and when, use an InstructionsLoaded hook; the docs point to it for debugging lazy-loaded files. To compare against a bare setup, start with claude --safe-mode, which turns off user customizations including CLAUDE.md, and see whether the symptom persists.

#claude-code#claude-md#memory#debugging