Sub topic 5
Writing instructions an agent can act on
This chapter assumes you know basic Git and repository layout, are comfortable with Markdown, and run build and test commands from the command line. You should also have used an AI coding assistant before. It covers how to turn general advice into instructions that an agent can follow and a reviewer can check.
Why wording matters
An agent reads AGENTS.md as part of its working context. It cannot ask you what "clean code" means. If an instruction is vague, the agent guesses. If it is concrete, the agent can act on it and check its own work.
A good instruction has three properties:
- Concrete: it names an exact command, path, or pattern.
- Concise: it fits in one line and does not repeat what the code already shows.
- Verifiable: someone can tell whether it was followed.
Rewrite vague guidance
Compare a vague instruction with concrete replacements.
<!-- Vague: hard to act on or check -->
- Write clean code and test it properly.
<!-- Concrete: an agent can follow it and a reviewer can verify it -->
- 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.The vague line has no command to run and no definition of "properly". The concrete lines name the command, the location, and the condition for being done. A reviewer can look at a pull request and answer yes or no.
A process for rewriting
Use these steps on each line of your file.
- Ask what the agent would do differently if the line were missing. If nothing changes, delete it.
- Replace adjectives such as "clean", "proper", or "good" with a command, a path, or a rule.
- Name the exact command, including flags, as you would type it.
- State the finish condition, such as "all tests pass" or "no new lint errors".
- Check that the line is true today. Run the command yourself.
Give commands in full
Agents often fail because they guess the wrong command. List the ones you actually use, and include the narrow variants that save time.
## Build and test
- 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`The single-file command matters. Without it, an agent may run the whole suite after every small edit, which is slow.
Be specific about style
Do not restate rules that a linter or formatter already enforces. Put those in the lint command instead. Spend your words on rules a tool cannot catch, and make each one specific.
## Code style
- Use named exports; do not add default exports.
- Keep route handlers thin and put business logic in `src/services/`.Each rule tells the agent what to do and what to avoid. "Keep route handlers thin" is still somewhat subjective, but it names the destination for the logic, so the agent can act on it.
Keep it short
Long files get skimmed, by people and often by agents. Aim for the smallest file that prevents real mistakes. A useful test is to add a line only after you have seen an agent get that thing wrong.
Common errors
| Problem | Example | Fix |
|---|---|---|
| Vague adjective | "Write good tests" | Name the file pattern and the command |
| Missing command | "Run the linter" | Give the full command with flags |
| Stale instruction | A script that was renamed | Run it and correct the line |
| Duplicated tooling rule | "Use two-space indents" when a formatter enforces it | Point to the format command instead |
| Unverifiable goal | "Make it fast" | State a measurable target or remove it |
Exercise
Exercise
Rewrite this instruction so an agent can follow it and a reviewer can verify it: "Make sure the code is well tested and follows our conventions." Assume a TypeScript project that uses npm test and npm run lint, and keeps business logic in src/services/.
Show answer
One acceptable answer is two lines. "Run npm run lint && npm test before finishing; fix any failures you introduced." and "New public functions in src/services/ need a unit test in the matching *.test.ts file." Each line names a command or location, and a reviewer can check each one by looking at the pull request or the command output.
Exercise
A line in your AGENTS.md says "Run npm run check-all before committing", but the script was renamed to npm run verify last month. What is the risk, and what should you do?
Show answer
The agent will run a command that fails and may skip the check or invent a substitute. Update the line to npm run verify, and run the command to confirm it works. Treating AGENTS.md changes like code changes helps catch this when scripts are renamed.