skip to content

In a monorepo, Claude Code launched at the root ignores the conventions in packages/billing/CLAUDE.md — how do CLAUDE.md files load, and what do you change?

level: seniorimportance: should knowfreq 14%

answer

  1. where you launched matters
  2. ancestors at launch, subdirectories later
  3. loaded when Claude reads a file there
  4. concatenated root-down, never overridden
  5. claudeMdExcludes and /context Memory files

basics

~20 s

Claude Code loads CLAUDE.md from the launch directory and its ancestors at startup, but a subdirectory's file only when Claude reads a file there; all are concatenated root-down, never overriding. Launch from the package or use a path-scoped rule.

solid answer

~40 s

At launch Claude Code loads `CLAUDE.md` and `CLAUDE.local.md` from the working directory and every directory above it. A `CLAUDE.md` in a subdirectory is discovered but included only when Claude reads a file in that subdirectory, so from the repository root `packages/billing/CLAUDE.md` is absent until Claude opens a billing file. Everything that loads is concatenated, ordered from the filesystem root down, so a nested file is read later but does not override its parent; if the root and the package disagree, Claude may follow either. The fixes: launch `claude` from `packages/billing/`, or move the rule into `.claude/rules/` with a `paths:` glob, remove contradictions from the root file, use `claudeMdExcludes` to skip other teams' files, and confirm with `/context` under **Memory files**.

code

json · 6 lines
json
{
  "claudeMdExcludes": [
    "**/packages/legacy-*/**",
    "/home/dev/monorepo/packages/web/CLAUDE.md"
  ]
}

go deeper

for a junior

Recall that the launch directory and its parents load at startup, and that /context lists the loaded memory files.

for a middle

Explain on-demand loading of subdirectory files and the root-down concatenation order, with CLAUDE.local.md after CLAUDE.md.

for a senior

Diagnose the monorepo case from loading rules, remove contradictions rather than rely on override, and choose launch directory, path-scoped rules or claudeMdExcludes deliberately.

for a principal

Decide how a large organization splits guidance between root, package files, rules and managed policy, and who owns each layer.

## The scenario A monorepo has a root `CLAUDE.md` with repository-wide rules and a `packages/billing/CLAUDE.md` with that package's conventions, say "store amounts as integer cents; never use floats". A developer launches `claude` at the repository root, asks for a billing change, and the plan uses floats. Nothing is broken. This is how loading works, and fixing it starts with knowing the three rules below. ## How Claude Code discovers and loads CLAUDE.md files 1. **At launch**, Claude Code loads `CLAUDE.md` and `CLAUDE.local.md` from the working directory **and every directory above it**. Run it in `foo/bar/` and it loads `foo/bar/CLAUDE.md`, `foo/CLAUDE.md` and any `CLAUDE.local.md` beside them. 2. **Subdirectory files are discovered, not loaded.** A `CLAUDE.md` below the working directory is included **on demand, when Claude reads files in that subdirectory**. 3. Everything loaded is **concatenated, not overridden**. Content is ordered from the filesystem root down to the working directory, and within one directory `CLAUDE.local.md` follows `CLAUDE.md`. Instructions closer to where you launched are simply read **last**. From the root, then, `packages/billing/CLAUDE.md` is not in context at all until Claude opens a file in that package. If Claude plans from the root conventions, or answers before reading anything there, the package's rules never reach it. ## Concatenation makes conflicts your job Because nothing overrides, "the more specific file wins" is not a rule Claude Code applies. If the root says "use Jest" and a package says "use Vitest", **both are in context**, and the docs warn that Claude **may pick one arbitrarily**. The fix is editorial: let the root file state only what is true everywhere, and let package files add to it rather than contradict it. | Mechanism | When it loads | Good for | | --- | --- | --- | | Ancestor `CLAUDE.md` | At launch | Repository-wide rules | | Subdirectory `CLAUDE.md` | When Claude reads a file in that directory | Conventions owned by a package's team, versioned beside its code | | `.claude/rules/` file with `paths:` | When Claude works with a file matching the glob | Conventions kept in one central place, or spread across scattered paths | | Managed policy `CLAUDE.md` | At launch, always | Organization-wide guidance | ## What to change - **Launch from the package.** Starting `claude` in `packages/billing/` loads that package's file and the root file at launch, with no other package's instructions in context. - **Or move the rule into `.claude/rules/`** at the root with `paths: ["packages/billing/**"]`, so it loads as soon as Claude works with a matching file, whatever the launch directory. - **Remove contradictions** between the root file and package files. - **Exclude what isn't yours.** Launched at the root, Claude picks up other teams' files as it reads around the tree. The `claudeMdExcludes` setting skips specific CLAUDE.md and rules files by glob or absolute path, and patterns are matched against **absolute** file paths. It works at any settings scope (user, project, local or managed), and **arrays merge across scopes**, so a team can set project defaults while an individual adds more in `.claude/settings.local.json`. - `claudeMdExcludes` **cannot** remove the managed policy CLAUDE.md; organization-wide guidance always applies. A related case runs the other way: with `--add-dir`, CLAUDE.md files in the added directories are **not** loaded unless `CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1` is set. ## A diagnosis sequence 1. Run `/context` straight after launching at the root: the root file is listed under **Memory files**, the billing file is not. 2. Ask Claude to read one billing file, then run `/context` again: the package file should now appear. 3. If it appears but is still ignored, look for a contradicting line in the root file or in a user-level rule. 4. If it never appears, check `claudeMdExcludes` at every scope for an over-broad glob such as `**/packages/**`. ## Verifying what loaded - `/context` lists the loaded files under **Memory files**. A file missing from that list is a file Claude cannot see. - An `InstructionsLoaded` hook fires whenever a CLAUDE.md or rules file loads, at session start or lazily, and reports a load reason such as `session_start`, `nested_traversal` or `path_glob_match`. Logging it answers "did the billing file load, and when" directly. - Large monorepos often end up with both mechanisms: per-package files for teams that own their conventions, path-scoped rules for cross-cutting ones. Whatever loads, it remains guidance. If a billing rule must hold regardless of what the model decides, such as never touching a ledger directory, the enforcing layer is a permission rule or a hook, not another CLAUDE.md line.

  • When should a package's conventions be a nested CLAUDE.md rather than a path-scoped rule?
    A nested `CLAUDE.md` lives beside the code, so the package's owners maintain it and it is versioned with their changes; it loads at launch from that directory or when Claude reads a file there. A path-scoped rule lives centrally in `.claude/rules/` and suits conventions you want in one place or that apply to many scattered paths.
  • How can you tell exactly when a nested CLAUDE.md loaded during a Claude Code session?
    `/context` shows the files loaded so far under **Memory files**. For a timeline, an `InstructionsLoaded` hook fires on every CLAUDE.md or rules load and carries a load reason, such as `session_start` for launch or `nested_traversal` for a subdirectory file picked up while Claude read files there.

  • A deeper CLAUDE.md overrides its parent's instructions
  • Every subdirectory CLAUDE.md loads when the session starts
  • When files conflict, the most specific one always wins
  • claudeMdExcludes can remove the managed policy CLAUDE.md
  • Conflicting CLAUDE.md files produce a startup error