Sub topic 13
Common pitfalls
This chapter assumes you have read the earlier chapters. You should know what AGENTS.md is, what belongs in it, how nested files and precedence work, and how to check that an agent follows it. You should also be comfortable with Git, Markdown, and build and test commands in a terminal.
Most AGENTS.md problems come from a few repeated mistakes. Some make the file useless, some make it misleading, and a few make it unsafe. Each section below names a pitfall, shows how it looks in practice, and gives a fix.
Pitfalls at a glance
| Pitfall | Typical symptom | Fix |
|---|---|---|
| Vague instructions | Agent does something plausible but not what you wanted | Name exact commands and paths |
| Bloated file | Agent ignores rules buried in a long document | Keep only what the agent cannot infer |
| Stale commands | Agent runs a script that no longer exists | Check commands in CI |
| Conflicting files | Different results depending on which directory is edited | Put each rule in one place |
| Duplicate tool files | CLAUDE.md and AGENTS.md disagree | Use a symlink or an import |
| Secrets in the file | Credentials end up in Git history | Reference variable names only |
| Rules that need enforcement | Agent breaks a rule occasionally | Move the rule into a linter or CI |
| Never tested | You assume the file works | Run a small task and observe |
Vague instructions
The most common problem is advice that sounds sensible but gives the agent nothing to act on. "Write clean code" and "test thoroughly" cannot be followed or checked. The agent will fall back on its own habits, which may not match your project.
## Code style
- Write clean, readable code.
- Make sure everything is tested properly.
- Follow best practices.The fix is to name the command, the location, or the observable condition:
## Code style
- Use named exports; do not add default exports.
- Run `npm run lint && npm test` before finishing; fix any failures you introduced.
- New public functions in `src/services/` need a unit test in the matching `*.test.ts` file.A useful test is to ask whether a reviewer could look at a pull request and say yes or no to the instruction. If they could not, the agent cannot follow it reliably either.
Writing too much
An instruction file is read as part of the agent's working context, and every line competes with the task and the code. A file that grows to hundreds of lines tends to hide the few rules that matter. It also invites contradictions.
Cut anything that falls into one of these groups:
- Facts the agent can discover by reading the repository, such as a list of every file in
src/. - General programming advice that applies to any project.
- Long rationale and history. Keep the rule, and link to a design document if the reasoning matters.
- Rules your formatter or linter already applies automatically.
A good compact file covers setup, build, test, a handful of specific style rules, the directory layout, and pull request conventions. If a section needs more than a page, it probably belongs in a separate document that AGENTS.md points to.
Stale commands and paths
An AGENTS.md file is documentation that nothing compiles. When you rename npm run typecheck to npm run tsc, the file keeps saying the old thing. The agent then runs a failing command, and it may work around the failure in a way you did not intend, such as skipping the check.
Treat command drift as a test failure. This script reads every npm run <name> mentioned in AGENTS.md and confirms that the script exists in package.json:
#!/usr/bin/env bash
set -euo pipefail
grep -oE 'npm run [a-zA-Z0-9:_-]+' AGENTS.md | sort -u | while read -r _ _ name; do
if ! node -e "process.exit(((require('./package.json').scripts) || {})['$name'] ? 0 : 1)"; then
echo "AGENTS.md mentions a missing script: $name"
exit 1
fi
done
echo "All npm scripts mentioned in AGENTS.md exist."Run it in CI so a rename breaks the build until the file is updated. It only checks script names. Paths, flags, and non-npm commands need their own checks, or a reviewer who knows to look for them. A simple habit also helps: when a pull request changes build tooling or directory layout, the checklist asks whether AGENTS.md needs an edit.
Conflicts between files
Nested files add a second source of trouble. The nearest file applies to the code being edited, and an explicit instruction in the user's prompt overrides the files. That precedence is well defined, but only if your files do not contradict each other.
Consider this pair:
# AGENTS.md (root)
## Test
- Run tests with `npm test`.# AGENTS.md (packages/web)
## Test
- Run tests with `yarn test`.An agent working in packages/web/ follows the nearer file. An agent working at the root follows the other one. The result depends on where the agent happens to be, and a person reading both files will be confused too.
Three habits prevent this:
- Put repo-wide rules in the root file only.
- In nested files, add package-specific commands and rules, and say whether repo-wide rules still apply.
- If a nested file really must override the root, say so explicitly and give the reason.
Also watch for commands that only work from a particular directory. npm test --workspace packages/web runs from the repository root. The same text in a nested file is a trap if the agent's working directory is the package. State the directory when it matters.
Letting tool-specific files drift apart
Teams often have AGENTS.md for some tools and CLAUDE.md for others. If both contain full, hand-written instructions, they will diverge. One gets a new test command and the other does not, and different tools then behave differently on the same repository.
Keep a single source of truth. The simplest option is a symbolic link:
ln -s AGENTS.md CLAUDE.mdIf you also need notes for one tool, make the tool-specific file import the shared one and add only the differences:
# CLAUDE.md
@AGENTS.md
## Claude-specific notes
- Prefer running the single-file test command while iterating.Check that your tools support the mechanism you pick. Symlinks can behave differently on some operating systems and Git configurations, and the @ import syntax is a feature of specific tools, not part of Markdown. Whichever you choose, verify it by asking each tool to report the instructions it loaded.
Putting secrets and risky guidance in the file
AGENTS.md is committed to the repository, so everyone with read access sees it, and so does its Git history. Do not put API keys, passwords, tokens, connection strings with credentials, or private URLs in it. Name the environment variable and say where a developer gets the value:
## Configuration
- The API reads `DATABASE_URL` from `.env` (copy `.env.example`).
- Never commit `.env`. Do not print its contents in logs or pull request text.If a secret reaches the file, deleting it in a later commit is not enough. Rotate the credential, because it remains in history.
The second kind of risk is guidance that widens what the agent may do. Examples are "run any command without asking", "force push to fix conflicts", or "delete the database volume if tests fail". Instruction files are trusted input, so a careless line there acts like a standing permission. Keep destructive actions out, and prefer lines that narrow behavior, such as "never edit an existing migration".
Finally, review changes to AGENTS.md like code changes. In a project that accepts outside contributions, a pull request that quietly alters the instructions can change how every later agent session behaves.
Using the file for rules that must be enforced
An instruction is a request, not a guarantee. An agent can miss a rule, misread it, or lose track of it in a long session. If breaking a rule would be costly, such as committing a secret, skipping the formatter, or editing a migration, do not rely on the file alone.
Put the check in a place that runs regardless of the agent: a pre-commit hook, a linter rule, a CI job, or branch protection. Then use AGENTS.md to tell the agent the check exists, so it can run the check itself and fix problems before a human sees them. The two layers work together. The file reduces failures, and the automated check catches the ones that remain.
Never testing the file
The last pitfall is assuming the file works because it reads well. Agents can fail to find a nested file, follow an old copy, or ignore a rule that is phrased ambiguously. You only learn this by watching one.
The diagram shows a quick way to diagnose a rule the agent did not follow.
To run a basic test, give the agent a small task that exercises one rule, for example "add a function to src/services/ and finish the task". Then check the outcome: did it run the lint and test commands, add a test in the right file, and use named exports? Repeat the task after each edit to the file, and keep a short list of such probe tasks for the rules that matter most. Do this in each tool your team uses, because they differ in how they discover and merge files.
A short review checklist
Before merging a change to AGENTS.md, ask these questions:
- Can every instruction be answered with yes or no on a pull request?
- Does every command run as written, from the stated directory?
- Does any nested file contradict the root file or another nested file?
- Is there exactly one source of truth for tools that read other filenames?
- Is the file free of secrets and of permissions that widen the agent's authority?
- Are the costly rules also enforced by a linter, hook, or CI job?
- Has an agent completed a probe task using the updated file?
Exercise
A root AGENTS.md says "Run tests with npm test." The file packages/api/AGENTS.md says "Run tests with pnpm test." An agent editing packages/api/src/user.ts runs the wrong command in one session and the right one in another. Name two problems in this setup and how you would fix each.
Show answer
First, the two files conflict. The nearest file (packages/api/AGENTS.md) should win for files under that package, but an agent that is at the repository root or does not load the nested file will follow the root rule. Fix it by deciding which tool the repository uses, then stating the rule once in the root file, with a nested override only if the package truly differs, and saying so explicitly. Second, nothing checks the commands. Add a CI step, similar to the script in this chapter, that validates that the commands mentioned in the files exist, and run a probe task in the package to confirm the agent uses the intended command.
Exercise
Your AGENTS.md contains the line "Never commit secrets." Why is this not enough, and what two additions would make it effective?
Show answer
It is a request that the agent can miss, and it gives no actionable detail. Add a concrete instruction, such as "Read DATABASE_URL from .env (copy .env.example); never commit .env". Also add enforcement outside the agent, such as a pre-commit hook or CI secret scanner, and mention in AGENTS.md that the check exists so the agent can run it.