The CLAUDE.md Hierarchy: User, Project and Directory Files, How They Stack, and the Team Rule Stuck on One Laptop
Ben clones the shop app and Claude doesn't know how to run the tests, though it does on Asha's laptop. The rule is in her user file, which git never sees. Learn the three CLAUDE.md levels, how they stack, and how to check what is loaded with /memory.
What you will learn
- Place a rule in the user, project or directory CLAUDE.md by who needs it
- Explain how the three levels stack, and when a directory file loads
- Diagnose a team rule that only works for one developer because it lives in ~/.claude/CLAUDE.md
- Check what is loaded with /memory, and keep personal project notes in CLAUDE.local.md
Before you start
- Running Claude Code in a terminal
- Basic git: clone, commit, push
Ben joins the team on Monday. He clones the shop app, opens Claude Code and asks: how do I run the tests? Claude has no idea. On Asha's laptop it knows perfectly well. Same repo, same Claude.
Nothing is broken. Claude Code reads instructions from up to three kinds of CLAUDE.md file, each with its own home, and the test rule is sitting in the wrong one.
The rule never left her laptop
Asha wanted Claude to always run the tests with pytest -q. So she wrote that rule in a file in her own home folder, ~/.claude/CLAUDE.md, and Claude followed it every time. Then she pushed the repo. That file isn't inside the repo, so git never saw it. Ben clones, asks his question, and Claude has nothing to go on.
House rules, room rules, your diary
Think of a house. The house rules are on the fridge (shoes off, dinner at eight), and everyone who lives there gets them. That's the project file. Your room can have rules too, like "knock first", and they only matter when you're in that room. That's the directory file. And your diary holds your own notes and taste; nobody else reads it. That's the user file.
| Level | Where it lives | Who gets it |
|---|---|---|
| User | ~/.claude/CLAUDE.md | Only you, in every project you open |
| Project | ./CLAUDE.md in the repo root, or ./.claude/CLAUDE.md | Everyone who clones, through git |
| Directory | A CLAUDE.md inside one subfolder, like api/ | Loaded on demand, when Claude works with files in that folder |
The docs also call the project file "project instructions".
They stack, and all of them load
The files don't replace each other. Together they make the instructions. Say Claude is working on files in api/: it reads all three, and they add up. Now it works in web/. There's no CLAUDE.md in web/, so only the user and project files load.
The three files in the shop app
The project file: ./CLAUDE.md
# shop-app
## Tests
- Run the tests with: pytest -q
- Every new function gets a test in a *_test.py file next to it.
## Code style
- Python 3.12, with type hints on every function.
- Format with: ruff format
- Keep functions under 30 lines.
The test command, where tests sit, type hints and the formatter. Every teammate needs these, so they belong here, and everyone who clones gets them. You can ask Claude to write this file for you: "Create a CLAUDE.md in the repo root for a Python shop-app. Include the test command pytest -q, type hints on every function and ruff format."
The directory file: api/CLAUDE.md
# api/ rules
- Every endpoint returns JSON errors, never an HTML page.
- Error shape: {"error": "message", "code": 404}
- Validate input at the top of each route.
These rules only matter when Claude touches api/. The file loads on demand, when Claude works with files in that folder.
The user file: a sample of ~/.claude/CLAUDE.md
The project carries Asha's personal file as user-CLAUDE.md, so you can see it. The real one lives in her home folder.
<!-- SAMPLE. The real file lives at ~/.claude/CLAUDE.md (your user -->
<!-- folder, outside the repo). Only you read it. Not in git. -->
# Asha's personal notes
- Reply briefly, in bullet points.
- Explain with small examples.
- Run the tests with: pytest -q
<!-- ^ a TEAM rule. Move it to the project CLAUDE.md for Ben. -->
"Reply briefly" and "explain with small examples" are personal taste, and they're fine here. But "Run the tests with: pytest -q" is a team rule, and in this file nobody else will ever get it. The fix is to move that one line into the project CLAUDE.md and commit it. Ben gets it on his next clone. The lecture's prompt for it: "My user CLAUDE.md has the team test rule. Move that line into the project CLAUDE.md and delete it from my user file."
Ask /memory what is loaded
To check what Claude actually has, open Claude Code in the terminal and type /memory. It lists the memory files by level, user and project. Pick one and it opens in your editor, even a file that doesn't exist yet, so you can create it from there.
For Ben's case, that's the quickest diagnosis: if the project file has no test rule, the rule isn't coming from git. You can also just ask: "Which CLAUDE.md files are loaded in this session, and which one does the test command come from?"
CLAUDE.local.md: personal, for one project
Sometimes a note is personal but only makes sense in one repo, like your own shortcut for this project. That goes in CLAUDE.local.md in the repo root. It's a personal file for this one project; add it to .gitignore so it stays out of git.
All of these files are advice that Claude reads as context. When a rule must be enforced rather than followed, it belongs in settings or a hook instead; that layering is covered in CLAUDE.md, settings.json and plugins.
Common mistakes
- A team rule in
~/.claude/CLAUDE.md. It works for you and nobody else. Move it to the project file. - Folder rules in the root file. API-only rules in
./CLAUDE.mdload for every task. Put them inapi/CLAUDE.md. - Expecting a directory file to replace the project file. It adds to it. All the levels that apply load together.
- Committing personal notes. Personal notes for one project go in
CLAUDE.local.md, kept out of git.
How this shows up in a question
The classic symptom: a new developer clones the repo, and Claude ignores the team's test rule, while it works for the maintainer. The most likely cause is that the rule sits in the maintainer's user-level file, which is never shared. Watch for distractors about file length, a newer model, or /memory "downloading" rules; /memory shows and opens files, it doesn't fetch anything.
Quick recap
| File | For | In git? |
|---|---|---|
~/.claude/CLAUDE.md | Your taste, in every project | No |
./CLAUDE.md or ./.claude/CLAUDE.md | Team rules for this repo | Yes |
api/CLAUDE.md | Rules for one folder, loaded on demand | Yes |
CLAUDE.local.md | Your notes for this one repo | No, in .gitignore |
Put each rule where the people who need it will get it. For the wider team setup (which settings win, CI, plugins across repos), see rolling out Claude Code to a team. The three CLAUDE.md files for this lesson are in the community, free to join.
Try it yourself
In a project of your own, put one personal line in ~/.claude/CLAUDE.md and one team line in ./CLAUDE.md. Run /memory and check both levels are listed. Then add a CLAUDE.md to one subfolder and ask Claude a question about a file in that folder, and one about a file outside it.
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.
