0Pricing
Claude Architect · Leçon

Niveaux utilisateur, projet et répertoire

Où se trouve chaque CLAUDE.md et à qui il s’applique.

Niveaux utilisateur, projet et répertoire est une leçon Claude Architect gratuite sur CoddyKit. Ceci est la leçon 1 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Claude Architect, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Claude Architect comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

Three Places a CLAUDE.md Can Live

Claude Code reads memory from three levels, and each one answers a different question: who does this rule apply to?

  • User level — ~/.claude/CLAUDE.md: your personal preferences, on your machine only.
  • Project level — ./CLAUDE.md or .claude/CLAUDE.md: shared with the whole team via version control.
  • Directory level — a CLAUDE.md inside a subfolder: scoped to that subtree only.

Knowing which file a rule belongs in is a core Claude Certified Architect skill. Put it in the wrong place and either your teammates miss it, or your personal habits leak into everyone's workflow.

User Level — Personal, NOT Shared

The user-level file at ~/.claude/CLAUDE.md lives in your home directory. It applies to every project you open on this machine, but it travels with you, not the repo.

Critically, it is NOT shared via version control. A new teammate cloning the repo will never see it. So it is the right home for personal taste: your preferred commit-message style, how chatty you like responses, or shell aliases you favor.

It is the wrong home for anything the team must agree on — coding standards, build commands, security rules.

# ~/.claude/CLAUDE.md  (personal, machine-local, never committed)

## My preferences
- Keep explanations short; show the command, not a paragraph.
- Prefer `rg` over `grep` and `fd` over `find` on my machine.
- Use Conventional Commits for messages.

Project Level — Shared via VCS

The project-level file lives at the repo root as ./CLAUDE.md (or .claude/CLAUDE.md). Because it sits inside the repository, it is committed and shared via version control.

That is exactly what you want for rules the whole team relies on: the build command, test framework, architectural conventions, directory layout, and anything a new contributor needs on day one.

Rule of thumb: if a fresh clone would break without it, it belongs in the project-level CLAUDE.md — not in your personal user file.

# ./CLAUDE.md  (repo root — committed, shared by everyone)

## Build & Test
- Build:  yarn build
- Test:   yarn test --runInBand
- Lint must pass before every commit.

## Conventions
- NestJS modules under src/<feature>/.
- All DB access goes through the repository layer, never inline SQL.

Directory Level — Scoped to a Subtree

A CLAUDE.md placed inside a subfolder is directory-scoped: it applies only when Claude is working within that subtree. This keeps narrow, local rules close to the code they govern.

Example: a frontend/CLAUDE.md can hold React/Tailwind conventions that make no sense for the backend, while services/payments/CLAUDE.md can carry rules that only matter for billing code.

Directory-level files are still committed (they live in the repo), so they are shared — but their reach is the folder, not the whole project.

# frontend/CLAUDE.md  (scoped to the frontend subtree)

## UI conventions (apply only under frontend/)
- Components are function components with hooks; no class components.
- Style with Tailwind utility classes; avoid inline style objects.
- Co-locate tests as Component.test.tsx next to the component.

How the Levels Combine

The levels are additive context, not mutually exclusive. When you work in a subfolder, Claude can draw on the user file, the project file, and the directory file together.

Think of it as concentric scopes:

  • User — broadest reach (every project), narrowest audience (just you).
  • Project — whole repo, whole team.
  • Directory — one subtree, whole team.

So the question is never only "how specific is this rule?" but also "who needs to see it — me, or everyone?" Audience decides user vs project; scope decides project vs directory.

The Classic Mistake: Team Rules in the User File

The most common anti-pattern: putting a rule everyone depends on into ~/.claude/CLAUDE.md. It works perfectly for you — so the gap is invisible — but because the user file is never shared via VCS, new teammates miss it entirely.

Symptoms: Claude follows the convention on your machine and ignores it on a colleague's, and nobody can figure out why. The fix is always the same: move shared rules down into the project-level (or directory-level) CLAUDE.md so they ship with the repo.

Modularize with @path Imports

A CLAUDE.md does not have to be one giant file. You can pull in other files with @path imports, which keeps each file focused and readable.

For example, a project file can import a shared standards document instead of inlining hundreds of lines. This makes the hierarchy easier to maintain and lets you reuse the same standards across files.

