Workbranch › Guides

Guide

How to write a CLAUDE.md file for Claude Code

Every Claude Code session starts with an empty context, so you end up repeating the same build commands and house rules. A CLAUDE.md file fixes that. This guide covers where it goes, what belongs in it, and how to check that Claude is actually reading it.

Updated 30 October 2026

Quick answer: CLAUDE.md is a plain Markdown file that Claude Code loads at the start of every session. Put a project one at ./CLAUDE.md (or ./.claude/CLAUDE.md), run /init to have Claude draft it from your code, then trim it to the commands, conventions and rules Claude can't guess, ideally under 200 lines.

Locations and commands below were checked against Anthropic's Claude Code documentation as of October 2026. If something is missing in your version, run claude update.

Where CLAUDE.md files live

You can have several files, each with a different reach. Claude Code combines them all instead of letting one replace another; the more specific ones are read last.

FileApplies toTypical content
~/.claude/CLAUDE.mdYou, in every projectPersonal style and tooling preferences
./CLAUDE.md or ./.claude/CLAUDE.mdEveryone on the project (commit it)Build and test commands, architecture, conventions
./CLAUDE.local.mdOnly you, in this projectYour sandbox URLs, test data; add it to .gitignore
Managed policy file (set by IT)Everyone in the organizationCompany standards and compliance reminders

Files in the folder you launch from and every folder above it load at startup. A CLAUDE.md inside a subfolder loads later, once Claude reads or edits a file in that subfolder.

Create the file with /init

  1. Open a terminal in the project's root folder and start claude.
  2. Type /init. Claude looks through the codebase and writes a starter CLAUDE.md with the build commands, test instructions and conventions it finds. If a CLAUDE.md already exists, it suggests improvements instead of overwriting it.
  3. Read the draft and delete anything obvious or wrong.
  4. Add what Claude can't discover from the code: decisions, environment quirks, "never do X" rules.
  5. Commit the file so teammates get the same instructions.

To edit later, run /memory. It lists your CLAUDE.md and CLAUDE.local.md locations for user and project scopes, including ones that don't exist yet, and opens the file you pick in your editor. You can also just say add this to CLAUDE.md.

What to put in it

A simple test: if you have had to tell Claude something twice, it belongs in the file. Typical moments to add a line: Claude repeats a mistake, a code review catches something it should have known, or you type the same correction you typed last session.

Write rules you could check. Run npm test before committing works better than test your changes. Group lines under headings and bullets, and remove instructions that contradict each other, because Claude may follow either one. Multi-step procedures or rules that matter for one part of the codebase belong in a skill or a path-scoped rule instead.

Keep it short and organized

CLAUDE.md vs auto memory

Claude Code also keeps notes of its own, called auto memory. You write CLAUDE.md; Claude writes auto memory from your corrections and preferences. It lives per repository at ~/.claude/projects/<project>/memory/, with a MEMORY.md index whose first 200 lines (or 25KB) load into each session. It stays on your machine and isn't shared through git. When you say remember to always use pnpm, that goes to auto memory; turn the feature on or off with the toggle in /memory. Use CLAUDE.md for anything the whole team should get.

Good to know

If it doesn't work

Keep decisions and to-dos outside the file

CLAUDE.md is for lasting rules, not for the open tasks of this week. The Workbranch plugin for Claude Code covers that part: run /workbranch:save and Claude files the session's tasks, decisions and open questions into a Workbranch project, and when a session starts in a folder linked to a Workbranch project, the plugin shows what's still open there. There is a 3-day free trial at app.workbranch.ai.

Sources

Frequently asked questions

Does Claude have to obey CLAUDE.md?

No. Anthropic describes it as context, not enforced configuration. For something that must never happen, such as a command that must be blocked, use a permission deny rule or a PreToolUse hook instead.

Can I keep notes in CLAUDE.md that Claude doesn't read?

Yes. Block-level HTML comments are stripped before the file is sent to Claude, so you can leave maintainer notes without spending context on them.

My repository already has an AGENTS.md. Do I need both?

No. If there is no CLAUDE.md in the folder or above it, recent versions of Claude Code read AGENTS.md instead. If you have both, only CLAUDE.md is read unless you import AGENTS.md from it or change the Project instructions setting in /config.