CLAUDE.md file guide: best practices, examples, and measured limits A hand-written CLAUDE.md file cut broken rules from 47 to 11 per 100 requests in a benchmark of Claude Code, but enforced nothing, according to the guide's cited benchmark. The guide documents that Claude Code loads CLAUDE.md files from four scopes — a managed policy path such as /etc/claude-code/CLAUDE.md on Linux, the user file at ~/.claude/CLAUDE.md, the project file at ./CLAUDE.md or ./.claude/CLAUDE.md, and the local ./CLAUDE.local.md — concatenating rather than overriding them, and recommends keeping the file short, imperative, and limited to commands, repeated constraints, and non-default conventions. CLAUDE.md file guide: best practices, examples, and measured limits The CLAUDE.md file is a text file Claude Code reads at the start of every session: your instructions, in context before the first prompt. This guide covers where the file lives, what belongs in it, a template you can copy, and the part most guides skip: what a rules file measurably changes. In our benchmark https://besydr.com/blog/claude-code-benchmark-with-and-without-besydr , a hand-written file cut broken rules from 47 to 11 per 100 requests. It enforced nothing. Where the CLAUDE.md file lives Claude Code loads CLAUDE.md files from several locations, from the broadest scope to the most specific. The official memory documentation https://code.claude.com/docs/en/memory lists them in load order: | Scope | Location | Shared with | |---|---|---| | Managed policy | System path set by your organization, such as /etc/claude-code/CLAUDE.md on Linux | Everyone in the organization | | User | ~/.claude/CLAUDE.md | Only you, in every project | | Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Your team, through source control | | Local | ./CLAUDE.local.md , added to .gitignore | Only you, in this project | The global CLAUDE.md file at ~/.claude/CLAUDE.md holds personal preferences that reach every project on your machine. The project file holds what a teammate's agent needs to know about this repository. Files are concatenated, not overridden: Claude Code walks from the filesystem root down to your working directory, and at each level reads CLAUDE.local.md after CLAUDE.md . A file in a subdirectory loads later, when Claude first reads or edits something there. CLAUDE.md structure and best practices A good CLAUDE.md file is short, imperative, and limited to what applies to most requests. The mechanism is the reason: the whole file enters the model's context, and a longer file spends more of the model's attention on lines the current task does not need. These CLAUDE.md best practices are working rules of thumb, not measured optima: - Commands the agent should use. How to build, how to run one test file, how to lint. An agent that knows the command runs it instead of guessing. - Constraints you repeat. "Never push to main." "Do not install anything." One line each, in your own words. - Conventions that differ from the default. The naming pattern, the error-handling style, the folder a new module goes in. - What to leave out. Long prose, duplicated documentation, and rules for one folder. Import a document instead of pasting it, and keep folder-specific rules in that folder's own file. A README is written for a human deciding whether to use the project; a CLAUDE.md file is written for an agent about to change it. They answer different questions, and one does not replace the other. A CLAUDE.md template Copy this CLAUDE.md example and replace the lines with your own. It shows the structure the section above describes: commands first, then constraints, then an import. Project instructions Commands - Run one test file: python -m pytest tests/test parser.py - Lint before handing work back: ruff check . Rules - Install nothing; the environment is already set up. - Run only the test files that cover your change, not the whole suite. - Keep the final message to three lines at most. More context See @docs/conventions.md for naming and error-handling conventions. The three rules are real ones from our benchmark, where a program checked each on every piece of work. They are a useful starting set because each is checkable: you can tell from the commands run and the diff whether the agent kept them. CLAUDE.md imports CLAUDE.md files import other files with @path/to/file syntax. The imported text is expanded into context alongside the file that references it. Three details from the documentation https://code.claude.com/docs/en/memory matter in practice: - Relative paths resolve from the file containing the import, not the working directory. Imports can nest, up to four hops deep. - Backticks keep a path literal: @README wrapped in backticks stays text, while a bare @README imports the file. - A path with spaces needs a backslash before each space, or the import ends at the first space. Imports are also how one file serves several tools: a CLAUDE.md that opens with @AGENTS.md shares the AGENTS.md convention https://agents.md with Codex and other clients, and adds Claude-specific lines below the import. What a rules file measurably changes Most CLAUDE.md best-practices posts assert what the file does. We measured it. In our Claude Code benchmark https://besydr.com/blog/claude-code-benchmark-with-and-without-besydr , a scripted developer worked on five Python projects and stated each rule once. The third setup adds Besydr say: besider , a program that supervises the agent and learns from its sessions. Per 100 requests, rules from an earlier session were broken: | Setup | Rules broken per 100 requests | Minutes per request | Client cost per request | |---|---|---|---| | Claude Code alone | 47 | 1.90 | $1.24 | | Claude Code, rules file written by hand | 11 | 1.41 | $1.01 | | Claude Code with Besydr, all parts on | 4 | 2.25 | $0.99 | Two honest caveats. The hand-written file held all 38 rules of the benchmark, and nobody writes that file by hand: the setup exists to measure the ceiling of a perfect file, not a workflow. And within a single project, Claude Code's own notes kept every rule in every run without any file; the decay the file fixes is across sessions and projects. The file setup was also the fastest of the three, because a rule the agent reads up front removes the correction turns that cost time. What the file cannot do Three limits survive any template: 1. CLAUDE.md rules are advice. The agent reads them and can still act against it. In a study of 20,574 coding-agent sessions Tang et al., EMNLP 2026 https://arxiv.org/abs/2605.29442 , the largest group of failures, 38.33% of episodes, was the agent violating an explicit constraint; the largest root cause, 36.49%, was failing to follow an instruction it clearly received. 2. The file does not learn. Every line exists because a person wrote it. A correction you type in chat is spent once and lost; the file does not grow from it. 3. A project file stops at the project. A lesson learned in one repository does not reach the next. The global file reaches everywhere, but only with what you remembered to put in it. Besydr say: besider is a program that runs beside a coding agent and closes those three gaps: it learns rules from your corrections, adds the ones that fit to later requests in any project, and can deny a tool call that conflicts with your words. In the same benchmark it broke 4 rules per 100 requests without a hand-written file. The benchmark post https://besydr.com/blog/claude-code-benchmark-with-and-without-besydr has every number and limit; the hooks tutorial https://besydr.com/blog/claude-code-hooks-tutorial shows the enforcement mechanism on Claude Code. The local program is free with octomind; with Claude Code it needs a licence https://besydr.com/pricing after a trial. CLAUDE.md management Treat the file as a budget, not a notebook. When a line stops earning its place, cut it: a rule the agent never breaks on its own, a convention the linter already enforces, a paragraph nobody has needed in a month. Move detail into imported files so the top-level file stays small, and keep the constraints you actually repeat in chat. If you want to know which lines the agent follows, check them the way the benchmark did: write each rule so a program can decide from the commands and the diff whether it was kept. Sources and method - File locations, load order and import syntax: the Claude Code memory documentation https://code.claude.com/docs/en/memory , read 2026-11-29. - The measured numbers come from our benchmark https://besydr.com/blog/claude-code-benchmark-with-and-without-besydr : 30 runs, Claude Code, five Python projects, two models. The rules-file setup ran twice; its numbers are means. - The study is Tang et al., EMNLP 2026 https://arxiv.org/abs/2605.29442 ; its shares were read from Table 2. - This post was drafted with AI assistance from these sources.