Learning how to write CLAUDE.md well is less about prose style and more about deciding what must survive across sessions. A strong project-levelCLAUDE.md tells an agent how this repository works: toolchain, layout, verification commands, and hard boundaries. A weak one repeats generic “be careful” advice the model already knows—or buries ticket-only instructions that go stale the next day.
01
Independence note
02
Why a project-level CLAUDE.md exists
Coding agents forget your house style between chats. Humans also forget which command is canonical after a toolchain bump.CLAUDE.md (when your tooling loads it) is a shared checklist: “here is how we build, test, and refuse unsafe help.” Put facts that are true for the whole repo—not the narrative of last week’s bug.
- Stack pin: Node/pnpm versions, package manager, SSG vs SSR assumptions.
- Source of truth: which file registers routes, sitemap, or feature flags.
- Done checks: the exact commands reviewers will run.
- Non-goals: deploy, DNS, secret files, out-of-scope packages.
For the broader delivery loop—brief, explore, change, verify, land—see the coding agent workflow section in the agent engineering series.
03
Persistent project memory vs one-shot prompts
| CLAUDE.md (project) | One-shot agent prompt |
|---|---|
| Stable across tickets and contributors | Scoped to this session’s objective |
| “Always register pages in pages[]” | “Add /good-claude-md/ with FAQ this PR only” |
| Safe defaults and forbidden operations | Acceptance checks for the current change |
| Updated when the repo’s process changes | Discarded when the PR merges |
If you paste the entire ticket into CLAUDE.md, you will fight stale instructions forever. If you omit repo contracts from every prompt and have no project file, every session re-learns your indent and build command the hard way. Use both layers. Session craft is covered in how to write a good agent prompt; IDE session habits in cursor agent tips; editor rule files in cursor rules examples.
04
A CLAUDE.md outline you can copy
Start from this skeleton. Delete sections you do not need; fill paths and commands with your repository’s reality.
# CLAUDE.md — project notes for coding agents
## Stack
- Node 22+, pnpm (see package.json packageManager if present)
- Hono JSX + Vite + Hono SSG → static dist/; no server runtime in prod
## Layout
- Routes + sitemap: src/index.tsx pages[]
- Pages: src/pages/*.tsx
- Static CSS/JS/images: public/
## Commands
- Dev: pnpm dev
- Typecheck: pnpm check
- Build: pnpm run build
- Do not deploy unless explicitly asked
## Conventions
- 4-space indent
- Mirror existing EN how-to pages for new docs
- Unique Title/Description; one H1 with the target phrase
- Bidirectional Related reading links to sibling guides
## Non-goals / safety
- No wrangler/Cloudflare/DNS changes unless requested
- No secrets in prompts, commits, or screenshots
- Do not invent indexed URLs beyond the task list
## When stuck
- Ask; do not invent a second router, package manager, or deploy path
- Prefer reading a sibling page before inventing a new layoutTeams that also run Codex-style CLIs often keep parallel notes for profiles and home directories—see Codex CLI multi-config and Codex cloud agent integration when runtime isolation matters.
05
How to write CLAUDE.md well
- Lead with verification. Put the build/test commands near the top so agents see them early.
- Name files, not vibes. “Edit
src/index.tsxpages[]” beats “update routing somehow.” - Write non-goals as hard stops. Deploy, DNS, and secret files are classic accidental “helpful” edits.
- Link exemplars. Point at one good page or PR; agents copy structure better than abstract essays.
- Keep it skimable. Short bullets over paragraphs; humans must maintain this file.
- Separate tool policy. If the agent can call MCP tools, say when to use them; see the MCP server tutorial.
06
Keep it alive
- After a toolchain change (Node, package manager, CI), update commands the same day.
- When the agent invents a wrong path twice, add an explicit pointer—then delete fluff elsewhere to stay short.
- Review
CLAUDE.mdin PRs that change conventions, not only in “docs” PRs. - Do not paste entire API references; link or point at the file that owns the schema.
Related reading: How to write AGENTS.md · How to write GEMINI.md · AGENTS.md vs CLAUDE.md vs Cursor rules · Cursor rules examples · Cursor skills examples · Good agent prompts · Cursor agent tips · MCP server tutorial · Agent engineering notes · Codex cloud integration
07
FAQ
Is CLAUDE.md the same as a system prompt?
Conceptually it is project-scoped durable instruction, not a one-shot chat message. Product loading rules differ by tool; this guide treatsCLAUDE.md as a committed project memory file you maintain like README conventions.
Should every detail go into CLAUDE.md?
No. Ticket goals, temporary experiments, and “only for this customer” notes belong in the session prompt. Put durable contracts inCLAUDE.md; put acceptance for this change in the prompt.
How does this relate to Cursor rules?
Both encode durable guidance. Cursor-oriented teams often use .cursor/rules examples; Claude Code-oriented workflows often use CLAUDE.md. Many repos keep overlapping facts in sync. Prefer one clear statement of each convention rather than three conflicting copies. For how to write AGENTS.md itself, see how to write AGENTS.md; for a fuller comparison, see AGENTS.md vs CLAUDE.md vs Cursor rules.
What length is “enough”?
Enough that a new agent session can build, find the route registry, and avoid forbidden actions without guessing—usually one to two screens of dense bullets, not a novel. If nobody wants to update it, it is too long.