Sub topic 2
Persistent project instructions as a baseline
This chapter assumes you have used an AI coding agent in an editor or terminal, that you can read Markdown and simple YAML, and that you know what a context window is from the previous chapter. It covers the instruction file that sits under every other mechanism in this tutorial: a Markdown file in your repository that the agent reads at the start of every session.
What persistent project instructions are
A persistent project instruction file is a plain Markdown file stored in your repository. The agent loads it automatically, so you don't have to paste the same rules into each conversation.
The most common convention is a file named AGENTS.md at the repository root. Other tools use their own names or locations. Examples are CLAUDE.md, .github/copilot-instructions.md, and a folder of "steering" or "rules" files. File names, supported locations, and whether a tool reads several files differ by product. Check your tool's documentation before you rely on a name.
These files share one property: they are loaded without being asked for. That separates them from the other mechanisms in this tutorial.
| Mechanism | Who triggers it | Cost in context |
|---|---|---|
| Persistent instructions | The tool, at session start | Always paid, every session |
| Prompt file | You, by invoking it | Paid only when invoked |
| Custom agent | You or the tool, by selecting it | Paid while that agent is active |
| Skill | The agent, when the task matches | Short description always, body only when used |
The first row is the key trade-off. Persistent instructions are the only mechanism that is reliable without anyone remembering to invoke it. The price is that every line competes for space in the context window in every session, whether or not that line is relevant.
How the file reaches the model
When a session starts, the tool gathers the instruction files that apply, adds them to the context, and only then handles your first message. The model has no memory of earlier sessions, so the file is the only way project knowledge persists.
Because the text is simply placed in the context, the model treats it as strong guidance, not as a guarantee. A rule like "never edit generated files" can still be broken, especially in a long session or when the file is crowded with other rules. If a rule must never be broken, enforce it with tool permissions, which a later chapter covers, and use the instruction file as a second layer.
What belongs in the file
Write down what the agent cannot cheaply work out by reading the code. Good candidates are:
- Commands. How to build, run tests, lint, and format. Agents guess these wrongly more often than anything else.
- Conventions that differ from defaults. For example, "use
pytestfixtures, notunittestclasses." - Layout hints. Which directory holds what, when the structure isn't obvious.
- Boundaries. Files or folders the agent must not touch, such as generated code or vendored libraries.
- Workflow rules. Branch naming, commit message format, and what to run before declaring a task done.
Leave out what the model already knows ("write clean code"), anything that the code or a linter already enforces, and long reference material. Reference material belongs in a separate file that the instructions point to, or in a skill.
A worked example
This example is for a hypothetical Python service. The commands are illustrative, so replace them with your own.
# Project instructions
Orders API: a FastAPI service with a PostgreSQL database.
## Commands
- Install: `pip install -e ".[dev]"`
- Run tests: `pytest -q`
- Run one test file: `pytest tests/test_orders.py -q`
- Lint and format: `ruff check . && ruff format .`
## Conventions
- Put route handlers in `app/routes/`, and keep business logic in `app/services/`.
- Use `pydantic` models for all request and response bodies.
- Every new endpoint needs a test in `tests/`.
## Boundaries
- Do not edit anything in `app/generated/`. Regenerate it with `make codegen`.
- Do not change files in `migrations/` that are already committed. Add a new migration instead.
## Done means
- `pytest -q` passes and `ruff check .` reports no errors.Notice the shape. It is short, each line is a checkable instruction, and the last section tells the agent when it may stop. Compare "keep the code well organized" with "put route handlers in app/routes/." The second can be followed and verified. The first cannot.
Scope and layering
Many tools support more than one level of instructions. The typical pattern is:
- A user-level file that applies to all your projects, such as personal style preferences.
- A repository-root file that applies to the whole project.
- Files in subdirectories that apply only when the agent works there.
The subdirectory level is useful in monorepos. A frontend/AGENTS.md can describe the JavaScript toolchain, while backend/AGENTS.md describes Python, and neither pollutes the other's context. Whether subdirectory files load at session start or only when the agent reads files in that folder depends on the tool. Test this in yours.
When levels disagree, the outcome is tool-specific. Some tools let the closer file win, and others concatenate everything and leave the model to reconcile it. Avoid depending on that behavior: do not write a root rule that a subdirectory file contradicts.
The instruction budget
The previous chapter introduced the idea that context is limited. Here is what it means in practice for this file.
- The file is paid for on every request in a session, in tokens and in the model's attention.
- Attention is not uniform. A rule buried among fifty others is less likely to be followed than one among ten.
- Adding rules has diminishing returns. Past some size, new rules dilute the old ones.
A workable habit is to treat the file like a budget. For each line, ask whether the agent would make a mistake without it, and delete the line if not. Many teams aim for a file that fits comfortably on one screen or two. That is a rule of thumb and not a limit set by any tool.
When the file grows, move content out in this order:
- Task-specific procedures go into a reusable prompt file, loaded only when invoked.
- Role-specific behavior goes into a custom agent.
- Detailed, occasionally needed knowledge goes into a skill, or into a reference file that the instructions link to by path.
The instruction file then keeps only what applies to nearly every task.
Common errors
Contradictions. A file that says "always add tests" in one section and "keep changes minimal, do not add files" in another leaves the model to guess. Read the file top to bottom for conflicts whenever you add a rule.
Stale commands. The file says npm test after the project moved to pnpm. The agent follows the file and fails. Treat the file as code: update it in the same pull request that changes the build.
Vague style advice. "Write idiomatic code" costs tokens and changes nothing. Replace it with a specific, checkable rule or remove it.
Emphatic capitals as a substitute for enforcement. Writing "NEVER" in capitals adds little. If the rule matters, restrict the tool or add a check in CI.
Secrets in the file. The file is committed and sent to the model provider as part of the context. Never put tokens, passwords, or private URLs in it.
Assuming other tools read it. A CLAUDE.md is not necessarily read by a tool that expects AGENTS.md. If your team uses more than one tool, keep one source of truth and check whether the others can read it, for example through a symbolic link or an import line. Support for this varies.
Summary
Persistent project instructions are the always-on baseline. They suit facts and rules that apply to almost every task, and they cost context in every session. Keep them short, specific, and verifiable. Move anything occasional or bulky into the mechanisms that load on demand, which the next chapters introduce.
Exercise
Your AGENTS.md has grown to 400 lines. It includes a 60-line procedure for preparing a release, a 40-line guide to the database schema, and the build and test commands. The agent often ignores the test commands. Which parts would you move out of the file, and where would they go?
Show answer
Keep the build and test commands in AGENTS.md, because they apply to almost every task. Move the release procedure to a reusable prompt file, because you invoke it only when releasing. Move the database schema guide to a skill, or to a reference file that AGENTS.md links to in one line, because it is bulky and needed only for some tasks. A smaller file leaves less competing text around the test commands, so the agent is more likely to follow them.
Exercise
A teammate adds "Never modify files in app/generated/" to AGENTS.md, then finds that the agent edited one anyway during a long session. What are two sensible responses?
Show answer
First, check the file for conflicting rules or a crowded layout, and make the rule specific by adding how to regenerate the files, for example "run make codegen instead." Second, enforce the boundary outside the instructions, for example by restricting the agent's write permissions on that folder or adding a CI check that fails when generated files change by hand. The instruction file guides the model but does not guarantee compliance.