Split a 600-Line CLAUDE.md: @import Lines, .claude/rules Files and Which One to Pick
A CLAUDE.md that grew to 600 lines loads all five topics for a one-test fix. Split it with @import lines so each package pulls in only its own standards, and move topics into .claude/rules/ files that load when the work needs them.
What you will learn
- Explain why one big CLAUDE.md costs context on every task
- Pull a standards file into a CLAUDE.md with an @import line, with the path relative to the importing file
- Split conventions into .claude/rules/ with one topic per file
- Choose between a folder CLAUDE.md, an import and a rule file
Before you start
- What CLAUDE.md is and where Claude Code looks for it
- Basic Markdown and YAML frontmatter
Asha looks after the shop app. Ben has just joined the team, and he asks a fair question: why does Claude read all of this? Asha's CLAUDE.md started small. It has grown to six hundred lines.
Today we fix that with two tools: the @import line, and rule files in .claude/rules/. By the end you'll know which of the two (or a plain folder CLAUDE.md) fits a given convention. If you haven't seen how user, project and folder CLAUDE.md files stack up, read the CLAUDE.md hierarchy first.
One big file, every task pays
Asha wrote every convention into one file: API conventions, web conventions, infra rules, testing rules and the git workflow. Five sections, six hundred lines.
Now Ben asks Claude to fix one failing test. Claude loads all five sections, every time. Only one of them is about tests. The other four cost context and give Claude nothing it needs for this job. A smaller memory file is a sharper one.
Think of a binder with tabs. The front page is short and lists the tabs: git, api, infra, test. When you fix a test, you open the test tab and leave the rest of the binder closed. Better still, picture the test tab opening by itself when a test file lands on the desk. The short front page is your CLAUDE.md, the tabs are imported files and rule files, and the tab that opens itself is a rule with a paths line.
@import: each package pulls in only what it needs
The first tool is an import line. A line that starts with @ and names a file pulls that file in next to the CLAUDE.md that holds the line. Here is the shop app's root CLAUDE.md, short on purpose:
# shop-app
A small shop. Folders: api/ (Python), web/ (JavaScript), infra/ (deploy).
## Always
- Keep changes small and explain them in one sentence.
- Never commit secrets or .env files.
## Shared standards (imported)
@docs/git-workflow.md
Three parts: the whole shop in one line, two rules that apply to every task, and the import on its own line at the end. That last line brings in docs/git-workflow.md:
# Git workflow
- One branch per task, named feature/<short-name>.
- Commit messages start with a verb: "Add", "Fix", "Rename".
- Open a pull request; Asha reviews every one.
The api package has its own CLAUDE.md, and it imports the API standards:
# api/ package
Only the API team's standards are imported here:
@../docs/api-standards.md
Notice the ../. The path in an import is relative to the file that holds the line, not to the project root. This file lives in api/, so it climbs one folder up to reach docs/. The root file, sitting next to docs/, writes @docs/git-workflow.md with no climb.
The web package has no CLAUDE.md and no import line, so the API standards stay out of web work.
.claude/rules/: one topic per file
The second tool takes the six-hundred-line file apart by topic. Each topic becomes its own Markdown file in .claude/rules/. The shop app ends up with three:
.claude/rules/testing.md: pytest rules.claude/rules/api-conventions.md: handler rules.claude/rules/infra.md: deploy safety
Here is api-conventions.md:
---
paths:
- "api/**/*.py"
---
# API conventions
- Handler functions are named handle_<resource>.
- Return a dict with "data" and "error"; never raise to the caller.
And infra.md:
---
paths:
- "infra/**/*"
---
# Infra rules
- Never put a real password in a file; read it from the environment.
- Change one environment at a time: staging first, then production.
Each file has one topic, and the paths line at the top decides when it loads. A rule file with no paths line at all loads at launch, like CLAUDE.md does.
A path-specific rule: testing.md
The rule that answers Ben's case is testing.md:
---
paths:
- "**/*_test.py"
---
# Testing rules
- Use pytest. One behaviour per test function.
- Name tests test_<thing>_<expected result>.
- No network calls; use the fakes in tests, never the live service.
The frontmatter sits between two lines of dashes. The glob **/*_test.py means every file ending in _test.py, in any folder. Below the frontmatter are plain Markdown rules.
So when Ben edits api/orders_test.py, the path matches and testing.md loads next to CLAUDE.md. When he edits web/app.js, nothing matches and testing.md stays out. Fewer irrelevant instructions means fewer tokens and a clearer focus.
The lecture shows this in Claude Code: Ben asks for a test for an unknown order id in api/orders_test.py, Claude reads that file, and the rule joins the context. Per the Claude Code docs, a path rule loads when Claude reads, writes or edits a matching file. To see which memory files are loaded at any moment, run /memory. Reach for it whenever Claude behaves differently than you expect.
How globs match, why a rule waits until a file is touched, and how to debug a glob that matches nothing get their own article: path-specific rules and paths globs.
Folder CLAUDE.md, import or rule file?
You now have three places to put a convention. Ask how far it spreads.
| Situation | Choose | Why |
|---|---|---|
| Rules for one package only | api/CLAUDE.md (optionally importing a docs file) | Loads when Claude works in that folder |
| Tests in every folder | A rule with a paths glob | One file matches by file type, wherever it sits |
| Rules for every task | The root CLAUDE.md, or a rule with no paths | Loads at launch |
The import is the tool for sharing: a standards document lives once in docs/, and each CLAUDE.md that needs it names it. The rule file is the tool for topics that cut across folders. If a convention is spread across folders, one glob rule beats ten folder files.
How this shows up in a question
A typical scenario: test files sit next to the code in api/, web/ and infra/, and the team wants the testing rules on every test file but not for other work. One rule file with paths: ["**/*_test.py"] fits. A CLAUDE.md in every folder loads for non-test files too and must be kept in step. A rule with no paths loads for everything. And rules in each developer's ~/.claude/CLAUDE.md are never shared with teammates.
Common mistakes
- Writing import paths from the project root. In
api/CLAUDE.md,@docs/api-standards.mdpoints atapi/docs/, which doesn't exist. The path is relative to the importing file:@../docs/api-standards.md. - Splitting the file but importing everything from the root. If the root CLAUDE.md imports all five topic files, every task still pays for all five. Import from the package that needs it.
- Putting a cross-folder convention in folder files. Test rules copied into
api/CLAUDE.md,infra/CLAUDE.mdand so on drift apart, and they load for every file in those folders, test or not. - Guessing what loaded. Run
/memoryand look, instead of assuming.
Quick recap
| Tool | Where | When it loads |
|---|---|---|
| Root CLAUDE.md | Project root | At launch, every task. Keep it short. |
@path/to/file.md | A line inside any CLAUDE.md | With the file that holds the line; path relative to that file |
| Folder CLAUDE.md | api/CLAUDE.md | When Claude works in that folder |
Rule with paths | .claude/rules/testing.md | When Claude reads, writes or edits a matching file |
Rule without paths | .claude/rules/ | At launch |
The shop-app config files for this lesson are in the community, free to join.
Try it yourself
Take your own project's CLAUDE.md and list its sections. For each one, decide: does it apply to every task, to one package, or to one kind of file? Keep the first group in the root file, move the second into a folder CLAUDE.md with an import, and turn the third into a rule file in .claude/rules/. Then edit a test file and run /memory to check what joined the context.
Related course on Udemy
Claude Certified Architect - Foundations (CCAR-F) Exam Prep
Agentic loops, tools, MCP, Claude Code, prompts, structured output and context.View on Udemy ↗: Claude Certified Architect - Foundations (CCAR-F) Exam Prep (paid course, opens in a new tab)Related posts
CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
Three needs in one repo: a test command, a rule that Claude must never read .env, and a shared deploy skill. See which file each belongs in, how the settings layers merge, and what a plugin manifest carries.
Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
Pack a support team's ticket-triage routine into one skill folder, then watch three requests load one, two or all three levels: the catalog, the SKILL.md body, and a script whose code never enters the context.
One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
Change one line in a repo and ask where it lands. A small resolver for bookshop-bot shows that a new model id in settings.json reaches only CI, a prompt bump reaches dev and CI, and a prod block edit reaches only prod.
Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
Follow one prompt edit from a branch to a merge: version prompts and the model pin like code, keep the API key in GitHub Secrets, gate changes by path, let Claude review the diff, and leave the merge to a person.
