Write a CLAUDE.md before your first prompt
An AI coding agent starts every session knowing nothing about your system. It finds out by looking around, and it fills the gaps with assumptions. Most agent mistakes I have seen come from those assumptions, not from bad code.
A short rules file, read at the start of every session, removes most of them. In Claude Code the file is called CLAUDE.md and lives in the project folder.
What goes in it
Four things earn their place:
- Where things are. The folders that matter, as full paths.
- What not to touch. The parts that look like clutter but are in use.
- How to verify. What "done" means, and how to check it.
- How to work. For example one change at a time, and a backup before larger edits.
A real example
The rules file for this website is about sixty lines. Four of them:
- Web root (absolute path): /var/www/sysapp.dk/httpdocs - The web root also holds a device backend, used by hardware in the field over plain http. Website work must not touch it. - One change at a time; verify against the live site before calling it done. - Make a dated backup of index.html before larger edits.
The second line matters most. A folder next to the website serves devices in the field, and those devices speak plain http. When the website got its redirect to https, that path was left out on purpose. The rule is written down so that no later session "tidies it up" and takes the devices offline.
Use absolute paths
An agent runs its commands in a non-interactive shell. The aliases and shortcuts from your own shell profile are usually not loaded there, so a command that works when you type it can fail, or do something else, when the agent runs it. Write the full path and the full command in the rules file.
Keep it short, keep it current
A rules file is not documentation. If it grows to ten pages, the important lines drown.
- When the agent makes a mistake that a rule would have prevented, add the rule.
- When a rule no longer applies, delete it.
- Put the open items in the file too, so the next session starts where the last one stopped.
Ten minutes on a rules file before the first prompt is the cheapest safety measure I know for agent work.