Meltlight

Claude Code not following CLAUDE.md: why, and what to change

Updated

The problem

You wrote a rule in CLAUDE.md — "run the tests before committing", "use pnpm, not npm" — and Claude Code does something else. Sometimes it follows the rule for a while and then stops. The question people search for is "Claude Code not following CLAUDE.md".

The short answer

First check that the file is loaded at all: run /context and look for it under "Memory files". If it is listed, the rule reached Claude, but CLAUDE.md is context, not enforced configuration: Claude tries to follow it, and there is no guarantee. Make the rule concrete, remove any rule that contradicts it, keep the file under 200 lines, and turn anything that must happen every time into a hook.

Why it happens

Everything in this section is from the Claude Code memory docs. I have not tested each case below myself.

The file never loaded. Only the CLAUDE.md and CLAUDE.local.md files in your working directory and the directories above it load when the session starts. A CLAUDE.md in a subdirectory loads only when Claude reads a file in that subdirectory, so it is not under "Memory files" and is not in the context before then. Files over 4 MiB are skipped.

It is read as a message, not as a setting. The docs say CLAUDE.md content is delivered as a user message after the system prompt, not as part of the system prompt. Claude reads it and tries to follow it, but there is no guarantee of strict compliance, especially for vague or conflicting instructions.

The rule is vague. The docs' example: "Use 2-space indentation" works better than "format code nicely". A rule you could not check by looking at the result is one Claude can satisfy in many ways.

Two rules contradict each other. If two instructions disagree — in one file, across nested CLAUDE.md files, or between CLAUDE.md and .claude/rules/ — Claude may pick one arbitrarily. A user rule and a project rule do not override each other either.

Claude Code's own guidance competes with yours. Claude Code adds its own instructions for commits and pull requests. If your CLAUDE.md sets different ones, turn the built-in ones off with the includeGitInstructions setting and set the attribution text with attribution.

The file is too long. The docs target under 200 lines per file: longer files consume more context and reduce adherence. Splitting the file with @path imports does not help here, because imported files also load at launch.

The rule was only said in the conversation. After /compact, Claude Code re-reads the project-root CLAUDE.md from disk. An instruction you gave only in chat, or one in a nested CLAUDE.md or path-scoped rule that has not loaded again yet, is gone.

Check it with the tool

Paste your CLAUDE.md into Kanon (beta), the free SKILL.md, CLAUDE.md and AGENTS.md linter on this site, and pick CLAUDE.md. It runs in your browser and sends nothing anywhere.

  • mem-length warns when the file is 200 lines or more, and mem-size is an error when it is over 4 MiB.
  • imports lists every @path import, so you can see what loads at launch besides the file itself. import-external flags imports that may point outside the project: Claude Code asks for approval the first time, and if the approval was declined, those imports stay off.
  • html-comment counts block-level HTML comments. Claude Code strips them before Claude sees the file, so a rule written inside one is never read.
  • fm-in-claude notes that frontmatter does nothing in CLAUDE.md. Only rule files in .claude/rules/ read a frontmatter field, paths.
  • agents-words warns when the file tells Claude to read AGENTS.md in words instead of importing it with @AGENTS.md.

Kanon checks the file, not your rules: it cannot tell whether two of your instructions contradict each other.

What to do next

  1. Confirm it loaded. Start a session and run /context. Every CLAUDE.md and CLAUDE.local.md that should load at launch must be under "Memory files"; if one is missing, Claude cannot see it. For a subdirectory CLAUDE.md, ask Claude to read a file in that subdirectory and watch for a Loaded line with its path. To test a new one, create it from your shell rather than asking Claude to write it.
  2. Rewrite the rule so it can be checked. "Run npm test before every commit" instead of "make sure things work".
  3. Remove contradictions. Read your ~/.claude/CLAUDE.md, the project CLAUDE.md, nested ones and .claude/rules/ together. /doctor prompt-audit asks Claude to look for outdated and conflicting instructions and proposes edits without changing anything until you say so.
  4. Shorten the file. Move instructions that only matter for part of the codebase into .claude/rules/ files with paths frontmatter; they load only when Claude works with matching files.
  5. Make must-happen rules a hook. Something that has to run before every commit or after every edit belongs in a hook, which runs as a shell command at a fixed point whatever Claude decides. To block an action outright, the docs point to a PreToolUse hook or permissions.deny in settings.
  6. Need system-prompt level? Pass the instruction with --append-system-prompt when you launch Claude Code. The docs say this suits scripts and automation better than interactive use.

To see which instruction files load, when and why, the docs suggest logging them with the InstructionsLoaded hook.