Ship It With AI Mihai Cvasnievschi

AGENTS.md and context

10 min read

By the end you can write an AGENTS.md in which every line earns its place, and run agent sessions that stay sharp.

TL;DR


What is AGENTS.md?

AGENTS.md is the team's agreement with the agent, committed in git.

It is a Markdown file for project instructions. A compatible client loads it according to its own discovery and configuration rules; some clients need explicit loading. The text records what the team wants the agent to follow, reviewable in a pull request. It is the manually owned layer of Memory from Chapter 1, not an enforced permission policy.

AGENTS.md vs CLAUDE.md: what's the difference?

The discipline is shared; loading depends on the agent and version.

The shared filename does not imply identical loading. This compatibility summary was checked October 23, 2026; verify the installed version and effective context.

Client Filename and configuration Scope and precedence Inspect what loaded
Codex CLI AGENTS.md; AGENTS.override.md takes precedence in a directory; fallback names configurable Global guidance, then repository root toward working directory; closer instructions override earlier ones; combined size limit configurable Ask for active sources and inspect session/TUI logs when auditing
Claude Code CLAUDE.md default; direct AGENTS.md from v2.1.277 Default AGENTS fallback only when the working-directory/ancestor path contains no CLAUDE.md, .claude/CLAUDE.md or CLAUDE.local.md; a CLAUDE file can import @AGENTS.md; AGENTS override/local filenames are not Codex equivalents /memory; direct AGENTS listings require v2.1.280+, with early exceptions fixed in v2.1.281
Gemini CLI GEMINI.md default; configure context.fileName to include AGENTS.md Global, workspace/ancestor and relevant directory context, subject to trusted-root rules; not Codex's precedence model /memory show, then /memory reload after changes
Aider Explicit aider --read AGENTS.md; persist read: AGENTS.md in .aider.conf.yml Included read-only chat context; no implied AGENTS ancestor-discovery hierarchy Startup confirmation and /ls

Primary documentation and version limits are in Appendix C. Test one distinctive instruction in a fresh session rather than assuming the file was discovered or has identical authority in every client.


The story: one convention, three supports

A team I worked with had used a coding agent for six months when a senior engineer brought me a complaint. "Every time we generate an API endpoint, I have to fix the validation. Always the same fix. The agent puts it in the wrong layer."

"Why isn't the rule written down?"

"We never wrote it down. We just keep fixing it."

The senior repeatedly corrected the same validation placement during endpoint reviews. The original account included endpoint counts and a time estimate, but the underlying review records are not available here, so this edition makes no precise monthly saving claim.

We documented the convention in AGENTS.md, added a PR-template reminder and identified correct endpoints as reference examples. Subsequent reviews reportedly needed fewer corrections of that kind. The intervention was that combination; the account does not isolate the instruction's contribution.

Case note What this account establishes
Provenance Author-reported, anonymized engagement
Evidence A recurring review problem and a reported improvement; underlying review/time records are not published
Comparison Before/after observations of a combined instruction, reminder and reference-example change
Limitations No isolated instruction effect, controlled task mix or defensible monthly time saving
Transfer Write a scoped convention, support reviewers and examples, then measure recurring corrections

Six rules for the file

Six rules, each with a test you can apply to any line.

# Rule You met it when
1 One line, one checkable constraint It names the layer, the mechanism and an example
2 A documented need or failure You can explain the risk, missing convention or repeated correction
3 Task-relevant contents Key conventions, commands, pitfalls, glossary and pointers
4 Concise and scoped Every always-loaded line earns its cost; start well below 200 lines
5 Treat it as code Git, PR review, one rotating champion
6 Read before cite Every name was read this session or found by grep

Rule 1: write rules the agent can check

A rule the agent cannot check is decoration.

The rule
Bad "Always follow our coding standards. Be careful with validation. Use the right architecture."
Good, for this project's HTTP entry path "Controller DTOs establish request-shape guarantees through Bean Validation before service calls; follow UserCreateController. Other entry points establish the same guarantees. Service/domain code still enforces business invariants; use service method validation where required by that boundary."

The bad version leaves the architecture unspecified. The scoped version identifies an entry boundary, its guarantee, a mechanism and an example without declaring services universally safe to trust arbitrary input. Spring supports service method validation too. A portable pattern is: "Within [scope], [entry boundary] establishes [input guarantee] using [mechanism]; follow [reference]. Other entries establish the same guarantee; [owner] maintains domain invariants." Appendix B.2 is a project-specific starting point.

Rules 2 and 5: justified by need, owned like code

A rule earns its place through a concrete need, and a champion keeps the file honest.

Rules 3 and 4: scoped contents, a size guideline

Keep the instructions the agent needs; link to the detail.

Avoid a repository dump. The revised context-file study found no general success improvement from generated files and over 20% more inference cost in its tested settings; developer-written files helped slightly, without a statistically significant average gain. That does not establish that all instructions harm or all maps are useless. Keep non-obvious conventions and useful pointers here; put a long architecture map in docs/architecture.md, read on demand (Chapter 7).

Aim short; treat 200 lines as a guideline. The file loads at session start, so every line spends context. There is no universal line count at which a model stops following rules. Remove duplication and stale instructions, and scope conventions to the paths or skills that need them. Keep rare but important constraints while their underlying risk remains.

A banking team's file grew to about nine hundred lines in six months and the agent began ignoring the newest rules. We cut it to ninety, moving conventions into skills that load on detection and past-mistake history into the architecture document, and compliance jumped within a week. That is one team's observation, not a measured threshold; the useful habit is deciding what belongs in every session.

Rule 6: when the agent confidently lies

The agent invents files, functions and options, so make it prove what it cites.

It will cite a file that does not exist, a function the library never exposed, an option deprecated three versions ago. The output looks plausible and is wrong; the agent pattern-matches against similar code and does not know it is guessing. Three mechanical tactics:


Context hygiene

The window is the agent's working memory, so load what the task needs and nothing else.

Everything in the window competes for the same bounded attention. Stale or conflicting context is one way a long session can lose track of the task. Four habits help manage that risk.

The client determines what it summarizes, retains and reloads; Claude Code's compaction documentation describes those distinctions. Check the behavior of the client and version you use.


When it breaks


Do this Monday


Go deeper