Claude Certified Architect

Foundations · CCAR-F

Domain 3 — 20%

Task 3.1

CLAUDE.md Hierarchy

User, project, and directory-level configuration precedence

📘What You Need to Know

Three Configuration Levels

CLAUDE.md is the persistent onboarding document Claude Code reads before every interaction. Unlike a one-off prompt, it survives across sessions and gives Claude durable context about how your project works. The exam tests three distinct levels, each with a different scope and storage location.

User-level config lives at ~/.claude/CLAUDE.md and applies personal preferences across every project you open — editor habits, preferred comment style, or how verbose you want responses. Project-level config lives at .claude/CLAUDE.md inside the repository and is committed to git so the whole team shares the same standards. Directory-level config is a CLAUDE.md file placed in any subdirectory; it scopes instructions to that folder and everything beneath it.

  • •User (~/.claude/CLAUDE.md): personal preferences across all projects
  • •Project (.claude/CLAUDE.md): team standards shared via version control
  • •Directory (CLAUDE.md in any directory): scoped to that directory and below
🔑Key Concept

Think of it like CSS specificity: the closer the rule is to the file being edited, the higher its precedence.

Precedence: More Specific Wins

When instructions conflict across levels, more specific configuration overrides more general configuration. The precedence order is Directory > Project > User. If your user-level CLAUDE.md says "prefer tabs" but the project-level file says "use 2-space indentation," the project rule wins when you are working in that repo. If the project says "use Jest" but a directory-level CLAUDE.md inside /src/legacy/ says "this folder uses Mocha — do not migrate tests," the directory rule wins for files in that subtree.

This hierarchy lets teams set global defaults while carving out exceptions for legacy modules, experimental features, or microservices with different conventions. The exam frequently presents a scenario with conflicting rules at two levels and asks which one applies.

Modular Config with @import

A single monolithic CLAUDE.md becomes hard to review, merge, and maintain as your project grows. The @import directive lets you split configuration into focused files and compose them in the root CLAUDE.md. For example, @import ./rules/typescript.md loads TypeScript-specific conventions, while @import ./rules/api.md loads REST API standards.

Imports keep pull requests small — a change to testing rules only touches testing.md, not the entire config. They also let different team leads own different rule files without constant merge conflicts on one giant document.

# .claude/CLAUDE.md
@import ./rules/typescript.md
@import ./rules/testing.md
@import ./rules/security.md

## Project Overview
Monorepo with /apps/web (Next.js) and /apps/api (Express).

.claude/rules/ — Auto-Loaded Glob-Scoped Rules

Beyond manually imported files, Claude Code auto-loads rule files from .claude/rules/. These rules activate automatically based on which files Claude is working with — you do not invoke them with a slash command. Each rule file can include YAML frontmatter with a paths glob pattern that scopes when the rule applies.

This is powerful for enforcing conventions that differ by file type. A rule with paths: ["**/*.test.tsx"] might mandate React Testing Library patterns, while a rule with paths: ["**/api/**"] might require input validation on every route handler. When Claude edits a file matching the glob, the rule loads silently into context.

---
paths:
  - "**/*.test.tsx"
---
# Testing Rules
Always use React Testing Library, never Enzyme.
Test behavior, not implementation.
Prefer screen.getByRole over getByTestId.
💡Tip

Rules in .claude/rules/ are automatic and glob-scoped. Commands in .claude/commands/ are manual and user-invoked. Do not confuse the two on the exam.

What Belongs at Each Level

User level: personal workflow preferences that should never be committed — response verbosity, preferred shell aliases, or how you like commit messages formatted when you are the author. Project level: team-wide standards everyone must follow — coding conventions, architecture overview, test commands, CI expectations, and security requirements. Directory level: local exceptions — legacy code constraints, framework-specific patterns, or service-specific API contracts.

The most common configuration mistake is putting personal preferences in project-level CLAUDE.md. That commits your habits to git and forces them on teammates. Keep personal prefs at ~/.claude/CLAUDE.md and team standards in .claude/CLAUDE.md.

⚠️Watch out

Never put personal preferences in project-level CLAUDE.md — use ~/.claude/CLAUDE.md for personal settings and .claude/CLAUDE.md for team standards.

⚠️Exam Traps

Trap: Personal preferences in project-level CLAUDE.md

Why it's wrong: Personal settings get committed to git and affect the whole team, even when they conflict with team standards.

Correct approach: User-level (~/.claude/CLAUDE.md) for personal preferences; project-level (.claude/CLAUDE.md) for team standards.

Trap: One massive CLAUDE.md instead of modular rules

Why it's wrong: Hard to maintain, review in PRs, and scope to specific directories or file types.

Correct approach: Use @import for modular files and .claude/rules/ with path-specific YAML frontmatter.

Trap: Believing user-level config overrides directory-level config

Why it's wrong: Precedence flows from general to specific: directory beats project beats user.

Correct approach: Directory > Project > User — more specific configuration always wins.

Trap: Using slash commands when glob-scoped auto-rules are needed

Why it's wrong: Commands require manual invocation; they do not activate automatically when editing matching files.

Correct approach: Use .claude/rules/ with paths globs for automatic, file-type-specific enforcement.

✓Concept Check

A monorepo has project-level CLAUDE.md requiring Jest for all tests. The /src/legacy/ directory has its own CLAUDE.md saying "use Mocha — do not migrate." A developer edits /src/legacy/auth.test.js. Which testing framework rule applies?

🔨Build Exercise

Beginner35 minutes

Set Up Modular CLAUDE.md Hierarchy

What you'll learn

  • •Configure user, project, and directory-level CLAUDE.md files
  • •Use @import for modular rule composition
  • •Create glob-scoped rules in .claude/rules/