CLAUDE.md, the instruction file for Claude Code, gets longer every time you add an instruction. A long CLAUDE.md uses more context in every session, and Claude Code ignores its instructions more often.
I run several websites on a home server with Claude Code. As I kept adding instructions, my CLAUDE.md files grew longer and instructions were missed more often, so I reworked what goes into them. This article explains where to put CLAUDE.md, what to write in it and how to split a CLAUDE.md that has grown too long, based on the official documentation and on how I run my own setup.
What You'll Learn from This Article
- Where to put CLAUDE.md and the order the files load in
- What to write in CLAUDE.md and what to leave out
- How long CLAUDE.md should be, and how to check how much of it loads
- How to split a long CLAUDE.md into rules and skills
- What to do when instructions are not followed
The official documentation is described as of December 2026. Behavior can differ between Claude Code versions, so check the official documentation for the latest details.
Where to put CLAUDE.md and the order the files load in
CLAUDE.md is a Markdown file that Claude Code reads at the start of a session, and where you put it decides which work its instructions apply to.
Location | Applies to | Example contents |
|---|---|---|
| All of your projects | The language for responses, when to ask for confirmation |
| That project (shared through the repository) | Build commands, conventions |
| That project (only you) | Personal settings |
| Work on files in that directory | Conventions for that directory only |
When there are several CLAUDE.md files, none of them takes priority over the others: they are concatenated, starting from the files higher up in the directory tree. The CLAUDE.md files in the directory where you launched Claude Code and in the directories above it load at the start of the session, and a CLAUDE.md in a subdirectory loads once Claude Code reads or writes a file in that directory.
I put instructions shared by all my projects in ~/.claude/CLAUDE.md, constraints that apply to the whole server in the CLAUDE.md of my working directory, and details specific to each site in the CLAUDE.md of that site's directory. A site's CLAUDE.md loads only when Claude Code works on that site's files, so it uses no context during work on the other sites.
In a project that uses AGENTS.md for other coding agents, watch the loading conditions. According to the official documentation, by default Claude Code reads AGENTS.md only when there is no CLAUDE.md in your working directory or above it. To have both loaded, import it by writing @AGENTS.md in CLAUDE.md.
What to write in CLAUDE.md and what to leave out
The official documentation says to keep CLAUDE.md to "facts Claude should hold in every session". It recommends moving multi-step procedures and instructions that only matter for one part of the codebase into a skill or a path-scoped rule.
I limit what goes into CLAUDE.md to these four kinds of content.
- Constraints that lead to an incident if broken
- Where the source of truth lives (which file holds the correct information for a setting or definition)
- Procedures used every time
- Pointers to detailed documents (and which task to read each one before)
Anything that does not fit these four kinds goes somewhere else, as shown below.
What to leave out | Where it goes |
|---|---|
Background, measurements and dates | A changelog document |
Open issues | A document listing known issues |
Conventions needed only when working on certain files | Rules in |
Procedures needed only before certain operations | A procedure document or a skill |
Anything you can learn by reading the code (the directory layout, the list of dependencies) | Leave it out |
Before I reworked them, my CLAUDE.md files kept the history of bugs and measured values in the same files as the instructions, and the CLAUDE.md files for my working directory and for each site added up to 2,090 lines. Instructions were missed more often, and because so much loaded in every session, responses were slower and my plan's usage limits ran down faster.
After I limited the contents to the four kinds, the total came to 940 lines. Claude Code now reads the information it needs at the point it needs it, from the document that holds it, and context use went down.
I recommend against three ways of writing CLAUDE.md.
- Writing background and dates in CLAUDE.md
- Piling emphasis onto instructions that are not followed
- Writing every instruction in a single file
On emphasis, the official best practices page says that current models follow a plainly worded line, and that "piling on emphasis mostly makes Claude over-apply the rule". Its examples of emphasis are "IMPORTANT" and all caps.
How long CLAUDE.md should be, and how to check how much of it loads
The official documentation says to "target under 200 lines per CLAUDE.md file", because longer files "consume more context and reduce adherence".
The line count alone does not tell you how much loads, though. The CLAUDE.md in my working directory is now about 200 lines, but its lines are long, so it comes to about 10,000 tokens. My instruction files are written in Japanese, and in my measurements Japanese text came to about 0.7 tokens per character. Check the character count as well as the line count.
You can check how much loads in these ways.
- Run
/context allin Claude Code and look at the list under "Memory files" for the files loaded at the start of the session - Check the line count and character count of CLAUDE.md with
wc -landwc -m - Check for a length warning at the start of the session and when you run
/status
In my setup, the CLAUDE.md files, rules and auto memory index loaded at the start of a session added up to about 29,000 tokens. The CLAUDE.md in my working directory accounted for about 12,000 tokens of that at the time, so I moved the details into other documents and brought it down to about 9,700 tokens.
Auto memory, which Claude Code writes on its own, also has a load limit. Of the index file, MEMORY.md, only "the first 200 lines or 25KB of MEMORY.md, whichever comes first" load. I keep each line of the index short and move the lines for finished work into a separate file.
How to split a long CLAUDE.md into rules and skills
Instructions moved out of CLAUDE.md go somewhere they load only when needed. There are three places to move them.
Where it goes | When it loads | What fits there |
|---|---|---|
Rules with | When Claude Code reads or writes a file that matches the pattern | Conventions that concern only certain files or directories |
Skills | When you invoke them, and when Claude Code determines they are relevant to the task | Procedures for work with several steps |
Separate documents (CLAUDE.md holds only a pointer) | When Claude Code reads them by following the pointer | Procedures needed only before certain operations |
A path-scoped rule is a Markdown file in .claude/rules/ with the patterns of the files it covers written at the top.
---
paths:
- "src/app/sitemap.ts"
- "src/i18n/**"
---
# URL and sitemap rules
- Build URLs with the shared function
- Do not include redirecting URLs in the sitemapRules without paths load at the start of the session, the same as CLAUDE.md. Moving the contents of CLAUDE.md into rules without paths does not change how much loads.
I turn conventions needed only when working on certain files, such as the steps for generating fonts and the rules for the sitemap, into path-scoped rules. For procedures moved into separate documents, CLAUDE.md has a table that points to each one along with which task to read it before. When the pointer says when to read a document, Claude Code reads it before the matching task.
I also checked in my own setup when path-scoped rules load. They loaded when Claude Code read or wrote a file and when it displayed a single file with cat, but not when the output of cat was piped to another command.
Importing with @ does not reduce context use
Writing something like @docs/guide.md in CLAUDE.md imports that file. The imported file loads together with CLAUDE.md at the start of the session, though, so it helps organize the files but does not reduce context use. The official documentation also says imports "don't reduce its context cost".
What to do when instructions are not followed
The instructions in CLAUDE.md are not enforced settings but part of the context given to Claude Code. The official documentation also says "there's no guarantee of strict compliance, especially for vague or conflicting instructions". When instructions are not followed, check these in order.
- Run
/context alland check that the CLAUDE.md in question has loaded - Rewrite the instruction so its result can be checked. The example in the official documentation is "Use 2-space indentation" instead of "Format code properly"
- Check that no instructions in different files contradict each other. Running
/doctor prompt-auditreports outdated and conflicting instructions - Move instructions that must run at a specific point into a hook
A hook runs a shell command at a set point, such as after a file is edited or before a commit, and it runs regardless of what Claude Code says in its response. I had an instruction in CLAUDE.md to respond in Japanese, but Claude Code still switched back to English partway through some tasks, so I changed it to a hook that checks the responses.
What happens after a long conversation is compacted can also cause instructions to be missed. The project-root CLAUDE.md is read again after compaction, but instructions given only in the conversation can be lost. Instructions you want followed in the next session need to be written in CLAUDE.md.
Summary
CLAUDE.md stays short if it holds only the instructions needed in every session and the instructions needed only in certain situations move to places that load in those situations. These are the five points to check when writing CLAUDE.md.
- Where CLAUDE.md is placed decides what it applies to, and the files are concatenated starting from the top of the directory tree
- CLAUDE.md holds constraints, where the source of truth lives, procedures used every time and pointers to documents, but not background or dates
- The target length is under 200 lines per file, and
/context allshows which files loaded - Conventions that concern only certain files go into path-scoped rules, and procedures go into skills or separate documents
- Instructions that are not followed get rewritten more concretely, and anything that must always run moves to a hook
Imports with @ and rules without paths load at the start of the session, so moving content out of CLAUDE.md into them does not reduce context use.
Related articles and tools
How I manage six websites on a single home mini PC with Claude Code: how I split CLAUDE.md, make it ask before risky operations, restrict unattended runs, and put repeated procedures into skills.
