Skip to content
mentoor

Topic 1 of 5 · 4 min read

Commands, conventions and boundaries worth writing down

Goal: Draft a memory file for a repository that lists the exact build and test commands, the conventions an agent would otherwise get wrong, and the files it must not touch.

A memory file should hold only what the agent cannot work out by reading your code: the exact commands, the house rules it would get wrong, and the places it must not touch.

Check yourself · 1 of 3

Which line is the best candidate for a repository memory file?

Choose one answer

Why it matters

A coding agent such as Claude Code, Codex, Copilot or Cursor starts every session with no memory of your project. It reads files, guesses, and acts. Most of what it needs is in the code. A few things are not: which command runs the tests, that your team forbids default exports, that generated/ is rebuilt by a script. A memory file (CLAUDE.md, AGENTS.md or a similar file) is loaded at the start of each session, so these facts are in front of the agent before its first guess.

What to write

Think of the first day of a new hire. Write down what you would tell them out loud.

  1. Commands, exact and copyable. Install, build, run one test file, run the full suite, lint, typecheck. Say which are slow. An agent that guesses npm test in a pnpm repo wastes a turn and may install the wrong thing.
  2. Conventions that differ from the default. Not "write clean code", but "errors use AppError, never throw new Error" or "dates are UTC strings in the API, Date objects only in the UI layer".
  3. A short map. Two or three lines on where things live and what each folder is for. Point to a longer doc rather than copying it.
  4. Boundaries. Files and actions that are off limits: migrations that are already applied, vendored code, the lockfile, production config, "never run db:reset".
  5. Workflow rules. Branch naming, commit style, "run the typecheck before you say you are done".

Before and after

Weak:

# Project
This is a web app. Please write good, clean, well-tested code and follow best practices.

Better:

# Orders API
- Install: `pnpm install`. Test one file: `pnpm vitest run path/to/file.test.ts`.
- Full suite takes about 6 minutes; run it only before you finish.
- Errors: throw `AppError(code, message)` from `src/errors.ts`. Never throw plain `Error`.
- Never edit `src/generated/` by hand. Run `pnpm gen` instead.
- Applied migrations in `db/migrations/` are immutable. Add a new one.

The first version tells the agent nothing it did not already assume. The second removes four likely mistakes.

What goes wrong

  • Writing for humans in general. Mission statements and tone guides cost tokens and change nothing.
  • Leaving out the command that matters. The agent runs the whole suite after every edit, or none at all.
  • Rules without a reason. "Do not use library X" is followed better, and applied more sensibly, with "because it breaks our bundle size budget".
  • Documenting only wishes. If a rule is not true of the current code, the agent will follow the file and the code will disagree.

A good test for every line: would the agent make a mistake without it? If not, delete the line.

Examples

A short, useful root file

# Billing service
- Run one test: `pytest tests/test_invoice.py -k refund`. Full suite: `make test` (about 4 min).
- Format with `ruff format` before committing; CI rejects unformatted code.
- Money is integer cents in code and the database. Never use float.
- Do not edit `vendor/` or applied files in `migrations/`.
- Architecture notes: see `docs/architecture.md`.

Five commands and rules, one pointer. Each line prevents a specific mistake.

Boundaries with a reason

Instead of "Be careful with the database", write: "Never run pnpm db:reset or any command that drops tables. The local database holds seed data that takes an hour to rebuild. Ask first." The agent now knows the action, the cost and what to do instead.

Key points

  • A memory file is loaded at the start of every session, so it should hold facts the agent cannot infer from the code.
  • Exact, copyable commands for install, one test, full tests, lint and typecheck save the most wasted turns.
  • Write conventions that differ from the default, not generic advice such as write clean code.
  • State boundaries plainly: generated files, applied migrations, lockfiles and destructive commands.
  • For every line ask whether the agent would make a mistake without it, and delete the line if not.

Common mistakes

  • Filling the file with generic advice (be clean, be careful) that the model already follows or ignores.
  • Listing commands from memory without running them, so the file points at scripts that no longer exist.
  • Writing a rule with no reason, so the agent cannot judge edge cases.
  • Describing the intended architecture instead of the real one.

Check yourself · 2 of 3

An agent keeps editing files in src/generated/, and they get overwritten at the next build. What is the best fix?

Choose one answer

Check yourself · 3 of 3

Why add a reason to a rule, such as 'because it breaks our bundle budget'?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic