Sub topic 11
Keeping AGENTS.md current
This chapter assumes you can write a basic AGENTS.md (covered earlier), you know Git and pull request review, and you run build and test commands from the command line. Here you learn why instruction files go stale, how to catch drift, and how to make updates part of normal work.
Why instructions go stale
An AGENTS.md file describes a codebase at one moment. The codebase keeps changing, and the file does not change unless someone edits it. Unlike code, a stale instruction does not fail a build. An agent reads it and acts on it.
Typical causes of drift:
- A script is renamed, for example
npm testbecomesnpm run test:unit. - A directory is moved or split, so the "Project structure" section points at paths that no longer exist.
- The team adopts a new tool, such as a different linter or package manager.
- A style rule is dropped in practice but stays in the file.
- A runtime version is upgraded, such as Node.js 20 to 22.
The cost is concrete. An agent told to run a missing command wastes a turn, then guesses. Worse, it may follow an outdated rule and produce code that a reviewer must reject. Because agents read the file on every task, a wrong line is repeated every time.
Treat the file as code
The most reliable habit is to treat AGENTS.md like source code. It lives in the repository, so it gets the same tools as everything else:
- Changes go through pull requests and review.
- History in Git shows when and why a rule was added.
- Owners can be assigned, for example with a CODEOWNERS entry.
- Checks can run in continuous integration (CI).
A CODEOWNERS entry makes sure someone who understands the workflow reviews changes to the file:
# .github/CODEOWNERS
/AGENTS.md @your-org/platform-team
/packages/api/AGENTS.md @your-org/api-team
/packages/web/AGENTS.md @your-org/web-teamNested files from a monorepo belong to the team that owns that package. This keeps the root file short and keeps package rules close to the people who know them.
Update the file in the same pull request
The cheapest time to update AGENTS.md is when the change that invalidates it is made. The author knows what changed, and the reviewer can see both edits together.
Add a line to your pull request template:
## Checklist
- [ ] Tests added or updated
- [ ] If this PR changes build, test, lint or setup commands, directory layout or conventions, AGENTS.md is updatedA good rule of thumb: if a change would make a new teammate's onboarding notes wrong, it makes AGENTS.md wrong too.
| Change in the pull request | Section of AGENTS.md to check |
|---|---|
| Renamed or added an npm script | Build and test |
| Moved or created a top-level directory | Project structure |
| Replaced a linter, formatter or framework | Code style, Build and test |
| Changed the required runtime version | Project overview, Setup |
| Changed branch, title or review rules | Pull requests |
| Added a package to a monorepo | Nested AGENTS.md for that package |
Verify commands automatically
Most drift is in commands and paths, and both can be checked by a script. The following script extracts every inline command from the "Build and test" section that starts with npm run and confirms that the script exists in package.json. It also checks that each backticked path ending in / exists.
#!/usr/bin/env python3
"""Check that npm scripts and directories named in AGENTS.md still exist."""
import json
import re
import sys
from pathlib import Path
root = Path(__file__).resolve().parent.parent
text = (root / "AGENTS.md").read_text(encoding="utf-8")
scripts = json.loads((root / "package.json").read_text(encoding="utf-8")).get("scripts", {})
problems = []
# Every `npm run <name>` mentioned must be defined in package.json.
for name in sorted(set(re.findall(r"npm run ([\w:.-]+)", text))):
if name not in scripts:
problems.append(f"npm script not found in package.json: {name}")
# Every `path/` in backticks must exist as a directory.
for path in sorted(set(re.findall(r"`([\w./-]+/)`", text))):
if not (root / path).is_dir():
problems.append(f"directory not found: {path}")
if problems:
print("AGENTS.md is out of date:")
for p in problems:
print(f" - {p}")
sys.exit(1)
print("AGENTS.md references look valid.")Save it as scripts/check_agents_md.py and run it in CI:
# .github/workflows/agents-md.yml
name: Check AGENTS.md
on:
pull_request:
paths:
- "AGENTS.md"
- "**/AGENTS.md"
- "package.json"
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: python3 scripts/check_agents_md.pyThis check has limits. It does not know whether npm test still runs the right tests, and it ignores commands that are not npm run. It catches the most common failure, a renamed script or moved folder. It also does not replace running the commands for real, which the next section covers.
Run the documented commands
A static check proves a name exists. Only running the command proves it works. Pick the commands in your "Setup" and "Build and test" sections and execute them in a clean environment on a schedule, for example weekly, or when the file changes.
A clean environment matters. A command that works on your laptop may rely on a global tool or an environment variable that the file never mentions. A fresh CI container exposes those hidden dependencies, and you can then add them to the file.
Learn from agent mistakes
Your agents are a free source of feedback. When an agent does something wrong, ask whether a missing or unclear line caused it.
- Note the mistake: the agent edited an old migration, used a default export, or ran the whole test suite for a one-line change.
- Find the cause: was there no rule, a vague rule, or a rule buried in a long file?
- Fix the file with a specific instruction, such as "Never edit an existing file in
migrations/; add a new one." - Confirm that the fix works by repeating the task (see the verification chapter).
Do not add a rule for every one-off mistake. A rule earns a place if the mistake is likely to repeat, costs real review time, or is hard to notice. Otherwise the file grows into a wall of text that agents and people skim past.
Keep the file short while it grows
Files tend to grow. Each incident adds a line, and nobody removes any. Long files cost more than reading time: they use up the agent's context window, and important rules get less attention among many minor ones.
Use these practices to prune:
- Delete rules a tool enforces. If the linter already rejects default exports, the file need not say so. Keep the command that runs the linter instead.
- Move package-specific rules down. Put them in a nested AGENTS.md so they load only when the agent works in that package.
- Link instead of copy. Point to a longer document, such as
docs/architecture.md, for background. Keep AGENTS.md for what an agent must do. - Merge duplicates. Two rules that say nearly the same thing invite contradictions.
- Remove history. "We used to use Jest" is not an instruction. Delete it.
A useful review question for each line: "If this line were missing, what would go wrong, and how likely is it?" If the answer is "nothing much", cut the line.
Avoid contradictions between files
With nested files, a rule in a package file can conflict with the root file. The nearest file wins, but the agent still sees both in many tools, and conflicting text causes unpredictable behavior. When you change a rule at the root, search nested files for the same topic:
# Find every mention of a topic across all instruction files
grep -rn --include="AGENTS.md" --include="CLAUDE.md" -i "default export" .If you keep tool-specific files such as CLAUDE.md alongside AGENTS.md, import or symlink them as described earlier so there is one copy of each rule to update. Two separate copies will drift apart.
Date and own the file
Small signals help maintainers. Some teams add a short footer:
<!-- Owner: platform-team. Last reviewed: 2026-11-01. Review quarterly. -->A comment is not a guarantee, but it tells a reader when someone last checked the file and who to ask. Pair it with a recurring calendar reminder or a scheduled issue so a review happens even when no one touches the file.
A lightweight review routine:
- Run the reference checker and the documented commands.
- Read the file top to bottom as if you were new to the project.
- Remove or fix every line you cannot confirm.
- Compare against the last few weeks of merged pull requests for changes that should have updated the file.
- Update the "Last reviewed" date.
Common mistakes
- Updating only the root file after a change that also affects a nested file.
- Documenting a command that works only on one machine. Check it in a clean environment.
- Letting the file become a changelog. Describe the present state, not the history.
- Relying on memory. Without a checklist item, a CI check, or a schedule, updates do not happen.
- Fixing a symptom twice. If two incidents have the same cause, rewrite the existing rule instead of adding a second one next to it.
Exercise
Your team renames the script npm run lint to npm run lint:all in package.json. AGENTS.md still says "Run npm run lint && npm test before finishing." Name two mechanisms from this chapter that would catch this before it misleads an agent, and say what each one catches that the other might miss.
Show answer
First, the reference-check script run in CI would flag that lint is no longer a script in package.json, so the pull request fails. It catches name mismatches automatically but cannot tell whether the command behaves correctly. Second, the pull request checklist item ("if this PR changes build, test or lint commands, update AGENTS.md") prompts the author and reviewer to update the file while the change is fresh. It catches changes the script cannot parse, such as a changed style rule or a new directory convention, but depends on people following it. A scheduled run of the documented commands in a clean environment would also catch it, because npm run lint would fail.
Exercise
An agent keeps adding default exports even though AGENTS.md says "Use named exports." The linter does not check for default exports and the file is 400 lines long. What two changes would you make, and why?
Show answer
Add a lint rule (for example, one that forbids default exports) so a tool enforces the convention, then shorten the AGENTS.md line to point at the lint command instead of relying on prose. Also prune the file: move package-specific content into nested AGENTS.md files and delete low-value lines, so the important rule is not lost among 400 lines. After the changes, repeat the same task and check that the agent now uses named exports.