How to Write an Effective AGENTS.md Under 150 Lines
Why verbose AI instruction files degrade agent accuracy, what commands and architectural boundaries actually move the needle, and a proven monorepo pattern.
When teams first discover AGENTS.md, the natural instinct is to write an exhaustive 400-line handbook covering every framework quirk and stylistic preference. In practice, bloated instruction files hurt agent accuracy: critical constraints get buried in prose, and every single prompt turn pays an unnecessary token tax.
The 150-Line Budget Rule
Treat your root AGENTS.md like a Makefile paired with an architectural warning sign. Aim for 60 to 150 lines (under ~1,500 tokens). Everything in that file is injected at the start of every task, so every sentence must earn its place by preventing a mistake an agent would otherwise make.
The 4 High-Signal Sections Every AGENTS.md Needs
1. Copy-Pasteable Build & Verification Commands
An agent should never have to guess whether your repository uses npm test, uv run pytest -q, or bundle exec rspec. Put exact dev, build, test, and lint commands in a fenced bash block near the top of the file:
## Build, Test & Verification Commands
```bash
# Install dependencies
npm install
# Typecheck & static build (mandatory before committing)
npm run build
# Run unit tests
npm test
``` 2. Top-Level Directory Map (5–8 Lines Max)
Skip individual filenames. Instead, tell the agent where domain boundaries live so it opens the right directory on its first search call:
## Project Layout
- `src/lib/` — Pure TypeScript domain logic (zero DOM imports)
- `src/scripts/` — Browser UI controllers wired into Astro pages
- `src/pages/` — File-based static routes
- `tests/` — Node test runner suites covering src/lib/ 3. Non-Obvious Invariants & Gotchas
Do not tell an agent how React or Python works; state the constraints unique to your repository. Examples: "Use trailing slashes on all internal links so canonical URLs match the sitemap," or "Never read from pnpm because the local shim is unconfigured—always use npm."
4. Explicit Negative Boundaries ("Never / Do Not")
Negative guardrails stop the expensive loops agents fall into when trying to be helpful:
- Never edit generated files in
dist/orsrc/generated/manually. - Never commit
.envsecrets or addCo-Authored-Bytrailers if repo policy forbids them. - Never add new npm dependencies when stdlib or an existing package handles the task.
Scaling Beyond 150 Lines in Monorepos
If your repository hosts an API, a web app, and Python workers, do not cram all three into one 400-line root file. Keep the root AGENTS.md focused on workspace-wide commands and shared rules, then drop focused 40-line AGENTS.md files inside apps/web/ or services/worker/. Most modern agents resolve the closest instruction file relative to the files being edited.