Lean CLAUDE.md: Trim a Bloated Rules File to 40 Lines
Your agent ignores half of a long CLAUDE.md or AGENTS.md. This prompt cuts it to a lean core (stack, commands, a few never-do rules) and moves the rest into imported files.
Added · Updated
You are an editor for AI coding agent instruction files. My CLAUDE.md (or AGENTS.md / .cursorrules) has grown too long and the agent ignores parts of it. Make it lean without losing anything that matters.
## My current file
[PASTE YOUR CLAUDE.md HERE]
## My project
[ONE LINE: e.g. Next.js + Supabase SaaS, solo dev, deploys on Vercel]
## Step 1: Sort every line
Put each rule into one bucket, as a table (rule, bucket, reason):
- CORE: the agent needs it on almost every task (stack, how to run/test/lint, hard never-do rules).
- TOPIC: only matters for some tasks (styling, database, deploys, a specific folder).
- DELETE: the model already does it by default, it repeats another rule, it contradicts another rule, or it's vague ("write clean code", "be careful").
## Step 2: Write the lean core (40 lines max)
Use exactly these sections:
# Project
One or two lines on what this is and the stack.
# Commands
Install, dev, test, lint, build: one line each, exact commands.
# Never
At most 3 rules, phrased as concrete actions (e.g. "Never edit files in /migrations by hand").
# Always
At most 3 rules (e.g. "Plan the files you'll change before editing", "Run the tests before saying done").
# More rules
One import line per topic file, e.g. @docs/agent/database.md
Write rules in plain sentences. No ALL CAPS, no "IMPORTANT!!!", no rule longer than two lines.
## Step 3: Write the topic files
For each TOPIC group, output a file named docs/agent/[topic].md with its rules, each under 30 lines.
## Step 4: Report
- Line count before and after.
- Every rule you deleted, with the reason, so I can veto any.
- Any contradictions you found and how you resolved them.
Rules: keep every exact command, path, and version number exactly as I wrote it, and don't invent rules I didn't have.How to use it
- Click Copy template.
- Paste into ChatGPT, Claude, Grok, Cursor, or your agent framework.
- Replace the [BRACKETED] parts with your details.
Pairs well with: Cache-Friendly System Prompt Layout: Stable First, Volatile Last
FAQ
How long should CLAUDE.md be?
Short enough that every line matters on most tasks. Many builders aim for roughly 40 lines or fewer in the root file and move topic rules into separate files the agent loads when needed.
How do I split CLAUDE.md into multiple files?
Claude Code supports @path imports inside CLAUDE.md, for example @docs/agent/database.md. Keep the root file as the core and import the rest. For Cursor, use separate .mdc files with globs.
Does this work for AGENTS.md too?
Yes. The same trimming applies to AGENTS.md, GEMINI.md, and .cursorrules. If a tool doesn't support imports, link the topic files by path and tell the agent when to read each one.
Should I trim CLAUDE.md when I switch to a newer model?
Yes, it's a good time to. Newer models often need fewer instructions, and rules written to work around an older model can now get in the way. Re-run this prompt after a model upgrade, then use the remove-and-add-back test on any rule you're unsure about.
Does a long CLAUDE.md hurt prompt caching?
Length alone doesn't, but editing the file mid-session does, because it changes the start of the prompt and the cache can't be reused. Make rule changes between sessions, and see the cache-friendly system prompt layout for the full ordering.
Get 3 new templates every week
Free. Unsubscribe anytime.Related templates
One Rules File for Claude Code, Codex, Cursor & Gemini
AGENTS.md Starter Template for Claude Code, Codex & Cursor
Cursor Rules Not Working? .mdc Fix Checklist + Starter Rules
Remove-and-Add-Back Test for CLAUDE.md & AGENTS.md Rules
Browse all Coding & Cursor Rules templates