Sub topic 11
Keeping AGENTS.md current
This chapter assumes you have already written an AGENTS.md with setup, build, test and style sections, and that you know basic Git and pull request workflows. It covers how to keep the file accurate as the codebase changes.
Why stale instructions cost more than none
An agent treats AGENTS.md as true. If the file says npm run lint and the script was renamed to npm run check, the agent runs a command that fails. It may then guess a fix, skip the step, or report that checks passed when they never ran.
A missing instruction makes the agent explore the repository. A wrong instruction sends it down the wrong path with confidence. Keeping the file accurate matters more than keeping it long.
What drifts
Some parts of the file change more often than others. Check these first.
| Section | Typical cause of drift | Signal that it drifted |
|---|---|---|
| Commands | Script renamed, tool replaced | The agent's command exits with "missing script" |
| Versions | Node or database upgrade | Setup steps fail on a clean machine |
| Project structure | Directories moved or split | Agent edits files in the wrong folder |
| Style rules | Linter config changed | Rules in the file contradict lint output |
| PR conventions | Team adopts a new title format | Reviewers keep correcting the same thing |
Prefer instructions that point at a single source of truth. "Run npm run lint" survives a change of linter, because only package.json changes. "Use ESLint with the airbnb config" breaks as soon as the config does.
Update the file in the same pull request
The most reliable habit is to treat AGENTS.md like code. When a change alters a command, a directory or a convention, the same pull request updates the file.
Add a line to your pull request template so reviewers ask the question every time.
## Checklist
- [ ] Tests added or updated
- [ ] AGENTS.md updated if commands, structure or conventions changedYou can also tell the agent to do this. A short rule in the file itself works well.
## Keeping this file current
- If you rename a script, move a directory or change a convention, update this file in the same change.Catch broken commands automatically
Commands are the easiest part to check by machine. A small script can extract the inline commands from AGENTS.md and confirm that each npm script exists.
#!/usr/bin/env bash
# check-agents-md.sh: fail if AGENTS.md mentions an npm script that package.json lacks
set -euo pipefail
status=0
for script in $(grep -oE 'npm run [a-zA-Z0-9:_-]+' AGENTS.md | awk '{print $3}' | sort -u); do
if ! node -e "process.exit(require('./package.json').scripts['$script'] ? 0 : 1)"; then
echo "AGENTS.md references missing script: $script"
status=1
fi
done
exit $statusRun it in continuous integration so a renamed script fails the build until the file is fixed. This only checks that scripts exist. It does not check that the commands succeed or that the prose is right.
Treat agent mistakes as bug reports
When an agent does the wrong thing, ask whether the file could have prevented it. If the agent put business logic in a route handler, the style section may be missing a rule. If it ran the full test suite for a one-line change, add the single-file test command.
Fix the file, then rerun the same task. If behavior improves, keep the change. This is a cheap feedback loop, and it turns real failures into precise instructions.
Prune as well as add
Files grow because adding is easy. Every few months, read the file top to bottom and remove:
- Rules the linter or formatter now enforces automatically.
- Descriptions of directories that no longer exist.
- Temporary notes such as "do not touch the billing module until the migration ends."
- Duplicates between the root file and nested files.
A shorter file is read more reliably, and each remaining line is easier to verify.
Exercise
A teammate renames the typecheck script to tsc:check in package.json. AGENTS.md still says "Run npm run lint && npm run typecheck before finishing." Name two ways to prevent this from reaching an agent unnoticed.
Show answer
First, require that the same pull request updates AGENTS.md, enforced with a pull request checklist item. Second, add a CI check, such as the script in this chapter, that fails when AGENTS.md references an npm script that is missing from package.json.
Exercise
An agent keeps adding default exports even though AGENTS.md says to use named exports. What should you check and change before blaming the agent?
Show answer
Check whether the rule is stated clearly and specifically, and whether a nested AGENTS.md closer to the edited files contradicts it. Then rewrite the rule concretely, for example "Use named exports; do not add default exports", rerun the task, and keep the change only if the behavior improves.