Write Docs for Humans and AI Agents
Updated
Picture a new engineer and an AI coding agent starting on the same repo on the same Monday. The engineer reads the README, asks three questions in chat, and learns that the payments module is off limits until the migration finishes.
The agent reads the same README. Nothing in it mentions payments. In its first hour it refactors the payments module. The rule existed, but it lived in a chat thread that neither the next hire nor the agent could read.
Your docs now have two readers. People skim, ask follow-up questions and remember what they were told. An agent reads what is in front of it, starts fresh every session, and acts on what it finds. Writing for both comes down to organization. Below: how to lay docs out, what the research says to leave out, and a template.
One source of truth, layered
Don't keep one set of docs for people and another for agents. Two sets drift apart, and the agent's copy goes stale first because nobody reads it. Keep one set, and organize it by who needs what, and when.
The layers
Each layer answers a different question and is loaded at a different moment.
- README.md: what this is and how to run it. People read it first. Agents read it too.
- AGENTS.md at the repo root: the short list an agent needs every session. Build and test commands, non-obvious tooling, boundaries, known traps. Claude Code reads CLAUDE.md instead, and that file can import AGENTS.md so you maintain one.
- Nested AGENTS.md files in subfolders of a large repo. In most tools the file closest to the code being edited wins.
- docs/: one topic per file, such as architecture, data model, testing and deployment. Loaded when the task needs it.
- docs/decisions/: decision records. They hold the why, which neither code nor tests can.
- llms.txt: only if you publish a public docs site. It is a curated index of key pages for AI tools. It is a proposal that has not become a standard, and it does not configure coding agents.
Keep the agent file short
Every line in AGENTS.md is read in every session and costs attention. Guides put the ceiling at about 300 lines, and some teams keep theirs under 60. Start with a few lines and add one each time the agent repeats a mistake.
Put in what the agent cannot work out from the code: the exact test command, the package manager you use, files it must not touch, a trap that caught someone before. Leave out directory listings, style rules a linter already enforces, and instructions for one task. Point to a docs file instead, and prefer a file and line reference over pasted code.
Write each page to survive being read alone
An agent often opens one file with no surrounding context. A person who lands from search is in the same position. The same habits help both.
- One topic per page, with a title that says what it covers.
- A first paragraph that summarizes the page.
- Headings that tell you what is under them. "Retry policy" works. "Notes" does not.
- Names that match the code. If the code says invoice_run, don't call it the billing job.
- A status and a date, so a reader can tell a current page from an old one.
- Links to other pages instead of copies of their content.
- The reason next to the rule. People nod at a bare rule. Agents follow it literally, including in cases it was never meant for.
What the research says
A 2025 ETH Zurich paper, "Evaluating AGENTS.md" (arXiv:2602.11988), tested context files on coding tasks. As summarized in Philipp Schmid's write-up, files generated by an AI lowered task success by about 3% and raised cost by more than 20%. Codebase overviews did not help agents find the right files faster. Files written by people helped by about 4% and cost up to 19% more.
The generated files did the most harm when they repeated what the agent could already read in the repo. So write down what is hard to find in the code, and skip what the agent can read in the source. I have not read the paper itself, only this summary of it, so check the numbers there before you quote them.
Keep it current
Update the docs in the same pull request as the change. A stale instruction does more damage to an agent than a missing one, because the agent follows it. When an agent makes the same mistake twice, add a line. When a line stops being true, delete it.
Where Ask Jentic fits
Ask Jentic writes its documentation into its own askjentic_docs folder and leaves your hand-written docs alone. The dependency map, routes, data model and change-impact tables are extracted from your code with no AI model. The overview is AI-written from those facts.
Given the research above, don't paste any of that into AGENTS.md. Link to it from there instead. The parts worth pointing an agent at are the ones it cannot cheaply work out alone, such as what depends on a file and which tests reach it.
Copy-paste layout and AGENTS.md starter
README.md what it is, how to run it (people first)
AGENTS.md short rules for agents, under 60 lines to start
CLAUDE.md one line: @AGENTS.md
docs/
architecture.md how the pieces fit
data-model.md tables, who writes them
testing.md how to run and write tests
deployment.md how releases go out
decisions/
0001-<title>.md decision records (see the ADR guide)
# AGENTS.md
## Commands
- Install: <command>
- Test: <command>
- Lint: <command>
## Boundaries
- Do not edit: <paths>, because <reason>
- Ask before changing: <paths or systems>
## Known traps
- <the mistake that has happened before, and what to do instead>
## More context
- Architecture: docs/architecture.md
- Data model: docs/data-model.md
- Decisions: docs/decisions/Frequently asked questions
Should I use AGENTS.md or CLAUDE.md?
Many coding tools read AGENTS.md. Claude Code reads CLAUDE.md, which can import AGENTS.md with a line that says @AGENTS.md. Keep the content in one file and let the other point to it.
Do I need an llms.txt file?
Only if you publish a public docs site and want AI tools to find its key pages. It does not apply to a code repository.
Can I generate my AGENTS.md with a tool?
The research above found that generated files lowered task success. Write a few lines by hand and add to it as the agent repeats mistakes.
Do I need separate docs for agents?
No. One layered set, with a short AGENTS.md that links to the rest, serves both readers.
Skip the manual work
Ask Jentic keeps a map of your repo and its decisions current on every push, in a folder your agents and your team can both read.