4.8GuidePart of Build a website with AI coding agents: the practical guide
CLAUDE.md best practices, with an example file
A CLAUDE.md holds what Claude Code can't learn from your code. Here is what to put in it, what to leave out, and a full example for an Astro site.

On this page9 sections
A CLAUDE.md is a plain Markdown file in your project that Claude Code reads at the start of every session, so you don’t have to repeat yourself. The best practice fits in one rule: write down only what Claude can’t learn from your code, such as the commands that check its work, the rules that are easy to break and the decisions that live in your head. Keep it short, and move anything that must happen every time into a hook or a deny rule, because Claude treats this file as context, not as enforced configuration.
This guide is part of Build a website with AI coding agents.
What is a CLAUDE.md file?
It is a text file, in the same format as a README. You keep it in your project’s top folder. There is nothing to install.
Claude Code is a coding agent: a tool that reads and edits your code. You work with it in sessions, and a session is one conversation. Each session starts with a fresh context, and context is everything Claude has in view while it works. So your commands, house rules and past corrections are gone unless they’re written down. Claude Code keeps some notes of its own, called auto memory. A CLAUDE.md is the part you write yourself and share with your project.
So what should you write down, without burying Claude in instructions? The docs explain why it matters: every line takes a little of Claude’s attention on every task, whether it’s relevant or not.
The file is a note, not a lock. Claude usually follows it, and it is also allowed to decide that a line doesn’t apply. That is why the rest of this guide asks two questions of every line: does it belong in the file at all, and is the file strong enough for it?
What to put in a CLAUDE.md
The docs list four things. Here is each one, with an example from an Astro site:
- How to confirm the work. The exact build, type-check and test commands:
pnpm check,pnpm build. - Where the code misleads. “Site search works in
pnpm preview, not inpnpm dev.” Without that line, Claude would test search in the wrong place. - Decisions that aren’t in the repo. “Pushing to
maindeploys the live site.” Nothing in the code says so. - Anything you’ve corrected twice. If you’ve told Claude twice not to hard-code a color, that is now a line in the file.
Write each line so that it can be checked. The docs say the more specific a line is, the more consistently Claude follows it.
| Vague | Checkable |
|---|---|
| Test your changes | Run pnpm check and pnpm build before you call it done |
| Follow the design | Don’t hard-code colors. Use the design tokens |
| Keep files organized | Images go in content/media/ |
What to leave out
The test: if Claude can learn it by reading the repo, cut it.
Folder tours and architecture overviews fail that test. The docs list “Describe your architecture and file layout in CLAUDE.md” under old advice you can stop following, and /doctor proposes cutting directory layouts, dependency lists and architecture overviews. A folder note is still fine when the code misleads, such as a directory that looks unused but isn’t.
You will see other advice. Many templates still include a folder map, and so does Anthropic’s own 2025 post. The docs aren’t uniform either: the memory page still lists “project layout” among the facts to keep. We follow the stricter advice, with the “where the code misleads” exception.
There is some evidence for it. One study of these context files found that they don’t generally raise task success and that they add cost. It also found that repository overviews didn’t help, and that the files are useful for non-standard practices. It measured coding tasks in software repositories, not site work in particular.
How long should the file be? The docs say longer files use more context and get followed less well. Stop when every line passes the test.
Example CLAUDE.md for an Astro site
Here is a CLAUDE.md for a personal site made from Vesper, our free theme. Commands and theme rules come from the AGENTS.md that ships with Vesper. Only the “My site” block is the owner’s. We ran pnpm check, pnpm test:units, pnpm test:skins and pnpm build on the theme on November 6, 2026.
There are two versions, and they are for different projects:
- The full file is the model for a project with no AGENTS.md. Copy its shape and swap in your own commands and rules.
- The short version, further down, is for a project that already has an AGENTS.md. A copy of Vesper does, so a Vesper owner uses that one.
# Personal site (Astro, Vesper theme)
## Commands
- Install: `pnpm install`
- Dev server: `pnpm dev` (http://localhost:4321)
- Build: `pnpm build` (a static site in `dist/`, then Pagefind indexes it)
- Serve the build: `pnpm preview`
- Type-check: `pnpm check`
- Unit tests: `pnpm test:units`
- After look or color changes: `pnpm test:skins`
## Styling
- Change the look and accent in `src/theme.config.ts`.
- Use the design tokens (`--ui-*`, `--v-*`). Don't hard-code colors.
- Don't use Tailwind's `dark:` variant. Dark mode swaps the token values.
## Gotchas
- Site search works in `pnpm preview`, not in `pnpm dev`.
- The setup check stops the build on a broken setting. Fix the setting. Don't turn the check off.
- Set `SITE_URL` before a real build. The feed, sitemap and share images use it.
## My site
- Pushing to `main` deploys the live site.
- Never invent facts about me: dates, jobs, quotes, numbers. Ask me.
- Fill `[[fill in: …]]` markers only with facts I give you.
## Before you call a change done
1. `pnpm check`, `pnpm test:units` and `pnpm build` pass.
2. Open the changed page in `pnpm dev`, in light and dark mode and at phone width.
CLAUDE.md
## Commands
How Claude checks its work
## Styling
Rules that are easy to break
## Gotchas
What Claude can't learn from the code
## My site
Decisions that live in your head
## Before you call a change done
What "done" means on this project
Left out on purpose: the framework list, the folder layout and “write clean code.” Claude can read the first two, and the last can’t be checked.
Short version for a project with an AGENTS.md
AGENTS.md is the shared instruction file that many coding agents read. By default, a CLAUDE.md with no import stops Claude Code reading it, and the full example would repeat its commands. So a Vesper owner adds only what the theme can’t know:
@AGENTS.md
## My site
- Pushing to `main` deploys the live site.
- Never invent facts about me: dates, jobs, quotes, numbers. Ask me.
AGENTS.md vs CLAUDE.md explains how the two files work together.
How to create and check the file
- Run
/init. It writes a first version from your code, or suggests changes if a file exists. Or write the file by hand from the example. - Cut. The docs say the work from there “is mostly removing lines”.
/doctorsuggests cuts. - Add what
/initcan’t know. That means your decisions and your gotchas. - Run
/context all. Check that the file is listed under Memory files. - Commit it, so everyone on the project gets it.
Where other rules go
Some rules don’t belong in the file even when Claude can’t learn them from the code. Four other places cover most of them:
| Place | What it is | Example |
|---|---|---|
| Hook | A command Claude Code runs at a fixed point, such as after an edit | Run the formatter after every edit |
| Deny rule | A setting that blocks an action, whatever Claude decides | Never read .env |
| Path-scoped rule | A rule file that loads when Claude works with matching files | Alt text on post photos |
| Skill | A saved procedure that loads when it’s needed | Your release steps |
Can Claude learn it from the code?
Yes
Leave it out
No
Must it happen every time?
Yes
Hook or deny rule
No
Only for part of the project?
Yes
Path-scoped rule
No
A procedure you run sometimes?
Yes
Skill
No
Keep it in CLAUDE.md
A rule for one part of the project. .claude/rules/posts.md loads only when Claude works with a post:
---
paths:
- "content/posts/**/*.md"
---
- Every `thumbnail` needs a `thumbnailAlt` that describes the photo.
- Images go in `content/media/`.
A rule for every time. This is .claude/settings.json, adapted from the docs’ own example:
{
"permissions": {
"ask": ["Bash(git push *)"],
"deny": ["Read(./.env)", "Read(./.env.local)"]
}
}
The file says what a push does. The setting makes Claude Code ask before one.
These rules match commands, not intent. The .env rule catches cat .env, but it won’t catch a script that opens the file. The push rule catches git push origin main, but not git -C . push origin main. For anything security-related, the docs suggest the sandbox as well.
Don’t overdo it. The docs say a hook is for a rule with zero exceptions. A preference shouldn’t be one, so it stays in the file and Claude decides.
How to keep it up to date
Add a line when:
- Claude repeats a mistake.
- A code review catches something Claude should have known.
- You retype a correction.
- A new teammate would need the same fact.
Cut a line when a command changes or the line stops mattering.
/doctor prompt-audit reports outdated lines and contradictions. It changes nothing until you ask.
Common mistakes
Writing a tour of the project. Claude reads the repo itself.
Keeping /init’s output as it is. It’s a first draft.
Adding IMPORTANT and ALL CAPS. The docs list this as old advice: it mostly makes Claude over-apply the rule. Shorten the file, or make the line a hook or a deny rule.
Trusting a sentence with something serious. The docs say “Never read .env” is followed almost every time. Claude Code applies a deny rule every time.
Splitting the file with imports to save space. An imported file loads in full. Path-scoped rules load only when they’re needed.
Letting two lines disagree. The docs say “Claude may pick one arbitrarily.”
What to do next
- Small new project, no file yet: you can wait. The docs say a plain prompt in a fresh session usually does the right thing. Add a file the first time you repeat a correction.
- Using only Claude Code: keep one CLAUDE.md at the root, with commands, gotchas, your decisions and what “done” means.
- Using more than one agent, or your project ships an AGENTS.md: keep the shared rules there, and make
@AGENTS.mdthe first line of a short CLAUDE.md. - A rule Claude keeps missing: first shorten the file. If it’s still missed, or can’t have exceptions, make it a hook or a deny rule.
To see where this file fits in the rest of the work, read Build a website with AI coding agents.


