How to Write a Project Instructions File (CLAUDE.md) That Keeps AI on Track
Every new AI session starts with a blank memory. It doesn't remember that your project uses a certain database, that prices are always in Canadian dollars, or that you told it last week never to change the sign-in page without asking. So you explain it again. And again. And the one time you forget, it gets it wrong.
A project instructions file fixes that. It's a plain text file in your project that the AI reads at the start of every session. In Claude Code it's called CLAUDE.md; other tools have their own versions. It's the difference between a clever assistant and a consistent one.
What it's for
Anthropic's documentation describes CLAUDE.md as the place you write down what you'd otherwise re-explain. It loads automatically at the start of each session, and a project's file can be shared with the whole team.
Two things to know:
- It's guidance, not a lock. The AI treats it as instructions and usually follows them, but it isn't enforced like a setting. For rules that must never be broken, use the tool's actual safety features, and check the work.
- Shorter is better. A long file gets skimmed by the AI, just like by a person. Anthropic suggests keeping it to about 200 lines.
What to put in it
- How to run the project. The commands to start it, test it and build it.
- How it's organized. Where the main pieces live, in a few lines.
- Your conventions. Naming, formatting, spelling (Canadian, say), currency, date formats.
- Your rules. Things to always do and never do: "ask before changing anything in billing", "never delete data without confirming".
- How you want it to work. "Ask questions instead of making assumptions." "Show every place a change will touch." "Run the tests before saying a task is done."
- Mistakes not to repeat. When the AI gets something wrong twice, add a line so it doesn't happen a third time.
Make every line checkable
Vague instructions get vague results. The documentation's examples make the point well: "use 2-space indentation" beats "format code properly", and "run the tests before committing" beats "test your changes."
A good test for each line: would removing it make the AI more likely to make a mistake? If not, cut it.
A starter template
# Project: Booking tool for [business]
## Run and test
- Start locally: npm run dev
- Run tests: npm test (run before saying any task is done)
## Layout
- Pages: src/pages/ · Shared parts: src/components/ · Data: src/data/
## Conventions
- Canadian spelling. Prices in CAD, shown as $1,500 CAD.
- Dates shown as Nov 28, 2026.
## Rules
- Ask questions instead of making assumptions.
- Before changing anything, list every page and file it affects.
- Never change sign-in, payments or data deletion without asking first.
- Never put passwords, keys or tokens in the code.
## Lessons learned
- The booking calendar uses Mountain Time. Don't convert to UTC on screen.
What to leave out
A short file gets followed. A long one gets skimmed. Leave out:
- Things the AI can see for itself, like a list of every file. It can read the project.
- General advice such as "write clean code". It changes nothing.
- Long explanations of why. One line of reason is enough.
- Rules for rare tasks. Put those in a separate file and point to it.
- Secrets. Never put passwords, keys or tokens in an instructions file.
- Anything out of date. A rule that's no longer true does more harm than no rule.
What a real one looks like after a few months
A file that's been used grows a "lessons learned" section, and that section becomes the most valuable part. Each line is a mistake that happened once and shouldn't happen again. Some examples of the kind of line that earns its place:
## Lessons learned
- Always work from the current version of a file, never an older copy.
(An old copy once undid approved corrections.)
- After saving a file, read it back and confirm the change is there.
- When a check fails, fix the cause. Don't change the check to pass.
- Show visible changes as a mockup and get approval before building.
- Don't mark a task done until it has been tested and the result shown.
Lines like these come from this website's own project files. None of them would occur to you on day one. All of them came from something going wrong.
Keep it alive
- Start small. Claude Code can generate a first draft from your project with the
/initcommand. Trim it to what matters. - Add a line every time you correct the same mistake twice.
- Prune it. If a rule is out of date, delete it. Old rules confuse.
- Keep it with the project, so everyone working on it, people and AI, gets the same instructions.
Beyond the main file
As a project grows, some instructions only apply sometimes: how to release, how to add a new report. Keep those in separate files the AI reads when the task calls for it, rather than cramming everything into the main one. A short set of written process files is also what makes AI work repeatable: the same task, done the same way, every time.
Common questions
What is a CLAUDE.md file? A plain text file in your project that Claude Code reads at the start of every session. It holds the instructions you'd otherwise repeat: how to run the project, your conventions, and your rules.
Where does it go? In the main folder of your project, so it's shared with everyone who works on it. You can also keep personal instructions that apply to all your projects.
How long should it be? As short as you can make it. Anthropic suggests around 200 lines at most. Many good ones are far shorter.
Do other AI coding tools have the same thing? Most do, under different names. The contents carry over: commands, conventions, rules and lessons.
Does the AI always follow it? Usually, not always. It's guidance. For anything that must never happen, check the work and use the tool's permission settings.
Related guides: make the AI ask first, testing AI-written software and running several AI threads at once.
The bottom line
A good project instructions file is an hour of work that pays off in every session after. Write down what you'd otherwise repeat, keep each line specific, and update it whenever the AI makes the same mistake twice.
This is part of my guide to building software with AI. If you'd rather have a project set up properly from the start, see how a custom build works, or book a call.