Sign in
Blog

Claude Code Ignores CLAUDE.md? Find the Cause and Fix It

18 min read

Cover: Ignores CLAUDE.md? A cable arcs over a dark CLAUDE.md card instead of passing through it, then ends at a check

TL;DR

  • Two problems look the same. When Claude Code ignores CLAUDE.md, the file either never loaded or loaded and was not followed. /context all shows which.
  • CLAUDE.md is context, not configuration. Anthropic's docs say so. A rule that must never break belongs in a PreToolUse hook or a deny rule.
  • Some files skip loading by design. A subfolder CLAUDE.md waits until Claude touches that folder, AGENTS.md is skipped when a CLAUDE.md exists in your folder or above, and the Explore and Plan subagents start without your CLAUDE.md.
  • The size target is 200 lines per file. That is Anthropic's documented number. The "80 lines" limit you may have read comes from one DEV post, not from the docs.

Why does Claude Code ignore your CLAUDE.md?

Claude Code reads CLAUDE.md at the start of a session and treats it as context. The memory page is direct about it: Claude treats these files "as context, not enforced configuration." The text arrives as a user message after the system prompt. There is no guarantee of strict compliance, "especially for vague or conflicting instructions."

"Ignored" therefore covers two failures with different fixes.

  • Not loaded. Claude never saw the text. No rewording can help.
  • Loaded, not followed. Claude saw it and did not act on it. Adherence drops when a rule is vague, conflicts with another file, or sits in a file long enough that each rule gets less attention.

Anthropic's debug page lists the suspects in that order: the file didn't load, it loaded from a different location than you expected, or another file overrode it. Check in the same order. The picture is the whole post in four questions.

Decision tree: is the file in /context all, is the rule short and clear, does it fail only late, must it never happen
Decision tree: is the file in /context all, is the rule short and clear, does it fail only late, must it never happen

Each answer ends in a different fix. None of them is to word the rule louder.

Users have filed reports about it since 2025. A 2025 report about ignored CLAUDE.md rules was locked in January 2026, and #17530 describes a 400-line file ignored in about half of one user's sessions, even with "MUST" and "HARD RULE" in the text. Those figures come from one person's sessions, so read them as reports. One DEV post says Claude starts ignoring content "after around 80 lines" and calls it a fundamental limitation of LLMs, without naming a study or a measurement. The docs give a different number, and we will get to it.

How do you check that CLAUDE.md actually loaded?

Start a fresh session in the folder where the failure happened and run /context all. Read the Memory files list. In fullscreen mode plain /context collapses that list, which is why the docs say all. If a file that should load at launch is not listed, Claude cannot see it. /memory lists your memory files and opens any of them in your editor.

Two quick checks before you read a single rule.

  • Your version. claude --version printed 2.1.319 (Claude Code) on our server on 15 November 2026. Many loading fixes are recent, so an older thread may describe behavior that has changed. The table below dates the ones that matter.
  • Safe mode. claude --safe-mode starts with CLAUDE.md, skills, plugins, hooks and MCP servers switched off. If the problem disappears in safe mode, you have narrowed the cause to one of the customizations it turned off.

Then look for the silent failures. Every row below is documented behavior, not a bug.

What you seeWhyFix
A subfolder CLAUDE.md has no effectIt loads once Claude reads, writes or edits a file in that folder, so it is not under Memory files at launch. A Loaded line appears when it arrives.Expected: it loads when Claude touches that folder. To test it, create the file from your shell, then ask Claude to read a file there
AGENTS.md is ignoredBy default it is read only when no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md exists in your folder or above. It needs v2.1.277 or later.Make @AGENTS.md the first line of your CLAUDE.md, or change Project instructions in /config
CLAUDE.md says "read AGENTS.md" in wordsClaude sees AGENTS.md only if it decides to open the fileReplace the sentence with an @AGENTS.md import
A subagent breaks a ruleExplore and Plan start without your CLAUDE.mdRestate the rule in the prompt you give when delegating
A headless job ignores it--bare skips CLAUDE.md files, as our headless post coversDrop --bare, or pass the text with --append-system-prompt or --append-system-prompt-file, which claude --help lists for bare mode
A folder added with --add-dir has no effectIts CLAUDE.md is not loaded by defaultSet CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1
An Instruction file not loaded noticeA Read deny rule covers the file, or it resolves outside your working directories while reads there are blockedRemove or narrow the rule, or move the file inside your working directories, then start a new session
An @import loads nothingA relative path resolves from the file that contains it, not from where you launchedFix the path