# ./CLAUDE.md  (project root)

## Engineering standards
@./standards/coding-style.md
@./standards/security.md

## Build
- Build: yarn build

Path-Scoped Rules with .claude/rules/

A monolithic CLAUDE.md loads into context for every task — even when most of it is irrelevant — wasting tokens. A cleaner pattern for narrow rules is .claude/rules/ files with YAML frontmatter.

Each rule file declares a paths pattern, and it loads only when you are editing matching files. This gives you directory-level precision while saving context, because rules that don't match the current file are never pulled in.

# .claude/rules/migrations.md
---
paths:
  - "db/migrations/**"
---

- Every migration must be reversible (provide a down step).
- Never edit a migration that has already shipped; add a new one.

Editing Memory: /memory and /init

You don't have to hand-edit these files in an external editor. Inside Claude Code, the /memory command opens and edits the CLAUDE.md memory, and changes persist across sessions.

For a brand-new repository, /init bootstraps a project-level CLAUDE.md by documenting the codebase, giving you a sensible starting point you can then refine.

Choosing which file /memory writes to still comes back to the same decision: personal (user) versus shared (project or directory).

# In an interactive Claude Code session:
/init      # generate a project-level CLAUDE.md from the codebase
/memory    # open and edit CLAUDE.md; edits persist across sessions

Skills and Commands Follow the Same Split

This user-versus-project split is not unique to CLAUDE.md — it is a consistent Claude Code pattern. Skills and commands use the exact same two scopes:

  • Project scope — .claude/skills/ and .claude/commands/ in the repo are shared via VCS.
  • User scope — ~/.claude/skills/ is personal.

Note that .claude/commands/ is the legacy form and .claude/skills/ is the current one, but the scoping rule is identical: repo = team, home = you. Learn the split once and it applies everywhere.

Keep Secrets Out of Committed Files

Because project-level and directory-level files are committed to version control, treat them like public code: never put secrets in them. The same discipline applies to a project-scoped .mcp.json (shared in VCS) versus the personal ~/.claude.json.

For tokens and keys, reference environment variables — for example ${GITHUB_TOKEN} — instead of pasting the raw value. The shared file says which variable to use; the actual secret stays in the environment, out of the repo and out of CLAUDE.md.

// .mcp.json  (committed — references env vars, never raw secrets)
{
  "mcpServers": {
    "github": {
      "command": "github-mcp",
      "env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
    }
  }
}

Quick Check: Where Does the Rule Go?

Your team agrees on a build command and a test framework that every contributor must use. A new engineer just cloned the repo. Where should this rule live so that Claude Code applies it for the whole team from day one?

Recap: Audience and Scope Decide the Level

Pick the level by answering two questions — who and where:

  • User (~/.claude/CLAUDE.md): personal, every project, NOT shared via VCS — new teammates miss it. Use for personal preferences only.
  • Project (./CLAUDE.md): shared via VCS, whole team, whole repo. The home for build commands and conventions everyone needs.
  • Directory (subfolder CLAUDE.md): shared via VCS but scoped to one subtree.

Keep files lean with @path imports and load narrow rules on demand via .claude/rules/ with paths frontmatter. Never commit secrets — reference env vars like ${GITHUB_TOKEN}. The biggest trap to avoid: putting team rules in your personal user file, where everyone else will silently never see them.

Questions Fréquemment Posées

La leçon « Niveaux utilisateur, projet et répertoire » est-elle gratuite ?

Oui — le texte complet de « Niveaux utilisateur, projet et répertoire » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Claude Architect, passe à CoddyKit PRO. Le cours Claude Architect comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « Niveaux utilisateur, projet et répertoire » ?

Où se trouve chaque CLAUDE.md et à qui il s’applique. Tu pratiques Claude Architect avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer Claude Architect ?

Aucune expérience préalable n'est requise. Claude Architect sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 1 sur 4.

Combien de temps prend la leçon « Niveaux utilisateur, projet et répertoire » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon Claude Architect ?

Oui. Chaque leçon Claude Architect inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Niveaux utilisateur, projet et répertoire
  2. Syntaxe d’importation @path
  3. .claude/rules/ avec chemins dans les métadonnées
  4. Règles monolithiques ou modulaires
← Retour à Claude Architect