CLAUDE.md Configuration Guide: Hierarchy, @import and Path-Specific Rules
👋 In plain words: CLAUDE.md is a plain text file where you write instructions Claude Code reads every time, such as 'use pytest' or 'never edit generated files'. Where you put that file decides who gets the rules. This lesson shows how to set it up so the whole team gets the same behaviour.
CLAUDE.md is how you give Claude Code persistent project knowledge. The exam tests where instructions live, who receives them, and how to keep them modular so the right conventions load at the right time (Task Statements 3.1 and 3.3).
🔑 Key terms
- CLAUDE.md: A Markdown file of standing instructions that Claude Code loads automatically.
- User level:
~/.claude/CLAUDE.mdon your own machine. Only you get these rules. - Project level:
CLAUDE.mdin the repository. Everyone who clones it gets these rules. - @import: A line in CLAUDE.md that pulls in another file's contents.
- Path-specific rule: A rule file in
.claude/rules/that loads only when Claude edits matching files.
📖 The story in this lesson
A new tester joins Ravi's team and Claude Code ignores the team's test conventions on their laptop. The reason: Ravi had put the rules in his personal CLAUDE.md.
💡 Think of it like this
CLAUDE.md levels are like notices in a company. A sticky note on your own monitor (user level) is for you alone. A notice on the office board (project level) reaches everyone. A sign on the lab door (directory or path rules) applies only to people working in that room.
🏛️ The three-level hierarchy
| Level | Location | Shared with team? |
|---|---|---|
| User | ~/.claude/CLAUDE.md | No — only you |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md | Yes, via git |
| Directory | packages/api/CLAUDE.md | Yes; applies when working there |
🌍 Real-world example: The rules the new hire never got
Ravi moves 'Use Playwright fixtures, never hard-coded waits' from ~/.claude/CLAUDE.md into the repository's CLAUDE.md and commits it. The next morning the new tester pulls the repository and Claude follows the rule on their laptop too.
📎 Keep it modular with @import
# packages/payments/CLAUDE.md
Payments service conventions.
@docs/standards/pci.md
@docs/standards/error-handling.md
Each package imports only the standards relevant to it, instead of loading everything everywhere.
🌍 Real-world example: Payment rules only where they matter
The payments package needs PCI security rules, but the storefront doesn't. The payments CLAUDE.md imports only the files it needs, so storefront work never loads irrelevant rules.
# packages/payments/CLAUDE.md
@docs/standards/pci.md
@docs/standards/error-handling.md📏 .claude/rules/ and path-specific rules
Split a huge CLAUDE.md into topic files such as testing.md, api-conventions.md and deployment.md in .claude/rules/. Add YAML frontmatter with paths globs so a rule loads only when Claude edits matching files:
---
paths: ["**/*.test.tsx", "**/*.test.ts"]
---
Use React Testing Library. One behaviour per test. No snapshot tests.
Path-scoped rules beat directory CLAUDE.md files when matching files are scattered (tests next to components, Terraform in many service folders), and they save context because irrelevant rules never load.
🌍 Real-world example: Test rules that follow the test files
ShopNest's test files sit next to the code they test, in dozens of folders. One rule file with a paths pattern applies the testing conventions wherever a test file lives, and only when Claude edits a test.
---
paths: ["**/*.spec.ts"]
---
Use page objects. One behaviour per test.🧠 Debug with /memory
When two developers see different behaviour, run /memory in each session to see exactly which memory files are loaded. It is the first diagnostic for hierarchy problems.
🌍 Real-world example: Why do our laptops behave differently?
Two testers get different results from the same request. Each runs /memory and compares the list of loaded files. One laptop still has an old personal rule file that overrides the team setup.
~/.claude/CLAUDE.md. Only you get them. Team rules belong in the repository.🛠️ Try it yourself (about 8 minutes)
- In a test repository, run
/initin Claude Code to create a CLAUDE.md. - Add one rule, such as 'Write tests with pytest'.
- Run
/memoryand find your file in the list. - Ask Claude to write a small test and check it follows the rule.
✅ You are done when: /memory shows the project CLAUDE.md and the generated test follows your rule.
🧪 Exam-Style Practice Questions
Try these before opening the answers. They use the same scenario style as the real exam.
Question 1. Your packages/payments/CLAUDE.md should include the PCI standards file but not the frontend style guide. What's the cleanest method?
- A.
@importthe PCI standards file in that package's CLAUDE.md - B. Copy-paste the PCI text into it
- C. Create a skill
- D. Put everything in the root
Show answer
Answer: A. Selective, modular imports. B duplicates text that will drift. D loads irrelevant rules everywhere. C isn't always-on.
Question 2. Test files sit next to their sources throughout the repo. What's the best way to apply testing conventions automatically?
- A. Root CLAUDE.md
- B. A CLAUDE.md in each folder
- C. A
/testcommand - D. A
.claude/rules/testing.mdwithpaths: ["**/*.test.*"]
Show answer
Answer: D. Glob-scoped rules follow file types wherever they are. B is impractical for scattered files. C needs manual invocation. A loads the rules always and relies on inference.
Question 3. What's the key difference between a skill and CLAUDE.md?
- A. CLAUDE.md can't be shared
- B. Skills are invoked on demand for specific tasks; CLAUDE.md holds always-loaded standards
- C. Skills can't restrict tools
- D. Skills are always loaded
Show answer
Answer: B. D is reversed. A: project CLAUDE.md is shared. C: allowed-tools restricts them.
📝 Assignment
Do these tasks in order. Each one has a Done when check, so you know when it is complete. The stretch task is optional but close to what the exam expects from an architect. Keep your answers in one notes file or Git repository, and revisit them in your final week of revision together with the cheat sheet in the last lesson of this course.
- Task 1: Run /init in a repository, then move one team convention from your user-level file into the project CLAUDE.md.
✅ Done when: A teammate who pulls the repository gets the convention without changing their own machine, and /memory shows the project file. - Task 2: Create .claude/rules/testing.md with a paths glob for test files and confirm it loads only when you edit a test.
✅ Done when: The testing rule appears when you edit a test file and does not appear when you edit an unrelated source file. - Stretch: split a long CLAUDE.md into three rule files and use @import for one shared standards document.
✅ Done when: The original CLAUDE.md is shorter, the three rule files each cover one topic, and the imported file loads where you expect.
❓ Frequently Asked Questions
🤔 Why doesn't my teammate get my CLAUDE.md rules?
They are probably in ~/.claude/CLAUDE.md, which is personal. Put team rules in the project CLAUDE.md.
🤔 What does @import do in CLAUDE.md?
It pulls another file's contents into CLAUDE.md, so each package can include only the standards it needs.
🤔 When should I use .claude/rules with paths?
When conventions apply to files spread across many folders, such as all test files.
🤔 How do I see which memory files are loaded?
Run /memory in the Claude Code session.
🏁 Summary
- User-level = personal; project-level = team.
- @import for modular standards; .claude/rules/ for topic files.
pathsglobs load conventions only for matching files, wherever they live./memoryshows what’s loaded.
Next, continue with Claude Code Slash Commands and Skills (SKILL.md Frontmatter).
Independent study material by SQA Tools. Not affiliated with, endorsed by or sponsored by Anthropic. Claude is a trademark of Anthropic. Mock questions are original practice items, not real exam content. Exam facts checked against Anthropic's official exam guides and certification FAQ on 11 November 2026.