Your CLAUDE.md Is Too Long: I Cut 322 Lines to 24
Published Nov 19, 2026 · 11 min read
My sample CLAUDE.md was 322 lines and about 3,300 tokens by a rough count. Same project, cut to 24 lines: about 200 tokens. Both load into every session, and Anthropic's own docs say longer files eat context and reduce adherence. So the short one costs less and, by that guidance, is more likely to be followed.
Real run (demo-bloat-vs-lean/run.txt, Nov 17, 2026):
$ ./measure.sh bloated/CLAUDE.md lean/CLAUDE.md
file lines chars ~tokens note
bloated/CLAUDE.md 322 13309 3328 over 200 lines
lean/CLAUDE.md 24 822 206
This guide covers what actually loads (and when), what to put in, what to cut, where the useful-but-rare stuff goes, how model routing really works, and how to keep one AGENTS.md for Claude Code, Cursor and Codex. Plus the one small personal file that makes Claude Code stop reading AGENTS.md. Every template is below, copy-paste ready, and you can download them all.
How this was tested: every terminal block on this page is a real run (Linux, bash 5.2, git 2.47, Node 24, Nov 17, 2026) of bash, grep, git and small scripts on plain files. Claude Code, Cursor and Codex were not run for these demos, and there is no agent output on this page. The 322-line CLAUDE.md is a sample built for this test, not copied from a real project. Token counts are rough estimates (characters ÷ 4), not an Anthropic tokenizer count. Claims were checked against the docs: Claude Code memory, subagents, model config, costs and skills; agents.md; Cursor rules; and Codex AGENTS.md.
Watch the video
The video walks through the same six steps with the same real terminal runs (about 10.5 minutes). Watch it on YouTube.
1. What actually loads
You add a rule to a CLAUDE.md inside a package folder, start Claude at the repo root, and ask about it. Nothing. It isn't broken. That file just hasn't loaded yet.
At launch, Claude Code reads CLAUDE.md and CLAUDE.local.md in the folder you started in and in every folder above it. Files in subfolders load on demand, when Claude reads or edits a file in that folder.
Real run (demo-hierarchy/run.txt, Nov 17, 2026):
$ find repo -name "CLAUDE*.md" | sort
repo/CLAUDE.md
repo/packages/api/CLAUDE.md
repo/packages/web/CLAUDE.md
$ cat repo/CLAUDE.md
## Commands
- Test everything: `npm test --workspaces`
This monorepo has three. Start at the root and only the root file loads at launch. packages/api/CLAUDE.md joins when Claude touches a file under packages/api/.
There are four scopes:
- Managed policy, set by your company.
- User:
~/.claude/CLAUDE.md, your personal defaults for every project. - Project:
./CLAUDE.mdor./.claude/CLAUDE.md, committed for the team. - Local:
./CLAUDE.local.md, your own notes, kept out of git.
They don't override each other. They're concatenated, broadest first, so the folder closest to you is read last.
Two commands to know. /init writes a starter file from your codebase; if you already have one, it suggests improvements instead of overwriting it. And /context all (or /memory) shows which files actually loaded. Check that before you blame the model.
2. What to put in
Start with what agents guess wrong most: your commands. Here's a first draft with test, lint and typecheck. Looks fine. To check it, I wrote a tiny script that runs every backticked command under the ## Commands heading of a CLAUDE.md or AGENTS.md, from that file's folder:
check-commands.sh · download
#!/bin/bash
# check-commands.sh FILE : runs every `backticked` command listed under "## Commands"
# in a CLAUDE.md / AGENTS.md, from the file's folder. PASS/FAIL per command.
f="$1"; dir=$(dirname "$f"); fails=0
cmds=$(awk '/^## /{on=($0=="## Commands")} on' "$f" | grep -o '`[^`]*`' | tr -d '`')
while IFS= read -r c; do
[ -z "$c" ] && continue
if (cd "$dir" && bash -c "$c" >/tmp/cc.out 2>&1); then echo "PASS $c"
else echo "FAIL $c"; grep -m1 -i "missing script\|error" /tmp/cc.out | sed "s/^/ /"; fails=$((fails+1)); fi
done <<< "$cmds"
echo "$fails failed"; [ "$fails" -eq 0 ]
Real run (demo-lean-claude-md/run.txt, Nov 17, 2026):
$ cat app/CLAUDE.v1.md
## Commands
- Test: `npm test`
- Lint: `npm run lint`
- Typecheck: `npm run typecheck`
$ ./check-commands.sh app/CLAUDE.v1.md; echo "exit $?"
PASS npm test
PASS npm run lint
FAIL npm run typecheck
npm error Missing script: "typecheck"
1 failed
exit 1
$ ./check-commands.sh app/CLAUDE.md; echo "exit $?"
PASS npm test
PASS npm run lint
PASS node --test test/cart.test.js
0 failed
exit 0
Test: pass. Lint: pass. Typecheck: fail, missing script. This project has no typecheck, so every session the agent would be told to run a command that can't work. The fixed file passes all three. Run a check like this whenever your scripts change: a wrong command in CLAUDE.md is worse than no command at all.
Here's the whole lean file, all 24 lines:
CLAUDE.md · download
# Cart API
<!-- Maintainers: keep this under 60 lines. Procedures go in .claude/skills/. -->
## Commands
- Test: `npm test`
- Lint: `npm run lint`
- One test file: `node --test test/cart.test.js`
## Conventions (only where we differ from defaults)
- Money is integer cents. Never floats.
- ES modules only: `import`, not `require`.
- Code in src/, tests in test/ named *.test.js.
## Workflow
- Plan first if a change touches more than 2 files.
- Smallest diff that works. Run npm test before you say done.
- Never edit a test to make it pass. Ask me instead.
## Model routing
- Searches, renames, one-file edits: use the quick-helper subagent.
- Multi-file bugs and design questions: stay on the main model, plan first.
## Guardrails
- Don't read or edit .env (also enforced by a deny rule in .claude/settings.json).
Commands. Conventions, but only where this project differs from the defaults: money in integer cents, ES modules only. Workflow: plan first for multi-file changes, smallest diff, run the tests, and never edit a test to make it pass. Then a model routing note (section 5) and one guardrail.
Write rules you could check. "Use 2-space indentation", not "Format code properly". "Run npm test before committing", not "Test your changes". That's straight from Anthropic's guidance. And when Claude makes the same mistake twice, that's your signal to add a line.
One more trick: block-level HTML comments in CLAUDE.md are stripped before Claude sees them. So the maintainer note on line 2 costs zero tokens.
3. What to keep out (token cost)
Now the bloated one. Look at the headings:
Real run (demo-bloat-vs-lean/run.txt, Nov 17, 2026):
$ grep -n "^## " bloated/CLAUDE.md
3:## Project Overview
20:## Directory Structure
108:## Dependencies
153:## Architecture
214:## Code Style
240:## Pull Request Review Procedure
272:## Database Migration Procedure
294:## Commands
299:## History of This File
319:## Final Notes
$ grep -n -i "indent" bloated/CLAUDE.md
219:- Use 2-space indentation.
230:- Indent with 4 spaces in all JavaScript files.
A project overview, a full directory tree, every dependency with versions, an architecture essay, a style guide, a 30-step review procedure and a migration procedure. The commands? Line 294, near the bottom. It also contradicts itself: line 219 says 2-space indentation, line 230 says 4 spaces. When two instructions conflict, the docs say Claude may pick one arbitrarily.
Now the cost. A rough estimate is characters divided by four, and that's all this script does (Claude's exact tokenizer isn't on the test box):
measure.sh · download
#!/bin/bash
# measure.sh FILE... : size of each instruction file.
# tokens = rough estimate (characters / 4). Claude's exact tokenizer isn't on this box.
printf "%-20s %6s %7s %8s %s\n" file lines chars ~tokens note
for f in "$@"; do
l=$(wc -l < "$f"); c=$(wc -m < "$f"); t=$(( (c + 3) / 4 ))
note=""; [ "$l" -gt 200 ] && note="over 200 lines"
printf "%-20s %6s %7s %8s %s\n" "$f" "$l" "$c" "$t" "$note"
done
That puts the bloated file at about 3,300 tokens and the lean one at about 200. And it isn't a one-time charge: CLAUDE.md loads at the start of every session, and those tokens are there even when you're doing unrelated work. Anthropic's target is under 200 lines per file.
What to cut first: anything Claude can work out from the code. Directory layouts, dependency lists, architecture overviews. That's exactly what Claude Code's /doctor checkup proposes trimming. Keep the pitfalls, the reasons behind rules, and the conventions that differ from defaults.
Real run (demo-bloat-vs-lean/run.txt, Nov 17, 2026):
$ git --no-pager diff --no-index --stat bloated/CLAUDE.md lean/CLAUDE.md; true
{bloated => lean}/CLAUDE.md | 334 +++-----------------------------------------
1 file changed, 18 insertions(+), 316 deletions(-)
Eighteen lines in, 316 out. The vague lines, like "write clean code" and "follow best practices", are gone too. They cost tokens and say nothing specific.
One trap: splitting the file into @imports doesn't save anything. Imported files load together with the file that imports them, so they cost the same.
4. Move it, don't delete it
Some of that bloat was useful: the 30-step review, the testing conventions. You don't want to delete them. You want them to load only when they matter. There are three places for that:
Real run (demo-scope/run.txt, Nov 17, 2026):
$ ./make-repo.sh
repo ready: /tmp/vk-scope
$ cd /tmp/vk-scope && find . -type f -not -path "./.git/*" | sort
./.claude/rules/testing.md
./.claude/skills/pr-review/SKILL.md
./.gitignore
./CLAUDE.local.md
./CLAUDE.md
Rules, in .claude/rules/. A rule with a paths field loads only when Claude reads or edits a matching file. This one covers test files, so while Claude edits source code, these lines aren't in context. paths is the only frontmatter field Claude Code reads in a rule.
.claude/rules/testing.md · download
---
paths:
- "test/**/*.test.js"
---
# Testing rules
- Use node:test and node:assert/strict. No Jest.
- One behavior per test. Name it after the behavior.
- Fixtures in test/fixtures/ are generated: run node scripts/fixtures.js.
Skills, in .claude/skills/. Procedures become skills. The review checklist moves to a SKILL.md. A skill loads when you invoke it, or when Claude decides it's relevant. disable-model-invocation: true means only you can start this one, by typing /pr-review (the command name comes from the folder name).
.claude/skills/pr-review/SKILL.md · download
---
name: pr-review
description: Review a branch before merge. Use when asked to review a PR or a diff.
disable-model-invocation: true
---
1. Run `npm test` and `npm run lint`. Stop if either fails.
2. Read `git diff main...HEAD`. Flag money math that isn't integer cents.
3. Flag new routes without auth or rate limits.
4. Flag new dependencies and irreversible migrations.
5. Report: blockers first, then nits. Don't edit files.
Personal notes, in CLAUDE.local.md. Your sandbox URL goes here, and the file stays out of git:
CLAUDE.local.md · download
# My local notes (not committed)
- My sandbox API: http://localhost:8787
.gitignore · download
CLAUDE.local.md
.env
Real run (demo-scope/run.txt, Nov 17, 2026):
$ cd /tmp/vk-scope && git check-ignore -v CLAUDE.local.md && git ls-files
.gitignore:1:CLAUDE.local.md CLAUDE.local.md
.claude/rules/testing.md
.claude/skills/pr-review/SKILL.md
.gitignore
CLAUDE.md
git check-ignore confirms it's ignored, and git ls-files shows it was never committed. Remember this file. It matters in section 6.
5. Model routing
A common tip is to write "use Haiku for small tasks" in your CLAUDE.md. But CLAUDE.md is guidance. It can't change which model runs anything. I searched this project for anything that actually sets a model:
Real run (demo-model-routing/run.txt, Nov 17, 2026):
$ grep -rn "haiku\|model:" CLAUDE.md .claude/
.claude/agents/quick-helper.md:5:model: haiku
One hit: line 5 of a subagent file. That's the real switch. The subagent lives in .claude/agents/: a name, a description that says when to use it, a short tool list, and model: haiku. Leave the model out and it runs on the same model as your conversation.
.claude/agents/quick-helper.md · download
---
name: quick-helper
description: Fast helper for searches, renames and single-file edits. Use for small, well-defined tasks.
tools: Read, Grep, Glob, Edit
model: haiku
---
You make small, well-defined changes. Touch one file unless told otherwise.
Report what you changed in two lines. If the task needs a design decision, stop and say so.
Now the ## Model routing lines in the lean CLAUDE.md make sense. They don't say "use Haiku". They say searches, renames and one-file edits go to the quick-helper, and multi-file bugs stay on the main model with a plan first. The instruction points at a subagent; the subagent sets the model. Claude can still pass a different model when it starts one, so treat it as the default, not a lock.
For the main session, use /model or set model in your settings. opusplan uses Opus while you're in plan mode, then switches to Sonnet to write the code:
settings.example.json (put the key in .claude/settings.json) · download
{
"model": "opusplan"
}
Anthropic's cost guide puts it simply: Sonnet handles most coding tasks well, so save Opus for complex architectural decisions and multi-step reasoning.
6. One file for every agent
You use Claude Code, Cursor and Codex, and you've got three instruction files slowly drifting apart. The fix is one AGENTS.md at the repo root. It's an open format, now stewarded by the Agentic AI Foundation under the Linux Foundation. Here's the same project as a shared file, minus the Claude-only lines:
AGENTS.md · download
# Cart API
## Commands
- Test: `npm test`
- Lint: `npm run lint`
- One test file: `node --test test/cart.test.js`
## Conventions (only where we differ from defaults)
- Money is integer cents. Never floats.
- ES modules only: `import`, not `require`.
- Code in src/, tests in test/ named *.test.js.
## Workflow
- Plan first if a change touches more than 2 files.
- Smallest diff that works. Run npm test before you say done.
- Never edit a test to make it pass. Ask instead.
## Guardrails
- Don't read or edit .env.
Codex reads AGENTS.md before doing any work, from the repo root down to your folder, with a default budget of 32 KiB. Ours is 519 bytes. Cursor reads it in the project root and in subfolders. And since v2.1.277 (September 2026), Claude Code reads it too.
Here's the catch. By default, Claude Code reads AGENTS.md only when there's no CLAUDE.md, no .claude/CLAUDE.md and no CLAUDE.local.md in your folder or above it. Remember that personal notes file from section 4? Add one to an AGENTS.md project, and Claude Code reads your notes instead of AGENTS.md. Not a bug: it's the default.
This script applies the rule from the docs to any folder. It isn't Claude Code; it just encodes the documented default table, walking from the folder up to /:
instructions-audit.sh · download
#!/bin/bash
# instructions-audit.sh [DIR] : lists instruction files from DIR up to /, then prints which
# project files Claude Code reads BY DEFAULT ("claude-md-or-agents-md", v2.1.277+), per
# code.claude.com/docs/en/memory#agents-md. This script encodes the docs' table; it is not Claude Code.
d=$(cd "${1:-.}" && pwd); found=(); claude=0; agents=0; imports=0
while :; do
for f in CLAUDE.md .claude/CLAUDE.md CLAUDE.local.md AGENTS.md .claude/AGENTS.md; do
[ -e "$d/$f" ] || continue
found+=("$d/$f")
case "$f" in AGENTS.md|.claude/AGENTS.md) agents=1;; *) claude=1; grep -q '^@AGENTS.md' "$d/$f" && imports=1;; esac
done
[ "$d" = / ] && break; d=$(dirname "$d")
done
for f in "${found[@]}"; do echo "found: $f"; done
if [ $claude -eq 1 ] && [ $imports -eq 1 ]; then
echo "Claude Code default: CLAUDE files, with AGENTS.md pulled in by @AGENTS.md"
elif [ $claude -eq 1 ] && [ $agents -eq 1 ]; then
echo "Claude Code default: CLAUDE files only. AGENTS.md is NOT read (unless CLAUDE.md imports it)."
elif [ $agents -eq 1 ]; then echo "Claude Code default: reads AGENTS.md"
elif [ $claude -eq 1 ]; then echo "Claude Code default: reads CLAUDE files"
else echo "no project instruction files"; fi
Real run (demo-one-file/run.txt, Nov 17, 2026):
$ for l in a-agents-only b-agents-plus-local c-import; do ./instructions-audit.sh /tmp/vk-layouts/$l; done
found: /tmp/vk-layouts/a-agents-only/AGENTS.md
Claude Code default: reads AGENTS.md
found: /tmp/vk-layouts/b-agents-plus-local/CLAUDE.local.md
found: /tmp/vk-layouts/b-agents-plus-local/AGENTS.md
Claude Code default: CLAUDE files only. AGENTS.md is NOT read (unless CLAUDE.md imports it).
found: /tmp/vk-layouts/c-import/CLAUDE.md
found: /tmp/vk-layouts/c-import/AGENTS.md
Claude Code default: CLAUDE files, with AGENTS.md pulled in by @AGENTS.md
AGENTS.md only: read. AGENTS.md plus a local notes file: not read. A CLAUDE.md that imports it: read.
That third layout is the safe one. A short CLAUDE.md whose first line is @AGENTS.md. Claude reads the shared file first, then your Claude-only lines below it, like the subagent routing. It also works in sessions that can't read AGENTS.md directly, and the file is never loaded twice. Save this as CLAUDE.md next to AGENTS.md:
CLAUDE.md (import version) · download
@AGENTS.md
## Claude Code only
- Searches, renames, one-file edits: use the quick-helper subagent.
- .env is also blocked by a deny rule in .claude/settings.json.
Or, in /config, set Project instructions to claude-md-and-agents-md so Claude Code reads both.
What about a symlink? ln -s AGENTS.md CLAUDE.md works, and Git stores it as a link (mode 120000). Then I cloned the repo with core.symlinks set to false, which is what you get on Windows unless symlinks are enabled:
Real run (demo-one-file/run.txt, Nov 17, 2026):
$ cd /tmp/vk-onefile && ls -l CLAUDE.md && git ls-files -s CLAUDE.md
lrwxrwxrwx 1 box box 9 Nov 17 07:51 CLAUDE.md -> AGENTS.md
120000 47dc3e3d863cfb5727b87d785d09abf9743c0a72 0 CLAUDE.md
$ cat /tmp/vk-winclone/CLAUDE.md; echo; wc -c < /tmp/vk-winclone/CLAUDE.md
AGENTS.md
9
Nine bytes: just the words AGENTS.md. Anthropic's docs warn about exactly this. (We simulated it with core.symlinks=false; we didn't test on a Windows machine.) If anyone on your team uses Windows, use the import.
Recap
- Check what loads with
/context all. - List real commands, and test them with
check-commands.sh. - Cut what Claude can learn from the code, and stay under 200 lines.
- Move procedures to skills and file-specific rules to
.claude/rules/. - Route models with subagents, not wishes.
- One
AGENTS.md, imported by a shortCLAUDE.md.
All templates (download)
Everything above in one zip, laid out in the right folders: claude-md-agents-md-templates.zip. Or grab single files:
CLAUDE.md: the lean 24-line CLAUDE.mdcheck-commands.sh: runs every command under## Commands, PASS/FAILmeasure.sh: lines, characters and rough tokens per instruction fileclaude-rules-testing.md: save as.claude/rules/testing.mdpr-review-SKILL.md: save as.claude/skills/pr-review/SKILL.mdquick-helper.md: save as.claude/agents/quick-helper.mdsettings.example.json: theopusplansetting for.claude/settings.jsonCLAUDE.local.md: personal notes (gitignored)gitignore.txt: save as.gitignore(or add the lines to yours)AGENTS.md: the shared AGENTS.mdCLAUDE.import.md: save asCLAUDE.mdnext to AGENTS.mdinstructions-audit.sh: which instruction files Claude Code reads by default
Make the scripts executable after downloading: chmod +x *.sh.
Want more ready-made setups?
Start with the AGENTS.md template, or lock things down with the 7 Claude Code guardrails from the previous video. If you'd rather have CLAUDE.md templates, subagents, skills and hooks pre-wired, that's what our Claude Code Starter Kit ($39) is for.
FAQ
How long should CLAUDE.md be?
Anthropic's docs target under 200 lines per CLAUDE.md file. Longer files use more context and reduce adherence. Keep commands, pitfalls and conventions that differ from defaults, and move procedures to skills and file-specific rules to .claude/rules/.
Do @imports make CLAUDE.md cheaper?
No. Imported files load together with the file that imports them, so they cost the same context. Use path-scoped rules in .claude/rules/ or skills when you want instructions to load only when they matter.
Can CLAUDE.md choose which model Claude Code uses?
No. CLAUDE.md is guidance, not configuration. To route small tasks to a cheaper model, create a subagent in .claude/agents/ with a model field such as haiku, and point to it from CLAUDE.md. For the main session use /model or the model key in settings, for example opusplan.
Why is Claude Code ignoring my AGENTS.md?
By default, Claude Code reads AGENTS.md only when there is no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md in your folder or above it. Adding a personal CLAUDE.local.md switches it off. Use a short CLAUDE.md whose first line is @AGENTS.md, or set Project instructions in /config to read both.
Should CLAUDE.md be a symlink to AGENTS.md?
A symlink works on macOS and Linux, but on Windows Git checks a committed symlink out as a plain text file unless core.symlinks is enabled. In our test with core.symlinks=false, CLAUDE.md became a 9-byte file containing just AGENTS.md. If anyone on your team uses Windows, use the @AGENTS.md import instead.