CLAUDE.md File Explained: Location, Length and Limits
Say you're Priya, and it's Tuesday. You tell Claude Code to use pnpm, not npm. It's the third time this week. So you open CLAUDE.md, add one line by hand, and move on. Next week Claude makes a new mistake, and the same loop starts again.
If that sounds familiar, you already know the problem. Claude Code forgets between sessions, and Anthropic's memory guide tells you to "treat CLAUDE.md as the place you write down what you'd otherwise re-explain." It's part of the fix. A CLAUDE.md file is a markdown file that Claude Code reads at the start of each session. A person writes it. It does not learn.
This page covers where the file goes, how long it should be, how it compares to AGENTS.md, auto memory and skills, and what it cannot do. I'm Chris Latimer, and I build Hindsight, an agent memory system, so I care most about that last part. Every number below names its source, and the sources disagree on length. Think of the file as one slice of AI agent memory: the slice you write by hand.
What a CLAUDE.md File Is
Anthropic's memory guide puts it plainly: "CLAUDE.md files are markdown files that give Claude persistent instructions for a project, your personal workflow, or your entire organization."
So what goes in? Build and test commands. Code style. Project rules. Anything Claude cannot work out by reading the code. If you find yourself typing the same correction a third time, it belongs in the file.
How does the text reach the model? Here Anthropic's own pages differ. The claude.com article on CLAUDE.md files says: "Your CLAUDE.md file becomes part of Claude's system prompt." The memory guide says: "CLAUDE.md content is delivered as a user message after the system prompt, not as part of the system prompt itself." I follow the memory guide, because it is the reference page for how Claude Code behaves. For you the practical result is the same: Claude reads the file and tries to follow it. Section six covers what "tries" means.
To start a file, run /init. Claude Code generates a first version from your codebase. The claude.com article calls /init "a starting point, not a finished product," while the HumanLayer blog says to avoid auto-generating the file. I use /init for a draft and then edit every line.
To add a line later, ask Claude: "add this to CLAUDE.md." Or edit the file yourself through /memory. That's all the memory guide offers, and it matters for the last section of this page. Every update is something a person does. For the wider picture, see my page on Claude Code memory.
Want to see the other side of this, a memory that updates itself? Read how the Hindsight Coding Agents plugin adds memory that learns to Claude Code.
Where CLAUDE.md Goes and How Claude Code Loads It
Where does CLAUDE.md reside? The memory guide lists six places. Each has its own scope.
| Scope | Path | Who it is for | When it loads |
|---|---|---|---|
| Managed policy | macOS /Library/Application Support/ClaudeCode/CLAUDE.md; Linux and WSL /etc/claude-code/CLAUDE.md; Windows C:\Program Files\ClaudeCode\CLAUDE.md | An organization | At launch |
| User | ~/.claude/CLAUDE.md | You, in every project | At launch |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Your team, through version control | At launch |
| Local | ./CLAUDE.local.md (add it to .gitignore) | You, in one project | At launch, after CLAUDE.md in the same folder |
| Subdirectory | Any CLAUDE.md under the working directory | Part of a codebase | On demand |
| Rules folders | ./.claude/rules/ and ~/.claude/rules/ | Topic-specific rules | Per the rule file |
At launch, Claude Code loads CLAUDE.md and CLAUDE.local.md from your current working directory and every directory above it. The order runs from the filesystem root down to your working directory. Subdirectory files load once Claude reads, writes or edits a file in that subdirectory.
You can pull other files in with the @path/to/import syntax. Relative paths resolve from the file that holds the import, and the guide sets a maximum depth of four hops. Imports are skipped inside code spans and fenced code blocks. This is the guide's own example:
See @README for project overview and @package.json for available npm commands for this project.
# Additional Instructions
- git workflow @docs/git-instructions.md
One trap: folders you add with --add-dir do not load their CLAUDE.md files by default. Set CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 to turn that on.
How Long a CLAUDE.md File Should Be
How long is too long? Three sources give four numbers: about 30 lines from a dev.to author, under 60 and under 300 from HumanLayer, and under 200 from Anthropic. Here they are side by side.
Anthropic's memory guide says to "target under 200 lines per CLAUDE.md file. Longer files consume more context and reduce adherence." HumanLayer writes that the "general consensus is that < 300 lines is best, and shorter is even better," and says its own root file is less than sixty lines. A dev.to post by Stanislav Silin argues for "only around 30 lines maximum."
The numbers differ because the authors measure different things. Anthropic gives vendor advice, not a cap. The shorter numbers come from people who watched Claude miss rules in long files. I treat 200 as a ceiling and aim well below it, because every line costs attention on every task. The best practices page says the same: every line "takes a little of Claude's attention on every task, whether it's relevant or not."
There are hard limits too, and they're far away. Claude Code skips a CLAUDE.md file over 4 MiB and loads none of it. Subdirectory and rule files have a per-file character limit: 40,000 characters at a 200K context window.
Picture Marco's team. They merge three CLAUDE.md files into one of 450 lines. A week later Claude starts skipping the rule that says how to run the tests. They cut the file to 120 lines and move the release procedure into a skill. The test rule sticks again. A shorter CLAUDE.md file isn't a trick. The model has less to ignore.
CLAUDE.md, AGENTS.md and the Files Other Tools Read
Are AGENTS.md and CLAUDE.md the same? No. They are two files for different tools, and the content can be shared.
- Codex reads
AGENTS.md(orAGENTS.override.md) from~/.codexand then from the project root down. It stops adding files at 32 KiB combined by default, per the Codex docs. - OpenCode reads
AGENTS.md. In a folder with noAGENTS.md, it readsCLAUDE.mdinstead, per the OpenCode rules page. - Claude Code reads
CLAUDE.md. By default, per the memory guide, it readsAGENTS.md"only when you have noCLAUDE.mdin your working directory or above it."
If your repository already has an AGENTS.md, the guide shows how to share it. Make a CLAUDE.md file that starts with an import:
@AGENTS.md
## Claude Code
Use plan mode for changes under `src/billing/`.
I compare the two files in more depth in Codex vs Claude Code. The limits differ too: Codex stops adding files at 32 KiB combined, while Anthropic's memory guide advises under 200 lines per CLAUDE.md file. Hindsight adds memory to both. You don't have to pick one file format to use one agent.
CLAUDE.md vs Auto Memory vs Skills
Claude Code has more than one place to keep what it should remember. They differ in who writes them and when they load.
| Layer | Who writes it | Where it lives | When it loads | Updates from outcomes |
|---|---|---|---|---|
| CLAUDE.md file | A person | Paths in the table above | At launch | No. A person edits it. |
| Auto memory | Claude | ~/.claude/projects/<project>/memory/ (MEMORY.md plus topic files), one machine | First 200 lines or 25 KB of MEMORY.md, every session | Claude saves notes of four types: user, feedback, project, reference |
Skills (SKILL.md) | A person | ~/.claude/skills/<name>/ or .claude/skills/<name>/ | Name and description at launch, body when invoked | No. A person edits it. |
| Hindsight (Coding Agents plugin) | The memory service | One bank per repository, coding-agent::<repo> | Recall on the first prompt of a session | Yes. The session transcript is retained at session end. |
The memory guide draws the line between the first and third rows. If an entry "is a multi-step procedure or only matters for one part of the codebase, move it to a skill or a path-scoped rule instead." The skills page gives the reason: "Unlike CLAUDE.md content, a skill's body loads only when it's used, so long reference material costs almost nothing until you need it." I explain the file format in Claude Code skills explained.
Auto memory is the closest thing Claude Code has to a memory that writes itself. It is machine-local, and the notes stay until you or Claude edit or delete them. If you want the same idea across several agents and machines, the options are compared in memory MCP servers compared.
In short: a CLAUDE.md file holds rules, skills hold procedures, auto memory holds notes on one machine. None of the first three is shared across agents, and none of the first two changes unless a person changes it.
What a CLAUDE.md File Cannot Do
This is the point I most want you to take away. A CLAUDE.md file is memory a person writes by hand. It does not learn from outcomes. Memory that learns is a different layer, and it sits beside the file, not in place of it.
Three limits follow from how the file works.
- A person writes it. Every correction is a manual edit. The memory guide says to ask Claude to add the line or to edit it through
/memory. - It does not learn from outcomes. A CLAUDE.md file is text. Nothing in it records whether a rule worked, and nothing updates it after a session goes wrong. That is how a file works, not a flaw in Claude Code.
- Claude may not follow it. The memory guide says there is "no guarantee of strict compliance, especially for vague or conflicting instructions," and that Claude treats the file as context: "They aren't enforced configuration." The best practices page goes further: "If something has to happen every time, make it a hook, a deny rule, or a managed setting. CLAUDE.md is for guidelines, and Claude is allowed to decide a guideline doesn't apply."
Does that make the file useless? No. It stays the right place for rules a person decides: the test command, the style guide, the branch policy. But back to Priya. Her third pnpm correction is exactly the kind of thing a person should not have to write down by hand.
How Hindsight adds memory that learns
The Hindsight Coding Agents plugin installs with one line:
npx @vectorize-io/hindsight-coding-agents install claude-code
Per the plugin's docs page, that writes three hooks in ~/.claude/settings.json, adds an MCP server at user scope, and installs a skill at ~/.claude/skills/hindsight-coding-agent. Memory is per repository, in a bank named coding-agent::{gitProject}, shared by every agent on that repository. On the first prompt of a session, the plugin injects a memory synthesis into context. At session end, it retains the transcript. There is no setup command for ingest.
Say you're Priya again, with the plugin on. Her next session opens with what the earlier sessions learned about the repository. She stops writing the same line into CLAUDE.md, and keeps CLAUDE.md for the rules she chooses.
Hindsight states its own result on the same page. In its sdebench run, a coding agent works through 61 real repository tasks, three runs each, with and without memory. For Claude Code, corrections per task fell from 0.85 to 0.36, and cost per task from $0.445 to $0.338. Those are Hindsight's figures, as stated on the page, as of November 2026. The run settings are in the Agent Memory Benchmark repository.
Try it on your own repository: View Hindsight on GitHub or start with Hindsight Cloud.
For how this compares with other Claude Code memory options, read Claude Code memory vs Mem0 vs Hindsight.
What to do next
- Keep the CLAUDE.md file short. Treat 200 lines as a ceiling and aim lower.
- Move multi-step procedures into skills, as Anthropic's memory guide advises.
- Put rules with no exceptions in hooks, not in prose.
- If you use more than one coding agent, share one file with an
@AGENTS.mdimport. - Add memory that learns for what changes from session to session. Install the plugin with the line above, and keep CLAUDE.md for the rules you write on purpose.
Start with your current file. Count its lines, cut it by a third, and see whether Claude follows the rest more often.
Frequently Asked Questions
What is a CLAUDE.md file for?
A CLAUDE.md file gives Claude Code persistent instructions for a project, your personal workflow or your organization. Anthropic's docs call it the place you write down what you would otherwise re-explain. Claude reads it at the start of each session, so build commands, code style and project rules belong in it.
Should I run /init to make a CLAUDE.md?
Run it once to get a starting file, then cut lines. Anthropic's best practices page says /init generates a starting version and the work after that is mostly removing lines. HumanLayer advises against auto-generating the file. I use /init as a first draft and edit every line before I commit it.
How do I turn off auto memory in Claude Code?
Use the /memory toggle, set autoMemoryEnabled: false in your settings, or set the environment variable CLAUDE_CODE_DISABLE_AUTO_MEMORY=1. Any of the three works, per Anthropic's memory guide. CLAUDE.md files are a separate feature, and Claude Code still loads them at launch.
How long does Claude Code keep session transcripts?
Thirty days by default. The cleanupPeriodDays setting sets the number of days, with a minimum of 1. Setting 0 fails validation, so Anthropic's settings reference suggests a large value such as 3650 for long retention. Auto memory notes are separate: they stay until you or Claude edit or delete them.