{"slug": "claude-md-file-guide-best-practices-examples-and-measured-limits", "title": "CLAUDE.md file guide: best practices, examples, and measured limits", "summary": "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.", "body_md": "# CLAUDE.md file guide: best practices, examples, and measured limits\n\nThe 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.\n\n## Where the CLAUDE.md file lives\n\nClaude 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:\n\n| Scope | Location | Shared with | \n|---|---|---|\n| Managed policy | System path set by your organization, such as `/etc/claude-code/CLAUDE.md` on Linux | Everyone in the organization | \n| User | `~/.claude/CLAUDE.md` | Only you, in every project | \n| Project | `./CLAUDE.md` or`./.claude/CLAUDE.md` | Your team, through source control | \n| Local | `./CLAUDE.local.md` , added to`.gitignore` | Only you, in this project | \n\nThe 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.\n\n## CLAUDE.md structure and best practices\n\nA 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:\n\n- **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.\n- **Constraints you repeat.** \"Never push to main.\" \"Do not install anything.\" One line each, in your own words.\n- **Conventions that differ from the default.** The naming pattern, the error-handling style, the folder a new module goes in.\n- **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.\n\nA 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.\n\n## A CLAUDE.md template\n\nCopy 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.\n\n```\n# Project instructions\n\n## Commands\n\n- Run one test file: `python -m pytest tests/test_parser.py`\n- Lint before handing work back: `ruff check .`\n\n## Rules\n\n- Install nothing; the environment is already set up.\n- Run only the test files that cover your change, not the whole suite.\n- Keep the final message to three lines at most.\n\n## More context\n\nSee @docs/conventions.md for naming and error-handling conventions.\n```\n\nThe 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.\n\n## CLAUDE.md imports\n\nCLAUDE.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:\n\n- Relative paths resolve from the file containing the import, not the working directory. Imports can nest, up to four hops deep.\n- Backticks keep a path literal: `@README` wrapped in backticks stays text, while a bare @README imports the file.\n- A path with spaces needs a backslash before each space, or the import ends at the first space.\n\nImports 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.\n\n## What a rules file measurably changes\n\nMost 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:\n\n| Setup | Rules broken per 100 requests | Minutes per request | Client cost per request | \n|---|---|---|---|\n| Claude Code alone | 47 | 1.90 | $1.24 | \n| Claude Code, rules file written by hand | 11 | 1.41 | $1.01 | \n| Claude Code with Besydr, all parts on | 4 | 2.25 | $0.99 | \n\nTwo 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.\n\n## What the file cannot do\n\nThree limits survive any template:\n\n1. **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.\n2. **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.\n3. **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.\n\nBesydr (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.\n\n## CLAUDE.md management\n\nTreat 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.\n\n## Sources and method\n\n- File locations, load order and import syntax: the [Claude Code memory documentation](https://code.claude.com/docs/en/memory) , read 2026-11-29.\n- 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.\n- The study is [Tang et al., EMNLP 2026](https://arxiv.org/abs/2605.29442) ; its shares were read from Table 2.\n- This post was drafted with AI assistance from these sources.", "url": "https://wpnews.pro/news/claude-md-file-guide-best-practices-examples-and-measured-limits", "canonical_source": "https://besydr.com/blog/claude-md-file-guide", "published_at": "2026-11-29 00:00:00+00:00", "updated_at": "2026-11-29 09:43:27.439855+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents"], "entities": ["Claude Code", "Anthropic"], "also_reported_by": [], "takeaway": "A hand-written CLAUDE.md cut broken rules from 47 to 11 per 100 requests but enforced nothing, so keep the file short and imperative with checkable commands, repeated constraints, and @path imports instead of pasted docs.", "recommendation": {"advice": "Keep CLAUDE.md short and imperative — build and test commands, repeated constraints, non-default conventions — and import long docs with @path instead of pasting them; the cited benchmark saw broken rules fall from 47 to 11 per 100 requests.", "playbook": "coding-agents", "playbook_url": "https://wpnews.pro/playbooks/coding-agents"}, "alternates": {"html": "https://wpnews.pro/news/claude-md-file-guide-best-practices-examples-and-measured-limits", "markdown": "https://wpnews.pro/news/claude-md-file-guide-best-practices-examples-and-measured-limits.md", "text": "https://wpnews.pro/news/claude-md-file-guide-best-practices-examples-and-measured-limits.txt", "jsonld": "https://wpnews.pro/news/claude-md-file-guide-best-practices-examples-and-measured-limits.jsonld"}}