Your CLAUDE.md is probably too long. Here's how to cut it

Anthropic's own advice is to prune ruthlessly. A one-question test, a short audit script that finds the stale lines for you, and a map of where each deleted rule should go instead.

A circle drawn as a dense tangle of hatched lines on the left and a few clean strokes on the right

A CLAUDE.md file starts life as five useful lines. Six months later it’s two hundred, half of which describe things Claude could work out by reading your code, and the instruction you actually care about is somewhere around line 140.

That’s not just untidy. Anthropic’s best-practices guide says it directly: bloated files cause Claude to ignore your actual instructions, because important rules get lost in the noise. The file is loaded at the start of every conversation, so every line costs context every time.

Pruning by hand is the right fix and a tedious one. This piece gives you the test to apply, a script that does the first pass, and a place to put everything you delete.

The test

For each line, the guide suggests asking one question: would removing this cause Claude to make mistakes? If not, cut it.

Applied honestly, that deletes a lot. Here’s a typical file before:

# Project overview
This is an e-commerce backend in TypeScript. We value clean, readable, well-tested code.

# Structure
- `src/routes/`: route handlers
- `src/services/`: business logic
- `src/db/`: database access
- `src/legacy/`: old payment code, do not extend

# Style
- Follow best practices
- Use ES modules, not CommonJS
- No default exports in `src/services/`

# Testing
- Single file: `pnpm vitest run path/to/file.test.ts`
- Lint with `pnpm run lint:strict` before committing
- Integration tests need `DATABASE_URL` pointing at the docker db

Claude can see that the project is TypeScript and can see the folder layout by looking. “Follow best practices” and “clean, readable, well-tested” change nothing. The guide’s exclude list names exactly these: anything Claude can figure out by reading code, standard conventions, file-by-file descriptions, and self-evident practices like “write clean code.”

Let a script do the first pass

Some lines fail the test for a more mechanical reason: they’re stale. A path that was renamed, a script that no longer exists. A stale line is worse than an empty one, because Claude will trust it. This script flags three things per line (it’s plain Python 3 with no dependencies, run as python audit_claude_md.py .): a backticked path that doesn’t exist, an npm, pnpm or yarn run command with no matching entry in package.json, and generic advice phrases.

#!/usr/bin/env python3
"""Flag CLAUDE.md lines that are probably stale or dead weight."""
import json, os, re, sys

root = sys.argv[1] if len(sys.argv) > 1 else "."
lines = open(os.path.join(root, "CLAUDE.md"), encoding="utf-8").read().splitlines()

scripts = set()
pkg = os.path.join(root, "package.json")
if os.path.exists(pkg):
    scripts = set(json.load(open(pkg, encoding="utf-8")).get("scripts", {}))

GENERIC = re.compile(r"clean code|best practices|meaningful (variable )?names|well[- ]tested|readable", re.I)
flagged = 0
for n, line in enumerate(lines, 1):
    for tok in re.findall(r"`([^`\s]+)`", line):
        looks_like_path = ("/" in tok or re.search(r"\.\w{1,5}$", tok)) and not tok.startswith(("-", "http", "$"))
        if looks_like_path and not os.path.exists(os.path.join(root, tok.rstrip("/"))):
            print(f"{n:>3}: missing path  {tok}"); flagged += 1
    for m in re.finditer(r"(?:npm|pnpm|yarn) run\s+([\w:-]+)", line):
        if scripts and m.group(1) not in scripts:
            print(f"{n:>3}: no such script  {m.group(1)}"); flagged += 1
    if GENERIC.search(line):
        print(f"{n:>3}: generic advice  {line.strip()[:60]}"); flagged += 1

print(f"{len(lines)} lines, {flagged} flagged")
sys.exit(1 if flagged else 0)

Against the file above, with a package.json that defines lint, build and test and with the src/legacy/ folder deleted, it prints:

$ python audit_claude_md.py .
  2: generic advice  This is an e-commerce backend in TypeScript. We value clean,
  8: missing path  src/legacy/
 11: generic advice  - Follow best practices
 17: no such script  lint:strict
18 lines, 4 flagged

