Rules file

Definition
A document an AI coding agent reads on every task, stating your conventions, your stack and the things it must never do.

Why it matters

Without one, the same correction is repeated every session: use British spelling, do not copy a component, check the tests before saying it is done. A rule written once applies to every future task, which makes this one of the cheapest improvements to working with an agent. It also gives a non-engineer a way to steer the work. Plain sentences in a file change what the agent does.

How to apply it

  • Add a rule each time a correction has to be repeated. Repetition is the sign that a rule is missing.
  • Write rules as concrete instructions. "Run the type check before finishing" works better than "write good code".
  • Put the traps first, the parts of the stack where the agent goes wrong by default.
  • Keep the file short enough to read in a minute. Long files dilute the important rules.
  • Point to a longer record, such as a decisions table, for detail that does not need to load every time.

What it is

An AI coding agent has no memory of earlier sessions. Each time it starts, it knows nothing about how a particular business writes code, which tools it uses or which mistakes it has made before. A rules file fixes this. It is a plain text document kept with the project that the agent loads automatically before it starts work. Common names are CLAUDE.md and AGENTS.md, depending on the tool.

A good rules file is short and specific. It might say which language to write in, how to spell things on the site, where the key records live, which commands to run before finishing and which actions need approval first.

Common mistakes

  • Writing aspirations instead of instructions.
  • Letting the file grow with outdated rules that contradict newer ones.
  • Putting secrets in it. The file is read by the agent and often stored in the repository.
Worked example

Suppose a six-person agency uses an AI coding agent to build client websites. Twice in one week the agent writes American spelling into British copy and commits changes without running the type check. Instead of correcting it a third time, the founder adds three lines to a rules file at the root of the repository: write in British English, run the type check before finishing, and never change the production database without approval. Claude Code reads that file at the start of each task. Over the next month the same two corrections stop appearing, and the founder spends the saved time reviewing results. The file stays under one page, with the riskiest rules at the top.

Tools in the example

Some links are affiliate links: we may earn a commission at no cost to you. It never decides a ranking. How we work with partners

  1. Article

    Context engineering

    Deciding what a model sees, of which a rules file is one standing part.

  2. Article

    AI coding agent

    The kind of agent the file is written for.

  3. Article

    System prompt

    The equivalent standing instruction in a chat product.

  4. Article

    Spec-driven development

    A companion habit of writing down intent first.