AI ToolsOctober 22, 2026

Learning how to write a CLAUDE.md file takes about ten minutes, and it pays you back every single day after that. Every Claude Code user knows the frustration: you explain your project’s build command, folder layout, and house rules on Monday, and by Friday a fresh session has forgotten all of it. The fix is permanent and simple. Claude Code reads a CLAUDE.md file at the start of every session in your project, so you brief the assistant once, in writing, instead of repeating yourself forever. This guide shows what belongs in the file, what to leave out, and how to structure it so Claude actually follows it.

What a CLAUDE.md File Is and Where It Lives

CLAUDE.md is a plain markdown document that Claude Code loads into context automatically when a session starts in a project. The standard location is the root of your repository, next to your README. You can also keep a personal global version in your home configuration for preferences that apply to every project, and nested files inside subfolders that add rules for that part of the codebase. When several files apply, Claude combines them, with the more specific instructions taking priority for their area.

  • Place the main CLAUDE.md in your repository root for project-wide rules.
  • A personal global file holds preferences that apply across all projects.
  • Nested files in subfolders add local rules for that part of the codebase.
  • Write it like an onboarding brief for a smart new developer.

Think of it as the onboarding document you would hand a new developer on their first morning, compressed down to what actually changes behaviour. A new hire needs the build commands, the test commands, the architecture in five sentences, and the handful of rules that are not obvious from the code itself. Claude needs exactly the same things, and suffers from exactly the same problem without them: it guesses. Every guess it does not have to make is a bug, a style violation, or a wasted question you never see.

Developer writing a CLAUDE.md file and project notes on a laptop for Claude Code

The Sections Every Good CLAUDE.md File Needs

Start with commands. List the exact commands to install dependencies, run the project, run tests, run a single test, lint, and build — copied from your real setup rather than typed from memory. A command you typed from memory is a command Claude will run wrong. Second, add a short architecture overview: what the project does, the main folders and what lives in each, and the one or two data flows that matter most. Third, write your conventions: naming patterns, error handling style, how you structure commits, and any libraries to prefer or avoid, each stated as a short, direct instruction.

  • List exact install, run, test, lint, and build commands first.
  • Summarise the architecture and main folders in a few direct sentences.
  • State conventions as instructions, not as essays about why they exist.
  • Dedicate a section to gotchas and traps that are invisible in the code.

Finish with the gotchas, the section that saves the most pain. Every project has traps: the file you must never edit because it is generated, the environment variable tests need before they will pass, the legacy module with surprising behaviour, the migration that must run before the server starts. These are invisible in the code and obvious to you, which makes them perfect CLAUDE.md material. Keep each entry to a line or two. If a section grows into paragraphs of background reading, it belongs in your docs, linked rather than pasted.

Markdown document open in an editor showing a CLAUDE.md file structure

How to Write a CLAUDE.md File That Claude Actually Follows

Claude follows instructions best when they are specific, positive, and short enough to stay in mind. Write “run npm test before finishing any change” instead of “remember testing is important”. Write “use the existing apiClient wrapper for network calls” instead of vague advice about consistency. Prefer telling it what to do over what not to do, except for genuine prohibitions, which should be few and clearly marked. Put the most important rules near the top, because a long file dilutes attention just like a long meeting does.

  • Write specific, positive instructions with exact commands and file names.
  • Keep the file lean, roughly fifty to two hundred lines for most projects.
  • Put critical rules near the top where they carry the most weight.
  • Prune monthly: remove the obvious, the outdated, and the ignored.

Length is the most common failure mode. A CLAUDE.md that tries to document the entire project becomes a wall of text that costs context in every session and competes with the actual task. Most strong files land between fifty and two hundred lines. Review yours monthly: delete anything the code now makes obvious, anything Claude follows anyway, and anything that turned out to be wrong. A lean, current file outperforms a comprehensive, stale one every time, and Claude itself can help you draft and prune it if you ask.

If you are still finding your way around the tool, our guide on how to use Claude Code for free covers the setup and the daily workflow, while the best Claude skills for coding shows how to extend it further once the basics are in place.

Software team planning project conventions and CLAUDE.md rules at a whiteboard

A Simple CLAUDE.md Template You Can Copy

A reliable starting structure has six short headings: Project overview, Commands, Architecture, Conventions, Testing, and Gotchas. Under overview, two or three sentences on what the project is and who uses it. Under commands, a code block with the half dozen commands that cover daily work, each verified by running it yourself once. Under architecture, a bullet per major folder or service with a six-word description. That skeleton takes fifteen minutes to fill in for a real project and immediately changes the quality of every session that follows.

