Your CLAUDE.md is too long: what to cut, what to move, and how to tell a rule is followed

Published · Updated

If Claude Code is skipping rules in your CLAUDE.md, the file is probably longer than it needs to be, and the fix is subtraction. Anthropic's memory documentation says, as of 2026-11-10, to target under 200 lines per file and gives the reason: "Longer files consume more context and reduce adherence." Nothing in the docs makes 200 a hard limit. Claude gets the whole file, as long as it is 4 MiB or smaller, and a file over 4 MiB is skipped entirely. Line count is a pressure gauge, not a cliff.

Start by deleting what Claude can read for itself

The docs' own advice for /init is to refine the file with "instructions Claude wouldn't discover on its own". Architecture overviews, directory listings and lists of dependencies are rediscovered every session at no cost to you. They are also the lines that go stale first, because nobody updates a directory tree after a refactor.

Check mechanically. This pulls every path written in backticks out of CLAUDE.md and reports the ones that no longer exist.

grep -o '`[^` ]*/[^` ]*`' CLAUDE.md | tr -d '`' | while read p; do
  [ -e "$p" ] || echo "MISSING $p"
done

On a seven-line test file it flagged src/api/handlers/ and scripts/old-deploy.sh, both deleted from the scratch repo. It cannot catch a command that still exists but does something different, so also run every command in the file once by hand. A build instruction that fails is worse than none, since Claude will try it first.

Sort what is left into three piles

A comment on an Ask HN thread about maintaining Claude.md files split the content into facts, constraints written after a specific failure, and behaviour rules, and said each behaves differently. Facts such as commands and conventions always work. Failure constraints work if each is one sentence about something that really happened. Broad behaviour instructions are the ones that fade. That works as a test for every line: which pile is it, and if behaviour, would anyone notice if it vanished?

Another commenter in the same thread wrote "Now I only put what amounts to a table of contents" in the file, with detail elsewhere. That fits the docs, which say to move instructions that matter for only part of the codebase into path-scoped rules.

Move, do not just trim

A rule file under .claude/rules/ can carry a paths field in its YAML frontmatter, and it then loads only when Claude works on matching files.

---
paths:
  - "src/api/**/*.ts"
---

# API rules

- All endpoints validate input before touching the database.

Two cautions from the docs. Imports with @path help you organise a long file but do not reduce its context cost, because imported files load together with the file that imports them. And block-level HTML comments in CLAUDE.md are stripped before injection, so you can leave maintainer notes there without spending tokens on them. Comments inside code blocks are kept.

Check whether a rule held

Most advice stops at "write shorter rules". Your old sessions can tell you whether the rule worked. If CLAUDE.md says "never use npm", count how often Claude ran it. Transcripts record every Bash call as a tool_use block, so this works on any command you care about.

jq -r 'select(.type=="assistant")
  | .message.content[]? | select(.type=="tool_use" and .name=="Bash")
  | .input.command' ~/.claude/projects/<project>/*.jsonl | grep -cE '^(npm|npx) '

On a fixture with one session that ran npm install and one that ran pnpm test, it printed 1 and 0. Run it per file and a rule that was ignored shows up as a nonzero count in sessions after the rule was written. Compare the dates, since a rule cannot be blamed for sessions that predate it. This catches violations you could verify by command. It will not catch a style rule such as "no narration between steps".

When a rule is still ignored while it is in context, look at the failure rather than lengthening the file. #33603 (open) documents repeated sessions in which rules written in response to earlier failures were violated again, and #96326 shows replies drifting into English despite a CLAUDE.md rule requiring Japanese. Both are single-user reports and neither is a confirmed product bug. They are a reminder that adding emphasis does not help.

Confirm what actually loads

Run /context all in a session and look under Memory files to see which CLAUDE.md and rule files are loaded. If a file is missing there, the model cannot see it. From Claude Code 2.1.283 on, /doctor prompt-audit asks Claude to review your instruction files for outdated or contradictory content, and it proposes edits without applying them.

For something that must happen every time, the docs recommend a hook instead. They say Claude treats CLAUDE.md as context, not enforced configuration, and that a PreToolUse hook is the tool for blocking an action regardless of what Claude decides.

Finding the sessions without grep

The jq check above works on the sessions still on disk, and Claude Code removes transcripts after 30 days by default (how to change that). If you use Sealkeep, sealkeep search <query> --content looks inside older sealed sessions for the moment a rule was broken. That is all it does here: it does not tell you whether a rule was followed, and it will not trim the file.

For where CLAUDE.md sits next to auto memory and MCP servers, see memory between sessions. Other guides are at /guides/.

FAQ

How many lines is too many?

The docs' target is under 200 per file, based on adherence rather than a technical cap. If you are over, find the lines that would not be missed before you add structure.

Should I split CLAUDE.md into several imported files?

Splitting by @import makes the file easier to maintain and does not shrink what is sent. Path-scoped rules do, because they load only for matching files.

Do I still need CLAUDE.md if I use auto memory?

They do different jobs. You write CLAUDE.md and the repo shares it. Claude writes auto memory, and it stays on one machine.