AI Agents and Coding Assistants

Writing Project Instructions That Coding Agents Will Follow

What to put in a coding agent's project instructions file, how to phrase rules and how to find out whether they work.

Key takeaways

  • Write down what a capable newcomer could not guess from reading the code.
  • Give exact commands for building, testing and checking, and say when to run them.
  • State rules concretely, with a reason and an alternative to anything forbidden.
  • Instructions guide behavior but do not enforce it, so protect important things with technical controls.
  • Review the file like code: test it, prune it and keep it current.

Coding agents follow project instructions best when the file is short, specific and testable: the commands to run, the conventions that are not obvious from the code, the places that need care and how to tell that a task is done. Long essays about good practice add little and can bury the rules that matter.

A project instructions file is a plain text document, usually kept in the project's main folder, that a coding tool reads automatically at the start of its work. File names and loading rules differ between tools and change over time, so check your tool's documentation. The writing principles carry across them.

Think of a capable newcomer

Imagine a skilled programmer joining the project this morning with no history. They know the language. They do not know that one folder is generated automatically, that tests need a local database running or that a certain old module must not be touched.

That gap is what the file should fill. The agent can discover much by reading files, but discovery costs time and sometimes goes wrong. A single line saying "edit the files in the source folder; the build folder is overwritten" prevents a whole class of mistakes.

Leave out general advice such as "write clean code" or "be careful." These give no direction. Also skip long descriptions that merely repeat what the code makes plain, since they go stale and compete for the model's attention. A model has a limited amount of text it can work with at once, and instructions take up part of it.

What belongs in the file

What a useful project instructions file covers
Instructions Short, specific, current Done How to verify a finished change Boundaries What needs approval or is off limits Conventions Local choices the code does not show Purpose What the software does and for whom Commands Install, run, test and check Layout Where things live and what is generated Instructions Short, specific, current Purpose What the software does and for whom Commands Install, run, test and check Layout Where things live and what is generated Conventions Local choices the code does not show Boundaries What needs approval or is off limits Done How to verify a finished change

A compact, invented example for a small booking application might read like this.

Purpose: booking system for a community sports hall.

Commands (run from the project root):
- Tests: the "test" script. Run after every change.
- Style check: the "lint" script. Fix errors before finishing.

Layout:
- app/ holds the source. dist/ is generated; never edit it.

Conventions:
- Store times in UTC; convert only when displaying.
- Money is stored as whole cents, never as decimals.

Ask first:
- Changing the database schema or adding a dependency.

Done means: tests pass, new behavior has a test,
and your summary lists every file changed.

Say how to verify the work

Of everything in the file, a reliable way to check results may matter most. An agent that can run a test and read the outcome can correct itself. One that cannot will judge its work by how reasonable it looks.

Name the command, what success looks like and how long it roughly takes if it is slow. If the full test suite is large, explain how to run only the relevant part during work, and require the whole set before finishing.

Mention known traps. If one test fails intermittently for reasons unrelated to most changes, say so, or the agent may spend a long session "fixing" it by weakening it. If tests need a local service, say how to start it and what the error looks like when it is missing.

Where no automated check exists, give a manual one: start the program, open a particular page, compare an output file with a saved example. Then say what the agent should do if it cannot verify. A good rule is to report exactly what was and was not checked, instead of declaring success.

Also describe the report you want at the end: files changed, commands run, results and anything left unfinished. A consistent summary makes your review faster, though you should still read the changes themselves.

Phrase rules so they can be followed

Concrete beats abstract. "Handle errors properly" can mean anything. "When the payment service fails, show the retry message and log the error code; do not swallow the exception" can be checked.

Give a reason where it helps. "Do not edit migration files that have already been released, because live databases have already run them" lets the agent apply the idea to nearby cases that the rule did not name.

Pair a prohibition with the preferred route. "Do not call the database directly from page code; use the functions in the data folder" is far more useful than "no direct database calls."

Point to an example. "Follow the structure of the existing booking handler" often conveys style better than paragraphs of description.

Reserve strong emphasis for the few rules where mistakes are costly. If every line is marked critical, none stands out.

Avoid contradictions and clutter

Files grow by accretion. Someone adds a rule after each annoyance, and after some months two rules conflict, a third refers to a deleted folder and a fourth applied to one task long ago.

An agent facing conflicting instructions may pick either one, or try to satisfy both and satisfy neither. Read the file from top to bottom now and then and ask of each line: is this still true, does it change behavior and is it said elsewhere?

Where your tool supports it, put detailed or area-specific guidance in separate files near the code they describe, and keep the main file brief with pointers. Do not assume a linked document will be read. Say when to read it: "Before changing the payment code, read the payments note."

Instructions are not enforcement

A model usually follows a clear instruction. It does not follow it with the certainty of a program obeying a permission setting. It may overlook a line in a long session, judge that an exception applies or be steered by text it reads elsewhere, such as a malicious comment in a downloaded file.

So use real controls for real risks. Keep production credentials out of reach. Use the tool's permission settings to require approval for destructive commands. Protect the main branch so changes need review. Let automated checks reject code that breaks a rule, since a style checker or test never gets tired of the rule. Approval steps belong around anything you cannot undo.

Never put secrets in the instructions file. It is read into the model's input and is often committed to shared version control.

Test the instructions

Treat the file as something that can be wrong. Give the agent a small, representative task and watch.

Did it use the right test command? Did it edit generated files? Did it ask before adding a dependency? When it fails, work out why. The rule may be missing, vague, buried, contradicted or simply impossible, such as requiring tests that cannot run in its environment.

Fix the file and try a similar task in a fresh session, so that earlier conversation does not do the work the file should do. One success is weak evidence, so repeat with a different task. Testing prompt changes applies the same discipline to any instructions.

You can ask an agent to propose additions after a session, for example "what did you have to discover that should be written down?" Edit the answer firmly. Agents tend to produce more text than is needed.

Rewrite weak lines

Revision usually means turning wishes into checks. These invented pairs show the pattern.

Weak line Stronger line
Follow our style Run the style check and fix all errors before finishing
Be careful with the database Ask before changing tables; never delete rows in scripts
Write tests Add one test for the new behavior and one for bad input
Keep changes small Change only files needed for the task; list any others you think should change
Use the right logger Log through the shared logging module, never by printing to the screen

Each stronger line names an action or a limit that someone could confirm by looking at the result.

Keep it a team document

Commit the file to version control so changes are visible and reviewed. Give it an owner. Update it in the same change that makes it outdated, such as when a command is renamed.

The file also helps people. A new colleague who reads accurate commands, layout and boundaries gets a faster start. If a rule would sound strange or unclear to a person, rewrite it, since it is probably unclear to the model too. Writing instructions for agents outside software follows much the same logic.

Common questions

How long should the file be?

Long enough to cover what a newcomer cannot guess, and no longer. For many small projects a page is plenty. If it keeps growing, move specialized material into separate notes.

Why did the agent ignore a rule?

Common causes are a vague phrase, a conflicting line, a very long session or a rule placed where the tool did not load it. Check what the tool actually read, if it can show you, and consider whether an automated check should enforce the rule instead.

Written for 4ArtificialIntelligence with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 46 articles in AI Agents and Coding Assistants →

Latest news on this topic