# Project overview
# Commands
# Architecture
# Conventions
# Testing
# Gotchas
  • Start with six headings: overview, commands, architecture, conventions, testing, gotchas.
  • Verify every command in the file by running it once yourself.
  • Add one line each time a repeated explanation or mistake reveals a gap.
  • Review changes to the file in pull requests like any other code.

Grow the template from experience rather than imagination. Every time Claude makes a mistake a rule would have prevented, add the rule in one line. Every time you type the same explanation twice, move it into the file. Within a month this produces a document shaped by your project’s real friction, not by a template author’s guesses. Share it in code review like any other change, because your teammates’ sessions benefit from the same instructions and their additions will cover blind spots you did not know you had.

Example: What a Real Commands Section Looks Like

Concrete beats abstract, so here is the shape a commands section should take. Swap in your own stack, but keep the same discipline: one command per job, each one copied from a terminal where it actually ran.

## Commands
- Install: npm ci
- Dev server: npm run dev
- Run all tests: npm test
- Run one test: npm test -- auth.test.ts
- Lint: npm run lint
- Build: npm run build

Notice what is missing: no explanations, no alternatives, no “you could also”. Six lines, six jobs, zero ambiguity. If a command needs an environment variable first, say so on the same line. If the build only works after a migration, put the migration command directly above it. This is the part of the file Claude reads most, so it deserves the most care.

Example: Writing Conventions Claude Can Apply

Conventions only work when they read like rules, not opinions. “Use the existing apiClient wrapper for network calls” is a rule. “Write clean, maintainable code” is a wish. The first tells Claude which file to open; the second tells it nothing. Aim for the same precision across naming, error handling, and commits: “Prefix test files with the module name”, “Return typed errors, never throw strings”, “Commit messages start with feat:, fix:, or docs:”. Each one is a decision Claude can make without asking you, and that is the whole point of the file.

Mistakes That Make CLAUDE.md Files Useless

The first mistake is dumping documentation into the file: API references, long tutorials, and product background that Claude can read from the repo when it needs them. The second is contradiction, usually from accumulating rules over time without pruning, so the file tells Claude to use two different patterns in two different sections. The third is vagueness: “write clean code” and “follow best practices” change nothing, because they give no decision rule for the hundred small choices a session contains.

  • Never paste secrets or credentials into the file; reference their location instead.
  • Avoid vague advice that gives no concrete decision rule.
  • Resolve contradictions when adding new rules instead of stacking them.
  • Treat staleness as a bug: an outdated instruction will be followed confidently.

The fourth mistake is secrets. Never put API keys, passwords, or tokens in CLAUDE.md; it is committed to your repository and read constantly, the two worst properties a secret can have. Reference where secrets live instead, such as the project’s password manager or environment setup. The fifth mistake is writing it once and never returning. Projects change, commands change, and a stale instruction is worse than none, because Claude will follow it confidently into a wall. Ten minutes of maintenance a month keeps the file an asset instead of a liability.

Once your file is working well, you can push it further. Claude skills for writing and Claude skills for marketing show how the same briefing idea extends beyond code.

Frequently Asked Questions

Where exactly should I put my CLAUDE.md file?

In your project’s root directory for project rules. You can also keep a personal file in your Claude configuration folder for preferences across all projects, and nested files inside subdirectories for area-specific instructions.

How long should a CLAUDE.md file be?

Most effective files are between fifty and two hundred lines. Long enough to cover commands, architecture, conventions, and gotchas, short enough that every line is read and respected in each session.

Can I generate the first draft automatically?

Yes. Claude Code can draft an initial file by analysing your repository if you ask it to, which gives you a solid starting point. Review and correct that draft carefully, because its value depends on accuracy, then refine it from real session mistakes.

What is the difference between CLAUDE.md and a README?

A README introduces the project to humans, often for public readers. CLAUDE.md is an operational brief for the assistant: exact commands, conventions, and traps. They can overlap slightly, but CLAUDE.md should stay shorter, more direct, and instruction-focused.

Does CLAUDE.md work with other AI coding tools?

CLAUDE.md is read by Claude Code, but the idea travels well. Other tools have their own equivalents, and a well-written CLAUDE.md doubles as a solid project brief you can adapt. Keep the content tool-neutral where you can — commands, architecture, and gotchas are useful no matter which assistant reads them.

Wrapping Up

A good CLAUDE.md file is a short, specific, living brief: exact commands, a five-sentence architecture, clear conventions, and the gotchas only experience teaches. Put it in your project root, keep it lean, grow it one line at a time from real mistakes, and prune it monthly. Do that and every Claude Code session starts already knowing your project, which is the closest thing to a permanent upgrade you can give the tool for free.

Daniel Carter
Written by Daniel Carter

Daniel tests AI tools for a living. He has reviewed 200+ AI apps and helps readers pick the right tool for their work.

Similar Posts