Four findings, and each one is a real edit. Line 8 describes a folder that’s gone. Line 17 tells Claude to run a lint script that doesn’t exist, so it will either fail or invent a substitute. The other two are the generic lines you were going to delete anyway.

It isn’t clever, and it has false positives. Pointed at this site’s own CLAUDE.md, which has 200 lines, it flags four, and all four are fine: a path in a sibling repository, a placeholder path (assets/images/posts/<slug>.jpg), a bare .md, and the word “readable” inside “machine-readable”. Treat the output as a list of lines to look at, not a verdict. It also doesn’t know about pnpm vitest, which runs a binary and not a script, so it deliberately ignores any command that isn’t written as run <name>.

Run it in CI if you like (the exit code is 1 when it flags something), but running it by hand before each cleanup is the safer habit. A stale-line check that fails builds will get switched off the first time it’s wrong.

The file after

# Style
- Use ES modules, not CommonJS
- No default exports in `src/services/`

# Testing
- Single file: `pnpm vitest run path/to/file.test.ts`
- Lint with `pnpm run lint` before committing
- Integration tests need `DATABASE_URL` pointing at the docker db

Eighteen lines became eight, and every remaining line is something Claude couldn’t guess. The guide’s include list matches: commands Claude can’t guess, style rules that differ from defaults, testing instructions, repository etiquette, architectural decisions, environment quirks and non-obvious gotchas.

Where deleted rules should go

Cutting a rule doesn’t always mean it’s unimportant. Some of it belongs somewhere else. A quick way to decide:

  • Does it only matter some of the time? Put it in a skill. Claude loads skills on demand, so they don’t bloat every session. An example from the docs is an api-conventions skill: a folder under .claude/skills/ with a SKILL.md holding the REST rules for your services. Claude applies it when you’re working on an endpoint and ignores it the rest of the day.
  • Must it happen every time, with no exceptions? Put it in a hook. Instructions in CLAUDE.md are advisory. Hooks are deterministic. The guide’s own advice for the “over-specified CLAUDE.md” is to delete the rule or convert it to a hook if Claude already does the thing correctly. (See the Stop hook for tests .)
  • Is it reference material? Link it instead of pasting it. The @path/to/file import syntax lets one file pull in another when you need it.
  • Is it just history (“we moved to pnpm in March”)? Delete it. Git remembers.

A habit that keeps the file short: when you’re about to add a line, ask what went wrong that made you want it. If the answer is “Claude did X in a session”, the line is probably worth keeping, and it should say X. If the answer is “it felt like good hygiene”, it isn’t.

Let Claude propose the cuts

For a CLAUDE.md that’s checked into git, run /doctor and Claude proposes cuts for content it can derive from the codebase. Claude Code 2.1.283 also added /doctor prompt-audit for auditing these files. Check what your installed version does before relying on either, and read the proposed deletions the same way you’d read any diff.

The script and /doctor find different problems. The script finds lines that are provably wrong. /doctor finds lines that are redundant. Run both.

After editing, run /context to confirm Claude loaded the file, then test the change by watching whether behaviour actually shifts. Treat the file like code: review it when things go wrong, and prune it regularly.

Keep the lines that must survive compaction

One thing the guide suggests keeping, because compaction can otherwise drop it: instructions about what to preserve. A line such as “When compacting, always preserve the full list of modified files and any test commands” tells Claude what matters when it summarises a long session. It’s the kind of line that passes the one-question test, because without it the failure is real and hard to notice.

One more trick

If Claude keeps skipping a single instruction, the guide suggests adding emphasis such as “IMPORTANT” to that line alone. It only works while it’s rare. Emphasise ten lines and none of them stand out.

Codex users have a version of the same problem: its AGENTS.md chain silently truncates at 32 KiB, as the Codex layering guide explains. Different tool, same rule. Short files get read.

Do this in fifteen minutes

  1. Save the script as audit_claude_md.py in your repo (or a scripts folder), run it, and fix every flagged line that’s actually wrong.
  2. Read your CLAUDE.md top to bottom with the one-question test. Delete what fails it.
  3. For each deletion that felt risky, decide: skill, hook, import or gone.
  4. Run /context in a fresh session to confirm the short file loads, then work with it for a week. Anything you miss goes back in, with the reason next to it in your commit message.