Project instruction files: purpose and contents
Explain that an instruction file (CLAUDE.md, AGENTS.md, ...) is read automatically at session start, which fixes the 'it forgets every session' problem. Write a short one covering how to build, run and test, key conventions, folders to leave alone, and recurring mistakes. Keep secrets and long prose out of it, and update it whenever the agent repeats an error.
Builds on: What the agent can and cannot see, How a code project is laid out, What automated tests are and how to run them
Why does it forget what you told it?
Yesterday you told the agent that tests run with `pytest -q` and that it must never edit `data/raw/`. It followed both rules. Today you open it again in the same project and ask for a small fix. It tries a different test command, gets confused, then edits a file in `data/raw/`. You never changed your mind. Why did it 'forget', and how do you stop repeating yourself every time?
A note it reads every morning
A new session starts fresh: yesterday's chat is not in its context, so anything you only said in chat is gone. An **instruction file** fixes this. It is a plain text file, usually in the project root, such as `CLAUDE.md` or `AGENTS.md` (the name depends on the tool). The agent loads it into its context automatically at the start of every session. Think of a note taped to the desk for a new helper each morning.
What goes in, what stays out
Keep it short and specific. Include only what the agent can't easily guess from the code:
1. **Build, run, test**: the exact commands.
2. **Conventions**: naming, style, where things go.
3. **Leave alone**: folders or files it must not edit.
4. **Known mistakes**: errors it has made before.
Leave out **secrets** like passwords and API keys. The file is plain text. It is sent to the AI model behind the agent every session, and it is often shared with everyone on the project. Also leave out long prose, which buries the rules.
A short instruction file
An `AGENTS.md` for a small Python project. Every line is something the agent would otherwise guess, or has already got wrong. The `#` and `##` headings are Markdown and only group the lines. Ten clear lines beat three pages.
# Notes for the agent
## Run and test
- Run the app: `python main.py`
- Run tests: `pytest -q` (all must pass)
## Conventions
- Dates are text in `YYYY-MM-DD` form
- Shared helpers live in `src/utils/`
## Leave alone
- `data/raw/` (original files, never edit)
## Known mistakes
- New tests go in `tests/`, not `src/`
It repeats a mistake: update the file
For the third time, the agent leaves debugging `print()` lines in its finished code. Correcting it in chat only lasts until the session ends. So write the rule down instead:
▸ You: Add to AGENTS.md under Known mistakes: remove any print() debugging lines before finishing.
Open `AGENTS.md` and read the new line yourself. It should say something like `- Remove print() debugging lines before finishing`. The next time you start the agent and ask for a change, check whether stray `print()` lines still appear.
Remember
The agent forgets your chat between sessions but reads the instruction file every time. Keep it short: exact run and test commands, conventions, folders to leave alone, and known mistakes. Keep secrets and essays out. Add a line whenever it repeats an error. The file is strong guidance, not a lock, so still check what the agent does.
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.