CLAUDE.md as a Runbook: What to Write and Where
Claude Code reads CLAUDE.md at the start of every session, and the docs target under 200 lines per file. What to write, where it goes, what stays in the prompt.
- If you explain the same thing in every prompt, move it into CLAUDE.md. Claude Code reads it at the start of every session.
- Claude treats CLAUDE.md as context, not enforced configuration. To block an action regardless of what Claude decides, use a PreToolUse hook.
- Draft it with /init, then write instructions concrete enough to verify. The docs target under 200 lines per CLAUDE.md file.
If you keep typing the same explanation into every prompt, that explanation belongs in a file. In Claude Code, that file is CLAUDE.md, and it works best when you treat it as a runbook. This guide covers when CLAUDE.md loads, where to put it, drafting it with /init, a template, what stays in the prompt, where hooks come in, and how it relates to AGENTS.md. If your CLAUDE.md is already long, see trimming CLAUDE.md.
On 2026-10-29 our test environment reported 2.1.312 (Claude Code) from claude --version. We did not run /init, /context or /memory, and did not create or edit any CLAUDE.md for this article (not run). Everything below comes from the docs, checked the same day.
What CLAUDE.md is and when it loads
CLAUDE.md is a Markdown file of instructions you want Claude to have every time. Claude Code reads it at the start of every session. The docs describe it as the place you write down what you’d otherwise re-explain, and suggest adding to it when:
- Claude makes the same mistake a second time
- A code review catches something Claude should have known about this codebase
- You type the same correction into chat that you typed last session
- A new teammate would need the same context
Keep it to facts Claude needs in every session: build commands, conventions, project layout and “always do X” rules.
Claude treats CLAUDE.md as context, not enforced configuration. The content arrives as a user message after the system prompt, so there is no guarantee of strict compliance. Anything you must block goes to a hook, covered below.
Source: https://code.claude.com/docs/en/memory (checked 2026-10-29)
Locations and load order
| Scope | Location | Use |
|---|---|---|
| Managed policy | macOS /Library/Application Support/ClaudeCode/CLAUDE.md, Linux and WSL /etc/claude-code/CLAUDE.md, Windows C:\Program Files\ClaudeCode\CLAUDE.md | Organization-wide standards |
| User | ~/.claude/CLAUDE.md | Your preferences for all projects |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Team instructions, committed to git |
| Local | ./CLAUDE.local.md | Your own notes for one project; add it to .gitignore |
Claude Code loads CLAUDE.md and CLAUDE.local.md from the working directory and every directory above it. Start it in foo/bar/ and it reads foo/bar/CLAUDE.md and foo/CLAUDE.md. Files are concatenated, not overridden, ordered from the filesystem root down, so instructions closer to where you launched are read last. In each directory, CLAUDE.local.md comes after CLAUDE.md. A CLAUDE.md in a subdirectory loads later, once Claude reads, writes or edits a file in that subdirectory.
Instructions that apply to only some files can go in .claude/rules/. With paths in the frontmatter, a rule loads only when Claude works with matching files:
---
paths:
- "src/api/**/*.ts"
---
Validate input in every API handler before processing it.
To confirm what loaded, run /context in a session and check Memory files. /memory lists the CLAUDE.md locations and opens a file in your editor.
Source: https://code.claude.com/docs/en/memory (checked 2026-10-29)
Drafting with /init
/init has Claude analyze the codebase and write a starting CLAUDE.md with the build commands, test instructions and conventions it finds. If a CLAUDE.md already exists, it suggests improvements rather than overwriting it. The docs then suggest adding what Claude wouldn’t discover on its own. Setting CLAUDE_CODE_NEW_INIT=1 switches /init to an interactive flow that asks whether to set up CLAUDE.md files, skills and hooks, and shows a proposal before writing anything. We did not run either (not run).
Source: https://code.claude.com/docs/en/memory (checked 2026-10-29)
A template
This is a made-up example for a small todo app. The docs ask for instructions concrete enough to verify: “Run npm test before committing” rather than “Test your changes”.
# todo-app
## Commands
- Install: `npm install`
- Dev server: `npm run dev`
- Tests: `npm test`
- Lint: `npm run lint`
## Layout
- `src/api/`: API handlers
- `src/components/`: UI components
- `tests/`: tests, named `*.test.ts`
## Conventions
- 2-space indentation
- Every new API endpoint gets a test
- List environment variable names only in `.env.example`
## Before you finish
- `npm run lint` and `npm test` pass
- Report the list of changed files
## More detail
- API conventions: @docs/api-conventions.md
The last line is an import. @path pulls that file into context with the CLAUDE.md. Relative paths resolve from the file that contains the import, not the working directory. Imported files can import others, up to four hops deep. Paths inside backticks or code blocks are not imported.
The docs target under 200 lines per CLAUDE.md file, since longer files consume more context and reduce adherence. Imports help organize a long file but don’t reduce its context cost.
Source: https://code.claude.com/docs/en/memory (checked 2026-10-29)
What stays in the prompt
| Content | Where |
|---|---|
| Build, test and lint commands | CLAUDE.md |
| Directory roles, naming conventions | CLAUDE.md |
| Conventions for part of the codebase | .claude/rules/ with paths |
| Multi-step procedures | A skill |
| The goal and scope of this task | The prompt |
| One-off limits, such as which files to touch | The prompt |
| Your sandbox URLs, preferred test data | CLAUDE.local.md |
The test is whether every session needs it. The docs say to move multi-step procedures and things that matter for only one part of the codebase into a skill or a path-scoped rule. For writing skills, see creating Claude Code skills.
Source: https://code.claude.com/docs/en/memory (checked 2026-10-29)
Rules you must enforce go to hooks
Because CLAUDE.md is context, an instruction there can be missed. The docs say that to block an action regardless of what Claude decides, you use a PreToolUse hook. “Don’t edit the production config” can sit in CLAUDE.md as a reminder, but the block itself belongs in a hook. Events, exit codes and examples are in the hooks guide.
Source: https://code.claude.com/docs/en/memory (checked 2026-10-29)
AGENTS.md
If other agents such as Codex work in the same repository, you can keep shared instructions in AGENTS.md. Claude Code v2.1.277 and later reads it directly. The default behavior:
- AGENTS.md and no
CLAUDE.mdorCLAUDE.local.mdin the working directory or above: Claude reads AGENTS.md - AGENTS.md plus one of those files: Claude reads the CLAUDE.md files only
- A CLAUDE.md that imports AGENTS.md: both, with AGENTS.md through the import
~/.claude/CLAUDE.md, a managed CLAUDE.md and .claude/rules/ files don’t count for this check. A CLAUDE.local.md does, so adding one stops Claude from reading AGENTS.md unless you set Project instructions to claude-md-and-agents-md in /config.
To keep both, start CLAUDE.md with the import and add Claude-only instructions below it:
@AGENTS.md
## Claude Code
- Use plan mode for changes under `src/api/`
Source: https://code.claude.com/docs/en/memory (checked 2026-10-29)
Where Codex looks for AGENTS.md is covered in getting started with Codex CLI. For installing Claude Code itself, see getting started with Claude Code.
- Claude Code Setup and Daily Operations: where config files, instructions, daily commands and IDE setup live.
Summary
- Whatever you explain in every prompt goes into CLAUDE.md as a runbook.
- Locations are managed, user, project and local; files from the root down to your working directory are concatenated.
- Draft with
/init, then add what Claude can’t discover on its own. - Write commands, layout, conventions and finish checks in a form you can verify, under 200 lines per file.
- Keep this task’s goal and scope in the prompt. Block what must never happen with a hook.
- To share instructions with other agents, put
@AGENTS.mdat the top of CLAUDE.md.
FAQ
- When does Claude Code read CLAUDE.md?
- At the start of every session. CLAUDE.md files in the working directory and every directory above it load at launch; CLAUDE.md files in subdirectories load once Claude reads, writes or edits a file in that subdirectory.
- How long should CLAUDE.md be?
- The docs target under 200 lines per CLAUDE.md file, because longer files consume more context and reduce adherence. Imports help organize a file but don't reduce its context cost.
- What does /init do?
- Claude analyzes the codebase and writes a starting CLAUDE.md with the build commands, test instructions and conventions it finds. If a CLAUDE.md already exists, /init suggests improvements instead of overwriting it.
- Does Claude Code read AGENTS.md?
- Yes, from v2.1.277. By default it reads AGENTS.md only when there is no CLAUDE.md or CLAUDE.local.md in the working directory or above it. A CLAUDE.md that imports @AGENTS.md loads both.
- How do I check which CLAUDE.md files loaded?
- Run /context in a session and look at the list under Memory files. /memory lists the file locations and opens them in your editor.