Sub topic 12
Turning Repeated Corrections into Project Instructions
This chapter assumes you can review an agent's diff with Git, give corrective feedback, and run your project's tests and linter. You should also have used a coding agent at least once. Here you will learn to move corrections you keep repeating out of chat messages and into a file the agent reads at the start of every run.
Why repeated corrections belong in a file
A corrective message fixes one run. The agent does not carry it into the next session. If you have written "don't touch files outside the task" or "run pytest before you report" three times, the fourth run will need the same message.
Most coding agents read a project instruction file when a session starts. The name depends on the tool. Common names are AGENTS.md, CLAUDE.md, and a rules file under a tool-specific directory. Check your tool's documentation for the exact name and location. Because the file lives in the repository, it is versioned, reviewed in pull requests, and shared with your team.
Decide what deserves a rule
Not every correction should become a rule. Add one when a mistake has happened at least twice, or once with a costly result, and when you can state the fix as a check someone could verify.
| Correction you gave | Worth persisting? | Reason |
|---|---|---|
| "Run `pytest -q` and report the result" | Yes | Same command every time, easy to verify |
| "Don't skip tests to make them pass" | Yes | A recurring failure mode with a clear boundary |
| "Rename `load` to `load_config` in this file" | No | Applies to one task only |
| "Write better code" | No | Not checkable |
Write rules the agent can follow
Good rules are specific, bounded, and verifiable. They use the same qualities as the corrective message from earlier chapters. State the command, the path, or the prohibited action.
# Project instructions
## Commands
- Run tests with `pytest -q`. Run the linter with `ruff check .`.
- Run both before reporting a task as finished, and include the exact commands and their results in your report.
## Scope
- Change only files named in the task, plus tests for them.
- If another file needs a change, stop and say so instead of editing it.
## Tests
- Never add `@pytest.mark.skip`, `@pytest.mark.xfail`, `# noqa`, or `# type: ignore` to make a check pass.
- If a test fails, fix the code. Change a test only when the task says its expected behavior changes.
## Dependencies
- Do not add new packages. Use only APIs that exist in the installed versions.Each rule maps to a failure you can detect in review. The scope rule counters scope creep. The test rule counters weakened tests. The dependency rule counters invented APIs and unrequested packages.
Keep the file short
The instruction file shares the agent's attention with your task. A long file with dozens of rules dilutes the ones that matter, and some rules will conflict. Keep it to the rules you have actually needed. Prefer commands and paths over general advice. Remove a rule when the problem it addressed no longer appears.
Check that the rule works
A rule is a hypothesis. After adding one, watch the next runs.
- Add the rule in its own commit so you can revert it.
- Run a similar task on a clean branch.
- Review the diff for the failure the rule targets.
- If the failure persists, make the rule more specific, or move the check into something enforced, such as a CI job or a pre-commit hook.
Exercise
You have corrected the same mistake in three runs: the agent edits src/billing/ when the task is about src/config/. Write one instruction-file rule that addresses it, and name one way to enforce it outside the agent.
Show answer
A rule such as "Change only files under the directories named in the task. If a change is needed elsewhere, stop and report it instead of editing." It is specific, bounded, and checkable. To enforce it outside the agent, add a CI check or pre-commit hook that fails when a change touches paths outside an allowed list, or use CODEOWNERS and branch protection to require review for src/billing/.