Sub topic 3
The file format: just Markdown
This chapter covers what an AGENTS.md file is made of, what the format does not require, and the few file-level details that cause problems in practice. It assumes you know basic Markdown (headings, lists, code spans, fenced blocks) and how a repository is laid out in Git. It also assumes you have used an AI coding assistant at least once. The previous chapter covered what AGENTS.md is for. This one covers how to write the file.
No schema, no required fields
AGENTS.md is an ordinary Markdown text file. It has no schema, no required keys, no mandatory section names and no version number. A file containing one sentence is valid:
Run `npm test` before you finish any change.Nothing validates the file when you commit it, and nothing refuses to load it because a heading is missing. That is a deliberate design choice. Because the format asks for nothing, any project can adopt it in a minute, and any tool that can read a text file can support it.
The agent that loads the file is a language model. It reads your Markdown as text and interprets it, so it does not parse the file into fields. Two things follow from that:
- Structure helps the reader, but it is not machine-enforced. Headings, lists and code spans make instructions easier to find and harder to misread. A tool will not reject a file that skips them.
- Wording matters more than syntax. A malformed table does not crash anything, but an ambiguous sentence can send the agent in the wrong direction.
What "Markdown" means here
You can use the Markdown constructs you already know. The ones that earn their place in an instruction file are listed below.
| Construct | Typical use in AGENTS.md | Why it works |
|---|---|---|
| `#` and `##` headings | Group guidance into Setup, Build and test, Code style, and so on | Lets the agent (and you) locate a rule quickly |
| Bulleted lists | One rule or command per line | Each line is a separate, checkable statement |
| Code spans | Exact commands, paths, flags, identifiers | Marks literal text the agent should copy exactly |
| Fenced code blocks | Multi-line command sequences or short code examples | Preserves line breaks and spacing |
| Tables | Mapping directories to purposes, or tasks to commands | Compact for lookup-style information |
| Relative links | Pointing to longer docs such as `docs/architecture.md` | Keeps the file short and lets the agent read more on demand |
Rendering does not matter. Most of the time nobody views AGENTS.md in a browser, so the file only has to read well as plain text. Avoid decoration that adds characters without adding meaning, such as long rows of emoji or heavy nesting.
A typical layout
The format does not require a layout, but a common one has an H1 title followed by H2 sections. This is the example from the plan for this tutorial:
# AGENTS.md
## Project overview
Web API for invoice processing. TypeScript, Node.js 20, PostgreSQL.
## Setup
- Install dependencies: `npm ci`
- Start the local database: `docker compose up -d db`
## Build and test
- Build: `npm run build`
- Run all tests: `npm test`
- Run one test file: `npm test -- path/to/file.test.ts`
- Lint and type-check before finishing: `npm run lint && npm run typecheck`
## Code style
- Use named exports; do not add default exports.
- Keep route handlers thin and put business logic in `src/services/`.
## Project structure
- `src/routes/`: HTTP handlers
- `src/services/`: business logic
- `migrations/`: database migrations (never edit an existing migration)
## Pull requests
- Add or update tests for every behavior change.
- Use the title format `[area] Short description`.The section names above are conventions, and the later chapters on content and style explain why these sections are worth having. You could rename "Build and test" to "Commands" and nothing would break. What matters is that each heading tells the reader what the lines below it are for.
A few format-level habits make a file easier for both people and models to use:
- Put each command in a code span, and give one command per bullet. A sentence such as "you can run the tests with npm test or maybe pnpm" gives the agent a choice you did not mean to offer.
- Lead with the most important sections. If a tool truncates the file, the end is what gets cut.
- Keep headings descriptive and unique. Two sections both called "Notes" give the reader nothing to navigate by.
- Use relative paths from the repository root, so the same text is true wherever the agent's working directory happens to be.
How a tool reads the file
The diagram shows the usual path from file to agent. Details differ between tools, but the shape is common.
The key point is the step "read as plain text". No tool-specific parser sits between your Markdown and the model, which is why the format has no fields. It also means the file consumes space in the model's context window on every task. Every line you add is read each time, whether or not it is relevant, so the format rewards brevity.
Front matter and comments
Some instruction systems use YAML front matter, a block between --- lines at the top of a file, for metadata such as which files a rule applies to. AGENTS.md does not define front matter. If you add one, a tool that does not expect it will most likely pass it to the model as literal text. That is harmless but wasteful, and it suggests a behavior the file does not have. Keep metadata out of the file, and use directory placement to control scope (a later chapter covers this).
HTML comments such as the one in the following example are valid Markdown, and you can use them for notes aimed at human maintainers:
<!-- Maintainers: update the test command here when the CI job changes. -->
- Run all tests: `npm test`Be careful with them. Whether a tool strips comments before sending the file to the model varies, so assume the model can see them. Never put anything in a comment that you would not want the agent, or a reader of the repository, to see.
File name and encoding
The name is AGENTS.md: uppercase AGENTS, lowercase .md, plural. Three details cause real failures:
- Case sensitivity. Linux file systems treat
agents.mdandAGENTS.mdas different files. A file namedAgents.mdmay work on your macOS or Windows laptop and be ignored in a Linux container or CI runner. - Singular versus plural.
AGENT.mdis a different name, and a tool looking forAGENTS.mdwill not find it. - Encoding. Save the file as UTF-8 without extra markup. Other encodings can turn punctuation or non-ASCII path names into garbage characters.
Size is the other practical limit. Models have finite context windows, and some tools cap how many bytes of instruction files they load. For example, OpenAI's Codex CLI documents a default combined limit of 32 KiB, and anything beyond the cap is silently left out. Check your tool's documentation for its limit. As a rule of thumb, a file that fits on one or two screens is more likely to be read and followed than a file of several hundred lines.
You can check the basics from a shell at the repository root:
# Confirm Git tracks the file under the exact expected name
git ls-files | grep -x 'AGENTS.md' || echo "AGENTS.md is not tracked at the root"
# Check the encoding (expect utf-8 or us-ascii) and the size in bytes
file --mime-encoding AGENTS.md
wc -c AGENTS.md
# Look for front matter that you did not intend to add
head -n 1 AGENTS.md | grep -q '^---$' && echo "File starts with front matter"The first command matters most on teams that mix operating systems. Git on a case-insensitive file system can record a name with the wrong case, and the problem only appears on another machine.
Common errors
These are the format-level mistakes seen most often:
- Wrong name or case, so the tool never loads the file. The symptom is an agent that ignores everything you wrote. Check the name before you rewrite the content.
- Prose paragraphs where commands should be. The agent paraphrases the command or picks a variant. Put the literal command in a code span.
- Commands that only work from a subdirectory, with no note of where to run them. Say where to run them, or use the repository root consistently.
- A file that has grown into a full handbook. Models follow short, specific files better. Link to longer documents instead of pasting them in.
- Invented structure, such as custom tags or pseudo-fields like
[RULE:HIGH]. No tool defines them, and the model has to guess what they mean.
Exercise
A teammate adds YAML front matter with a scope: backend key to the top of AGENTS.md and expects the agent to apply the file only to backend code. Why will this not work as intended, and what should the team do instead?
Show answer
AGENTS.md defines no front matter or fields. The tool reads the whole file as plain text, so the model sees scope: backend as literal text and nothing enforces it. To limit guidance to the backend, place a separate AGENTS.md in the backend directory (for example packages/api/AGENTS.md), so that directory placement defines the scope.
Exercise
Your AGENTS.md works on your Mac, but the agent in the Linux CI runner ignores it. git ls-files shows the file as Agents.md. What is the likely cause, and how do you fix it without losing history?
Show answer
Linux file systems are case-sensitive, so a tool searching for AGENTS.md does not match Agents.md, while macOS often treats them as the same file. Rename it with Git so the change is recorded, using a two-step rename on case-insensitive systems: git mv Agents.md tmp.md && git mv tmp.md AGENTS.md, then commit.