The two AGENTS.md rows interact. If a teammate adds a personal CLAUDE.local.md to a repository that relies on AGENTS.md, Claude stops reading AGENTS.md for that teammate, because CLAUDE.local.md counts as a CLAUDE.md for this check. An @AGENTS.md import at the top of CLAUDE.md keeps it loading for everyone.

We set up a few of these cases as files in a scratch folder. Its api/CLAUDE.md starts with @AGENTS.md, and the AGENTS.md sits at the project root. Our audit script, which you can copy at the end of this post, printed MISSING ./api/CLAUDE.md:1 @AGENTS.md (looked for ./api/AGENTS.md), because the import resolves from the api folder.

Versions matter here. From the changelog:

VersionWhat changed
2.1.277AGENTS.md support: in a project with no CLAUDE.md, Claude Code reads AGENTS.md instead
2.1.281AGENTS.md support extended to Amazon Bedrock, Google Vertex AI, Microsoft Foundry, LLM gateways and sessions with telemetry disabled
2.1.283/doctor prompt-audit added
2.1.288Path-scoped rules and nested CLAUDE.md files also load when Write or Edit creates or changes a file in their scope (before, only Read loaded them)
2.1.293The same files also load when Claude views a file with a single-file cat, head, tail, sed -n or grep in Bash
2.1.309A nested CLAUDE.md over the size limit loads only its start

The next picture shows what Claude can see and when, in the order the docs give. It is the map for the table above.

Four bands of files: loaded at launch in order, also at launch, loaded later on demand, and never loaded
Four bands of files: loaded at launch in order, also at launch, loaded later on demand, and never loaded

Orange outlines mark the files that compaction summarizes away. Dashed boxes are the cases where a CLAUDE.md never loads at all.

Our free lesson Context budget: what loads when has a table of what loads before your first prompt and what survives /compact, and what each part costs in context covers the price of everything that does load.

How long can CLAUDE.md be before Claude loses the rules?

Anthropic's target is under 200 lines per CLAUDE.md file. Longer files use more context and reduce adherence. If a file is over that length you see a warning at startup and in /status, and a second warning when files that are each short enough add up past a combined limit. Each CLAUDE.md, rules file and @path import counts as a separate file. Splitting one file into five imported ones does not reduce its context cost, because imports load with the file that names them.

Two limits get less attention.

  • A hard stop at 4 MiB. Claude Code skips a larger file and loads none of it.
  • A per-file cap on on-demand files. Subfolder CLAUDE.md files and path-scoped rules are cut at 40,000 characters on a 200K window, and at 150,000 to 200,000 on a 1M window depending on the model. Claude then gets only the start, plus a note to read the rest. Until it does, the later rules are not in its context. Check with wc -m path/to/CLAUDE.md. Before v2.1.309 this limit did not apply.

The "80 lines" figure is one writer's claim, not a documented limit. The best evidence on why more rules mean less obedience comes from outside Claude Code. The IFScale benchmark gave 20 models up to 500 keyword instructions at once, and even the best frontier models reached only 68% accuracy at the top density. It also reports a bias toward earlier instructions.

An older paper, Lost in the Middle, found that models often do best when the relevant text sits at the beginning or end of a long context. Neither tested CLAUDE.md, and neither gives a line count. Our reading: every extra line dilutes the others, and a rule you care about should not sit at the bottom of a long file.

Keep what Claude cannot work out from the code. The best-practices page says the same: the exact test and lint commands, places where the code misleads, decisions that never reached the repository, and anything you have had to correct twice. /doctor proposes the cuts for a checked-in file: it removes content Claude can derive, such as directory layouts, dependency lists and architecture overviews, and keeps pitfalls, rationale and conventions that differ from tool defaults.

What moves out is anything that matters for one part of the codebase. Put it in .claude/rules/ with a paths field:

markdown
---
paths:
  - "src/api/**/*.ts"
---
All handlers must validate input with zod.

The rule then loads only when Claude works with a matching file. One trap: paths is the only field Claude Code reads in a rule, and any other field is ignored without an error, so a typo such as path: leaves the rule unscoped. We put that typo in a scratch rule. The audit script at the end of this post prints each rule's front matter keys and flags the ones with no paths key.

