Building with agents, lesson 5.1
CLAUDE.md and AGENTS.md: what goes where
Every session starts blank, so an agent reads a file of instructions first. This lesson shows which files it reads, in what order, and what earns a line in them.
Every example below changes to fit what you pick. The businesses are made up for teaching.
The picture, one step at a time
Each box is one stage. The picture lights up as you scroll.
Where an agent's instructions come from, broadest first
1Your organisation's file
Set by IT for every developer on the machine. Read first.
2Your own file
Your preferences for every project, kept in your home folder.
3The project file
CLAUDE.md or AGENTS.md at the top of the repo, shared with the team in git.
4Your private notes
CLAUDE.local.md: notes for you alone in this project, kept out of git.
5A folder's own file
Read only when the agent starts working in that folder.
The project file: read at the start of every session.
Step 1 of 6
Every session starts blank
An agent remembers nothing from yesterday. Each session starts with an empty context window: the text it can hold in mind for one conversation. So it reads an instruction file first, a plain text file with what it needs to know about your shop's website. Write it once, and you stop repeating yourself.
Step 2 of 6
Two names for one job
CLAUDE.md is Claude Code's file. AGENTS.md is an open format that many other coding agents read, including Codex, Cursor, Gemini CLI and GitHub Copilot's coding agent. If your team uses more than one, keep the shared notes in AGENTS.md. Then make a CLAUDE.md whose first line is @AGENTS.md, which pulls that file in, and add anything only Claude needs below it.
agents.md says the format is used by over 60,000 open-source projects, and is now looked after by the Agentic AI Foundation, part of the Linux Foundation (as of November 2026).
Your repo has an AGENTS.md. You add a CLAUDE.md with a few notes of your own. What does Claude Code read now, by default?
Step 3 of 6
The files stack up
There can be more than one file. An organisation can set one for every developer. You can keep one for all your projects. The project has the one your team shares. The agent reads them all, broadest first. None replaces another, so if two lines disagree it may follow either. Keep them consistent.
Step 4 of 6
Your private notes
Some things are true only for you: the address of your own test copy, how you like changes explained. Put them in CLAUDE.local.md and add it to .gitignore, the list of files git leaves out. It is read with the project file but never shared. Keep passwords and keys out of all of these files.
Step 5 of 6
A folder can have its own file
In a big repo, a rule for one part should not take up attention everywhere. Put a file in that folder. Claude Code reads it only when the agent starts working there. Other agents follow the same idea with AGENTS.md: the file closest to the code being changed wins.
Step 6 of 6
What earns a line
Ask two questions of every line. Could the agent find this by reading the code? Would it actually go and look? If both answers are yes, leave it out. What stays: the exact commands to check work, places where the code misleads, decisions made outside the repo, and anything you have had to correct twice.
Anthropic's docs suggest keeping each file under 200 lines, because longer files take up more of the agent's attention and are followed less well (as of November 2026).
You wrote "NEVER edit the payments file" in capitals, and the agent still did it once. What now?
Where does this line go?
Here are four things you might want the agent to know about your work. Sort each one into where it belongs, or leave it out.
1The exact command that runs only the checkout tests.
2The address of your own test copy of the shop, and the test card you like to use.
3Never edit the file that holds the live payment keys.
4The site is built with a popular web framework, and the code is in the src folder.
0 of 4 right so far, 4 to go.
A CLAUDE.md starter
This is what you keep: what goes in the file, in order, and the test every line has to pass.
A CLAUDE.md starter
- Start with the commands that check work: install, run one test file, run all the tests, the type check and the linter.
- Add the places where the code misleads: an old pattern not to copy, a folder that looks unused but is not.
- Add decisions made outside the repo: how deploys work, which helper the team chose, what needs a person's review.
- Add anything you have had to correct twice.
- Put your own notes in CLAUDE.local.md, kept out of git. If your team uses several agents, share AGENTS.md and pull it into CLAUDE.md.
- Stay under 200 lines. Move rules for one folder into a file in that folder.
For every line, ask: could it find this by reading the code? If yes, cut it. If it must never be broken, make it a hook.
Next: Lesson 5.2: Hooks: lint gates, test runs, guardrails. How to make the rules that cannot be broken run every time.