Rewrite AGENTS.md rules with a checklist
Audit AGENTS.md for length, enforceability, duplicates and stale commands before you blame the model.
Published here · 3 sources · Resume reading
An AGENTS.md that grew for six months usually fails because the commands are stale, the rules are vague, or a "never" sits in markdown where only a deny or hook can stop the tool. Rewrite it with a pass/fail audit before you blame the model [1] [2].
Run a pass/fail audit
Mark each question Pass or Fail. Any Fail blocks the rewrite from merging.
| # | Question | Pass | Fail |
|---|---|---|---|
| 1 | Does every install, test and lint command still work on a clean clone? | Commands run green | Commands 404, wrong package manager, or CI-only |
| 2 | Is every rule concrete enough to verify? | "Use 2-space indentation" | "Format code properly" |
| 3 | Did you delete anything the agent can see in the tree? | No duplicated folder maps or API lists | Tree dumps and sermons the layout already shows |
| 4 | Is every hard stop outside markdown? | Deny/hook owns "never touch .env" | Only a prose "never" with no enforcement |
| 5 | Is the file under about 200 lines, or split by path? | Short, sectioned | Essay that burns context |
| 6 | Was each new rule added after a repeated mistake? | Second failure, then the rule | Speculative rules for futures nobody hit |
Claude Code memory docs target under 200 lines per CLAUDE.md file: longer files use more context and reduce how reliably Claude follows them [2]. Keep AGENTS.md to the same budget. Prefer several focused sections (setup, tests, PR) over one essay [1] [2]. agents.md shows that shape: setup commands, code style, testing instructions, PR instructions [1].
Paste this checker and fill Pass/Fail by hand:
python3 - <<'PY'
rows = [
"Commands still work on a clean clone",
"Every rule is concrete enough to verify",
"No duplicate of README or obvious tree maps",
"Hard stops live in deny/hook, not prose only",
"File under ~200 lines or split by path",
"New rules added only after a repeated mistake",
]
for i, r in enumerate(rows, 1):
print(f"{i}. [ ] {r}")
PYYou should see six numbered checkbox lines.
Delete vague and duplicate rules
Claude Code memory docs say auto memory skips architecture and paths Claude can derive from the codebase, and skips anything CLAUDE.md already says [2]. Apply the same filter to AGENTS.md:
- Delete repeated tree maps and copy-pasted API inventories.
- Delete "don't invent files" sermons when the folder layout is obvious.
- Delete human onboarding that already lives in
README.md[1]. - Keep what a fresh agent session would otherwise re-ask: install, test, lint, deploy gates and house conventions that are not visible from code alone [2].
Vague lines fail the audit. Claude Code docs ask for instructions concrete enough to verify, and warn that if two instructions contradict each other, Claude may pick one arbitrarily [2].
Add rules only after repeated mistakes
Claude Code memory docs say when to add to CLAUDE.md [2]:
- Claude makes the same mistake a second time.
- A code review catches something Claude should have known about this codebase.
- You type the same correction into chat that you typed last session.
- A new teammate would need the same context to be productive.
Use that bar for AGENTS.md too. A rule you invent "just in case" usually ages into noise. Keep entries to facts every session should hold: build commands, conventions, layout, "always do X" rules. Move multi-step procedures or path-only advice out of the root file (Claude Code path-scoped .claude/rules/ for Claude-specific cases; nested AGENTS.md for shared agent entry in a package) [1] [2].
Move hard stops out of prose
Claude Code treats CLAUDE.md and auto memory as context, not enforced configuration. To block an action no matter what Claude decides, use a PreToolUse hook [2]. Permission deny rules live in settings JSON, not in markdown wishes [3]. When you rewrite AGENTS.md, turn "never touch .env" into a settings deny (or hook) and leave a one-line reminder that points at that enforcement [2] [3].
Teaching reminder line (enforcement lives in settings):
## Secrets
- Do not read `.env` files. Enforcement: deny rules in `.claude/settings.json` (see settings load order).Finish the rewrite checklist
- Re-run the six pass/fail rows above until all Pass.
- Date any fragile UI wording ("checked on YYYY-MM-DD") so the next rewrite knows what aged.
- Confirm nested package files still win for their trees when you rely on nearest-file precedence [1].
- If Claude Code also has a project
CLAUDE.md, import@AGENTS.mdor you will rewrite a file Claude never loads [2].
Related: Write an AGENTS.md coding agents actually read, Where each Claude Code instruction belongs, Constrain AI coding agent scope, Claude Code settings load order, Stop an AI coding agent from over-engineering.
Your next PR should shrink the file and move one fake "never" into a real deny or hook.
Send this to the teammate whose AGENTS.md still lists a package manager the repo abandoned last year.
Keep this guide
Filed under AI agents, Claude Code
Questions about this guide
How long should instruction files stay?
Claude Code memory docs say to target under 200 lines per CLAUDE.md file because longer files use more context and Claude follows them less reliably. Keep AGENTS.md equally short and specific.
Do AGENTS.md lines enforce deny rules?
No. Claude Code memory docs say CLAUDE.md and auto memory are context, not enforced configuration. To block an action regardless of what Claude decides, use a PreToolUse hook. Treat AGENTS.md the same way: guidance, not a sandbox.
When should I add a new rule?
Claude Code memory docs say add to CLAUDE.md when Claude makes the same mistake a second time, a review catches something the model should have known, you retype the same correction, or a new teammate would need the same context. Apply that bar to AGENTS.md too.
What belongs in AGENTS.md vs README?
Per agents.md: README for humans; AGENTS.md for agent build steps, tests and conventions that would clutter a README.
Sources
- AGENTS.md format siteagents.md
- Claude Code docs: How Claude remembers your project (memory)code.claude.com
- Claude Code docs: Settings files and precedencecode.claude.com