Our own app repository follows this split. Its CLAUDE.md is 104 lines (we counted at commit 1590bce on 15 November 2026), and the procedures live in six skills and one subagent, not in the file. Our workspace also sets claudeMdExcludes, which skips CLAUDE.md files by path, so the ones inside cloned upstream repositories and draft setups never load beside ours.

Do your rules contradict each other, or say too little?

When two instructions disagree, Claude may pick one arbitrarily. Several files can disagree: every CLAUDE.md up the tree, nested ones, CLAUDE.local.md, rules, and your ~/.claude/CLAUDE.md. Search them all for the topic, not file by file:

bash
grep -n -i "indent\|tabs\|spaces" CLAUDE.md .claude/rules/*.md

On our example folder that printed two lines, and they are the bug:

CLAUDE.md:3:Use 2-space indentation.
CLAUDE.md:8:Always use tabs for indentation.

Add ~/.claude/CLAUDE.md to your own command. A rule left in your user file months ago still loads, because all files are concatenated rather than overriding each other.

Vague rules are the other half. The docs say adherence drops when an instruction can be read several ways, and give three pairs worth copying:

VagueConcrete
Format code properlyUse 2-space indentation
Test your changesRun npm test before committing
Keep files organizedAPI handlers live in src/api/handlers/

Two more sources of conflict hide outside your files. If your CLAUDE.md sets commit or pull request rules, they compete with the guidance Claude Code adds on its own. The docs say to turn the built-in ones off with includeGitInstructions and set your attribution text with attribution. And capital letters do not help: Anthropic says that when Claude keeps ignoring a line that is in CLAUDE.md, adding IMPORTANT probably won't fix it. Either the file has grown long enough that the line gets lost, or the rule can't have exceptions and belongs in a hook.

To have Claude find the stale and conflicting lines for you, run /doctor prompt-audit (v2.1.283 or later). It looks for instructions written for older models, references to files or commands that don't exist, and files that contradict each other. You get a report with proposed edits, and nothing changes until you ask Claude to apply them.

A word on a theory you will meet. One user report, #22309, says CLAUDE.md is wrapped in a note saying the content "may or may not be relevant". It was closed as a duplicate, and we did not reproduce it, so we build no advice on it.

Why does Claude forget CLAUDE.md in long sessions?

Because compaction treats files differently. The docs spell it out:

  • Project-root CLAUDE.md survives. After /compact, Claude re-reads it from disk and re-injects it.
  • Nested CLAUDE.md files and path-scoped rules do not. They load into message history when Claude touches a trigger file, so compaction summarizes them away with everything else. They come back when Claude touches a matching file again.
  • Instructions given only in chat can vanish. The summary keeps your requests and key code, but detailed instructions from early in the conversation may be lost.

Rules without a paths field behave like the root CLAUDE.md and are re-injected on compaction, as Anthropic's blog puts it. Path-scoped rules are summarized away, as the context-window page says. We would not rely on a path-scoped rule to survive a long session.

The fixes, cheapest first:

  1. Move the rule into the project-root CLAUDE.md. If it is a path-scoped rule you cannot afford to lose, drop its paths field.
  2. Say what to keep. Add a "Compact Instructions" section to CLAUDE.md, or run /compact focus on the API changes before a long task.
  3. Re-inject on every compaction. A SessionStart hook with the compact matcher runs after each compaction, and its stdout goes into Claude's context:
json
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "compact",
        "hooks": [
          { "type": "command", "command": "echo 'Reminder: use pnpm, never npm. Tests: pnpm test.'" }
        ]
      }
    ]
  }
}
  1. Clear between tasks. Run /clear when you switch to unrelated work. Old conversation crowds out the files you need next.

How do you turn a must-never rule into a hook?

Anthropic splits instructions into two kinds. A prompt, CLAUDE.md or skill is non-deterministic: the model decides what to do with it. A hook, a deny rule or a managed setting is deterministic: Claude Code applies it every time. The docs' own examples of what to move are Never read .env, Always run the formatter after editing and Don't touch the migrations folder. Claude follows these "almost every time", and for the few where "almost" is not enough, they leave CLAUDE.md.

Do it only for rules with zero exceptions. The docs make the same point: Prefer named exports has plenty of exceptions, so it stays in CLAUDE.md.

Six cards: CLAUDE.md, rule with paths, skill, hook, blocker and personal file, with where each lives
Six cards: CLAUDE.md, rule with paths, skill, hook, blocker and personal file, with where each lives

Only the two orange cards, hooks and blockers, are enforced by Claude Code. The rest are requests.

Here is a PreToolUse hook for a familiar slip, Claude running npm install in a pnpm repository. The script reads the hook input from stdin, and exit code 2 is what blocks:

bash
#!/usr/bin/env bash
# .claude/hooks/deny-npm.sh
command -v jq >/dev/null || { echo "Blocked: jq is not installed, so this hook cannot check the command" >&2; exit 2; }
cmd=$(jq -r '.tool_input.command // ""')
if printf '%s' "$cmd" | grep -Eq '(^|[;&|[:space:]])npm[[:space:]]+(install|i|ci)([[:space:]]|$)'; then
  echo "Blocked: this repo uses pnpm. Run: pnpm install" >&2
  exit 2
fi
exit 0

Make the script executable with chmod +x, then register it in .claude/settings.json:

json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"${CLAUDE_PROJECT_DIR}\"/.claude/hooks/deny-npm.sh",
            "onFailure": "block"
          }
        ]
      }
    ]
  }
}

Three details decide whether this enforces anything.

  • Exit 2 blocks. Exit 1 does not, on its own. Any code other than 0 or 2 is a non-blocking error and the action goes ahead, unless the hook sets onFailure: "block". A DEV guide on enforcing rules uses exit 1 in its example hooks, so without that field they log an error and the action goes ahead. With exit 2, Claude Code passes the script's message to Claude as feedback, so it can change course.
  • onFailure: "block" covers a broken hook. Without it, a hook that crashes, times out or cannot start lets the call through. The field needs v2.1.295 or later. It does not catch a script that fails quietly and still exits 0. That is why ours checks for jq itself: with jq off the PATH, the same script without that line exited 0 on npm install left-pad, and with it, 2.
  • Misplaced JSON is ignored. If you return permissionDecision as JSON instead of using exit codes, it belongs inside hookSpecificOutput. At the top level it parses, and Claude Code ignores it without an error.

The docs suggest testing a hook by piping sample JSON into it. We did that with our script, and the exit codes were:

Command in the sample inputExit code
npm install left-pad2 (blocked, message on stderr)
cd app && npm ci2
npm i2
pnpm install0
npm test0
sh -c "npm install"0

That last row is the lesson. A hook that matches strings blocks the routes you listed and nothing else. Aident's walkthrough makes the same point about its own npm install hook: it says its example does not catch aliases, shell indirection or another tool that writes the lockfile. The way out is to enforce the outcome as well, with a repository check or CI step, and leave CLAUDE.md to explain why.

A PreToolUse hook that returns permissionDecision: "deny" blocks the tool even in bypassPermissions mode. For files, a permission rule is simpler, and deny rules hold in every permission mode:

json
{
  "permissions": {
    "deny": ["Read(./.env)"]
  }
}

Rules match tool calls, not intent. The Read rule catches cat .env, but a script that opens the file slips past it, which is why, for anything security-related, the docs want both the sandbox and the permission rules. For a rule that must hold across an organization, admin-deployed managed settings cannot be overridden by a user's local config.

Exercise: audit your CLAUDE.md in 10 minutes

Run this from the folder where you start Claude Code. It reads files and changes nothing:

bash
#!/usr/bin/env bash
d=$PWD
while :; do
  for f in CLAUDE.md .claude/CLAUDE.md CLAUDE.local.md AGENTS.md; do
    [ -f "$d/$f" ] && printf '%5s lines  %s\n' "$(wc -l < "$d/$f")" "${d/#$PWD/.}/$f"
  done
  [ "$d" = / ] && break; d=$(dirname "$d")
done
echo "-- nested CLAUDE.md files (load on demand):"
find . -mindepth 2 -name CLAUDE.md
echo "-- rule files and their front matter keys:"
for f in .claude/rules/*.md; do
  [ -f "$f" ] || continue
  keys=$(head -1 "$f" | grep -q '^---$' && sed -n '2,/^---$/p' "$f" | grep -o '^[A-Za-z_]*:' | tr '\n' ' ')
  echo "$f  ${keys:-no front matter}"
  case $keys in *paths:*) ;; *) echo "   ^ no paths: key, so this rule loads every session" ;; esac
done
echo "-- @imports (a path is read from the importing file's folder):"
grep -rn --include=CLAUDE.md '^@' . | while IFS=: read -r file line imp; do
  p="$(dirname "$file")/${imp#@}"
  if [ -e "$p" ]; then echo "ok       $file:$line $imp"; else echo "MISSING  $file:$line $imp (looked for $p)"; fi
done

On our example folder it printed a 230-line ./CLAUDE.md and the AGENTS.md next to it, the nested ./api/CLAUDE.md, the two rule files (one with paths:, one with the path: typo, flagged), and the missing import. Then work through the list:

  1. Minutes 1 to 2. Run the script. Anything over 200 lines goes on a cut list. Check that each nested file is under the character cap with wc -m.
  2. Minutes 3 to 4. Start a session and run /context all. Is each file the script found listed under Memory files? Subfolder files will not be. Touch one and look for the Loaded line.
  3. Minutes 5 to 6. Search for conflicts on the three topics you care about most (formatting, tests, git) with grep -n -i, across CLAUDE.md, rules and ~/.claude/CLAUDE.md.
  4. Minutes 7 to 8. Run /doctor prompt-audit and read the report before applying anything.
  5. Minutes 9 to 10. Pick the one rule that caused your last bad surprise. Ask: can it have exceptions? If not, write its hook or deny rule now, and run the hook on sample input before you trust it.

Finish by running /context all again and confirming that the file you trimmed still loads.

FAQ

Does Claude Code read CLAUDE.md automatically?

Yes, at the start of every session, from your working directory and every directory above it. Files in subfolders load when Claude reads, writes or edits a file there.

Where should CLAUDE.md go?

./CLAUDE.md or ./.claude/CLAUDE.md for the project, CLAUDE.local.md (kept out of version control) for your own notes, and ~/.claude/CLAUDE.md for every project on your machine.

Why does Claude Code ignore my AGENTS.md?

Usually because a CLAUDE.md exists in your folder or above. Add @AGENTS.md as its first line, and check you are on v2.1.277 or later.

Do subagents see my CLAUDE.md?

Not all of them. Other built-in and custom subagents load it, but Explore and Plan start without it, and a custom subagent with omitClaudeMd set skips it too. Put the rule in the delegation prompt.

Does /code-review read my CLAUDE.md?

Yes. /code-review reads your CLAUDE.md and not REVIEW.md, as our code review post explains, so put review rules in CLAUDE.md.

Can I make a CLAUDE.md rule mandatory?

Not in CLAUDE.md. Use a PreToolUse hook that exits 2, or a permissions.deny rule, and keep CLAUDE.md for the reason behind it.


Lessons 1 to 3 of our field guide are free, with no account. Start with the lesson on what loads when.

  • claude code setup
  • claude code hooks

Sources

  1. code.claude.com/docs/en/memory
  2. code.claude.com/docs/en/debug-your-config
  3. code.claude.com/docs/en/best-practices
  4. code.claude.com/docs/en/hooks-guide
  5. code.claude.com/docs/en/hooks
  6. code.claude.com/docs/en/context-window
  7. code.claude.com/docs/en/sub-agents
  8. code.claude.com/docs/en/errors
  9. code.claude.com/docs/en/how-claude-code-works
  10. claude.com/blog/steering-claude-code-skills-hooks-rules-subagents-and-more
  11. raw.githubusercontent.com/anthropics/claude-code/main/CHANGELOG.md
  12. github.com/anthropics/claude-code/issues/17530
  13. github.com/anthropics/claude-code/issues/2901
  14. github.com/anthropics/claude-code/issues/22309
  15. dev.to/dylan_1e07ca370a5576/why-claude-code-ignores-your-claudemd-and-how-to-fix-it-2hip
  16. dev.to/yurukusa/your-claudemd-rules-arent-being-enforced-heres-what-actually-works-3aa8
  17. aident.ai/blog/fix-claude-code-not-following-claude-md
  18. arxiv.org/abs/2507.11538
  19. arxiv.org/abs/2307.03172
  20. skillmanifest.co/learn/context

Keep reading