Skip to main content
guidesSource-backed

CLAUDE.md Hierarchy for Monorepos and Nested Packages

A practical walkthrough of structuring CLAUDE.md across a monorepo: how files load up the directory tree and on demand in subdirectories, path-scoped rules, imports, excluding other teams' files, and keeping per-package context lean.

by JPette1783·added 2026-06-05·
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://code.claude.com/docs/en/large-codebases, https://github.com/JSONbored/awesome-claude/blob/main/content/guides/claude-md-hierarchy-for-monorepos-and-nested-packages.mdx
Safety notes
CLAUDE.md is context, not enforcement; for rules that must always hold (block a path, run a check before commit), use a PreToolUse hook or managed settings, not prose., Conflicting instructions across nested CLAUDE.md files cause Claude to pick one arbitrarily; review the hierarchy periodically to remove contradictions., Managed-policy CLAUDE.md cannot be excluded by individual settings; keep organization-wide rules there when they must always apply.
Privacy notes
CLAUDE.md and loaded rules are sent to the model provider every session; keep secrets and sensitive data out of them, and use CLAUDE.local.md (gitignored) for personal notes., @path imports load the referenced files into context at launch; do not import files containing credentials., In large monorepos, other teams' CLAUDE.md may load unexpectedly; use claudeMdExcludes to avoid pulling in unrelated or sensitive context.
Author
JPette1783
Submitted by
JPette1783
Claim status
unclaimed
Last verified
2026-06-05

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

63

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Needs review

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    No reviewed flag detected in metadata.

    Pending

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

Copy & paste

Copy-ready — paste the snippet to get started.

Adoption plan

Balanced adoption plan

Current risk score 24/100. Use staged verification before broader rollout.

Risk 24

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    No review metadata found; increase manual validation.

    Pending
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Missing required evidence: Metadata review. Risk score 31.

Risk 31

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Missing

Review metadata is missing.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required gaps: Metadata review

Decision timeline

Decision timeline · balanced

Blocking gaps: Check metadata review status. Risk 28.

Risk 28

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is missing.

Pending

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

Blockers: Check metadata review status

Prerequisite readiness

Prerequisite readiness

3 prerequisites to line up before setup.

0/3 ready
General3

Safety & privacy surface

Safety & privacy surface

3 safety and 3 privacy notes across 3 risk areas. Review closely: credentials & tokens.

3 areas
  • SafetyLocal filesCLAUDE.md is context, not enforcement; for rules that must always hold (block a path, run a check before commit), use a PreToolUse hook or managed settings, not prose.
  • SafetyLocal filesConflicting instructions across nested CLAUDE.md files cause Claude to pick one arbitrarily; review the hierarchy periodically to remove contradictions.
  • SafetyGeneralManaged-policy CLAUDE.md cannot be excluded by individual settings; keep organization-wide rules there when they must always apply.
  • PrivacyCredentials & tokensCLAUDE.md and loaded rules are sent to the model provider every session; keep secrets and sensitive data out of them, and use CLAUDE.local.md (gitignored) for personal notes.
  • PrivacyCredentials & tokens@path imports load the referenced files into context at launch; do not import files containing credentials.
  • PrivacyGeneralIn large monorepos, other teams' CLAUDE.md may load unexpectedly; use claudeMdExcludes to avoid pulling in unrelated or sensitive context.

Safety notes

  • CLAUDE.md is context, not enforcement; for rules that must always hold (block a path, run a check before commit), use a PreToolUse hook or managed settings, not prose.
  • Conflicting instructions across nested CLAUDE.md files cause Claude to pick one arbitrarily; review the hierarchy periodically to remove contradictions.
  • Managed-policy CLAUDE.md cannot be excluded by individual settings; keep organization-wide rules there when they must always apply.

Privacy notes

  • CLAUDE.md and loaded rules are sent to the model provider every session; keep secrets and sensitive data out of them, and use CLAUDE.local.md (gitignored) for personal notes.
  • @path imports load the referenced files into context at launch; do not import files containing credentials.
  • In large monorepos, other teams' CLAUDE.md may load unexpectedly; use claudeMdExcludes to avoid pulling in unrelated or sensitive context.

Prerequisites

  • A monorepo or multi-package repository where you use Claude Code.
  • Edit access to root and per-package CLAUDE.md files and .claude/rules/ directories.
  • An understanding of which instructions are repo-wide versus package-specific.

Schema details

Install type
copy
Troubleshooting
No
Full copyable content
## Overview

In a monorepo, a single root CLAUDE.md cannot capture every package's
conventions without becoming huge and noisy. Claude Code loads CLAUDE.md files
hierarchically, so you can place repo-wide rules at the root and package-specific
rules deeper in the tree. This guide covers how that hierarchy loads and how to
keep per-package context lean.

## How files load

Claude Code walks up the directory tree from the working directory, loading every
`CLAUDE.md` and `CLAUDE.local.md` along the way. Content is concatenated from the
filesystem root down to the working directory, so the most specific instructions
are read last. Files in subdirectories below your working directory are not loaded
at launch; they load on demand when Claude reads files in those directories.

For `packages/api/`, that means `./CLAUDE.md`, `packages/CLAUDE.md`, and
`packages/api/CLAUDE.md` all contribute, with the deepest read last.

## Recommended monorepo structure

```text
monorepo/
  CLAUDE.md                 # repo-wide: build, conventions, layout
  .claude/rules/            # repo-wide topic rules (optionally path-scoped)
  packages/
    api/
      CLAUDE.md             # API package conventions (loads on demand)
    web/
      CLAUDE.md             # web package conventions (loads on demand)
```

Keep the root CLAUDE.md under ~200 lines and focused on what every session needs.
Push package-specific detail into nested CLAUDE.md files or path-scoped rules.

## Path-scoped rules

Instead of nesting many CLAUDE.md files, scope rules to file patterns with
`.claude/rules/` frontmatter so they load only when Claude touches matching files:

```markdown
---
paths:
  - "packages/api/**/*.ts"
---

# API package rules
- All endpoints validate input.
- Use the standard error response format.
```

Rules without a `paths` field load every session at the same priority as
`.claude/CLAUDE.md`.

## Imports

Pull shared context into a package CLAUDE.md with `@path` imports (relative or
absolute, max four hops). Imported files load at launch, so use them for
organization, not for reducing context.

## Exclude other teams' files

In a large monorepo, ancestor CLAUDE.md files from other teams may load. Skip them
with `claudeMdExcludes` in `.claude/settings.local.json`:

```json
{
  "claudeMdExcludes": [
    "**/monorepo/other-team/CLAUDE.md",
    "/abs/path/other-team/.claude/rules/**"
  ]
}
```

Managed-policy CLAUDE.md cannot be excluded.

## Tips

- Run `/memory` to confirm which CLAUDE.md and rules files loaded for the session.
- Use `CLAUDE.local.md` (gitignored) for personal, per-package preferences.
- After `/compact`, the project-root CLAUDE.md is re-injected; nested files reload
  only when Claude next reads a file in that subdirectory.

## Source

- Monorepos and large repos: https://code.claude.com/docs/en/large-codebases
- How Claude remembers your project: https://code.claude.com/docs/en/memory

About this resource

Overview

In a monorepo, a single root CLAUDE.md cannot capture every package's conventions without becoming huge and noisy. Claude Code loads CLAUDE.md files hierarchically, so you can place repo-wide rules at the root and package-specific rules deeper in the tree. This guide covers how that hierarchy loads and how to keep per-package context lean.

How files load

Claude Code walks up the directory tree from the working directory, loading every CLAUDE.md and CLAUDE.local.md along the way. Content is concatenated from the filesystem root down to the working directory, so the most specific instructions are read last. Files in subdirectories below your working directory are not loaded at launch; they load on demand when Claude reads files in those directories.

For packages/api/, that means ./CLAUDE.md, packages/CLAUDE.md, and packages/api/CLAUDE.md all contribute, with the deepest read last.

Recommended monorepo structure

monorepo/
  CLAUDE.md                 # repo-wide: build, conventions, layout
  .claude/rules/            # repo-wide topic rules (optionally path-scoped)
  packages/
    api/
      CLAUDE.md             # API package conventions (loads on demand)
    web/
      CLAUDE.md             # web package conventions (loads on demand)

Keep the root CLAUDE.md under ~200 lines and focused on what every session needs. Push package-specific detail into nested CLAUDE.md files or path-scoped rules.

Path-scoped rules

Instead of nesting many CLAUDE.md files, scope rules to file patterns with .claude/rules/ frontmatter so they load only when Claude touches matching files:

---
paths:
  - "packages/api/**/*.ts"
---

# API package rules
- All endpoints validate input.
- Use the standard error response format.

Rules without a paths field load every session at the same priority as .claude/CLAUDE.md.

Imports

Pull shared context into a package CLAUDE.md with @path imports (relative or absolute, max four hops). Imported files load at launch, so use them for organization, not for reducing context.

Exclude other teams' files

In a large monorepo, ancestor CLAUDE.md files from other teams may load. Skip them with claudeMdExcludes in .claude/settings.local.json:

{
  "claudeMdExcludes": [
    "**/monorepo/other-team/CLAUDE.md",
    "/abs/path/other-team/.claude/rules/**"
  ]
}

Managed-policy CLAUDE.md cannot be excluded.

Tips

  • Run /memory to confirm which CLAUDE.md and rules files loaded for the session.
  • Use CLAUDE.local.md (gitignored) for personal, per-package preferences.
  • After /compact, the project-root CLAUDE.md is re-injected; nested files reload only when Claude next reads a file in that subdirectory.

Source

Source citations

Add this badge to your README

Show that CLAUDE.md Hierarchy for Monorepos and Nested Packages is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/guides/claude-md-hierarchy-for-monorepos-and-nested-packages.svg)](https://heyclau.de/entry/guides/claude-md-hierarchy-for-monorepos-and-nested-packages)

How it compares

CLAUDE.md Hierarchy for Monorepos and Nested Packages side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

2 trust signals differ across this comparison (Source provenance, Submitter).

Field

A practical walkthrough of structuring CLAUDE.md across a monorepo: how files load up the directory tree and on demand in subdirectories, path-scoped rules, imports, excluding other teams' files, and keeping per-package context lean.

Open dossier

How to give Claude Code access to more than one directory: the --add-dir flag, the /add-dir command, and the permissions.additionalDirectories setting, plus how each one handles CLAUDE.md, rules, and skills in monorepos.

Open dossier

Set up sparse context for large codebases in Claude Code: scoped directories, CLAUDE.md hierarchy, subagents, and avoiding whole-repo loading.

Open dossier

Source-backed checklist for reviewing Claude Code MCP client configuration before a team rollout, covering scopes, transports, commands, secrets, allowlists, denylists, approvals, and rollback.

Open dossier
Next steps
Trust
Review statusNot reviewedNot reviewedNot reviewedNot reviewed
Package trustPackage not verifiedPackage not verifiedPackage not verifiedPackage not verified
Source provenanceDiffersSource-backedSource-backedSubmission linkedSource submissionSource-backed
SubmitterDiffersJPette1783kiannidevYB0y
Install riskReview firstReview firstReview firstReview first
Notes Safety ✓ Privacy ✓ Safety ✓ Privacy ✓ Safety ✓ Privacy ✓ Safety ✓ Privacy ✓
Brand
Categoryguidesguidesguidesguides
SourceSource-backedSource-backedSource-backedSource-backed
AuthorJPette1783JSONboredkiannidevYB0y
Added2026-06-052025-10-272026-06-142026-06-10
Platforms
Harness
Source repo
Safety notesCLAUDE.md is context, not enforcement; for rules that must always hold (block a path, run a check before commit), use a PreToolUse hook or managed settings, not prose. Conflicting instructions across nested CLAUDE.md files cause Claude to pick one arbitrarily; review the hierarchy periodically to remove contradictions. Managed-policy CLAUDE.md cannot be excluded by individual settings; keep organization-wide rules there when they must always apply.Any directory you grant with --add-dir, /add-dir, or additionalDirectories is readable and editable by Claude in that session; only add directories you intend Claude to modify.Sparse context reduces accidental edits outside the intended package but does not replace code review—verify diff scope before merge. Do not disable permission prompts to speed up large-repo exploration. When using subagents for exploration, constrain file access to approved directories.Local stdio MCP servers execute commands with the user's privileges, so review the exact command, arguments, package runner, file paths, and network behavior before sharing a config. Remote MCP servers can expose model-controlled tools for production systems; require least-privilege scopes, explicit approval for write tools, and a rollback path before team rollout. Do not rely on server names alone for enforcement because names are user-assigned labels; use command or URL allowlist entries when policy must control what actually runs.
Privacy notesCLAUDE.md and loaded rules are sent to the model provider every session; keep secrets and sensitive data out of them, and use CLAUDE.local.md (gitignored) for personal notes. @path imports load the referenced files into context at launch; do not import files containing credentials. In large monorepos, other teams' CLAUDE.md may load unexpectedly; use claudeMdExcludes to avoid pulling in unrelated or sensitive context.Granting a directory exposes its file contents to the session and the model provider; do not add directories containing secrets or unrelated private code.Large-repo CLAUDE.md files may reference internal service names across business units; scope instructions to teams that should see them. Sparse setups often use multiple CLAUDE.md files; ensure nested files do not leak restricted submodule details to broader teams. Exploration subagents may still read sensitive paths if permissions are too broad—align with least-privilege directory scope.MCP client configuration can reveal server URLs, internal hostnames, command paths, environment-variable names, header names, OAuth client IDs, and tool availability. Do not store API keys, bearer tokens, client secrets, tenant IDs, or personal credentials in shared `.mcp.json`, managed-mcp.json, PR bodies, issue comments, logs, or screenshots. Tool arguments, tool results, resources, prompts, logs, traces, and OAuth metadata can expose private repositories, tickets, databases, user identities, and workspace data.
Prerequisites
  • A monorepo or multi-package repository where you use Claude Code.
  • Edit access to root and per-package CLAUDE.md files and .claude/rules/ directories.
  • An understanding of which instructions are repo-wide versus package-specific.
  • Claude Code installed and runnable as `claude`.
  • A working directory you start Claude from; additional directories are granted relative to it.
  • A monorepo or large codebase where whole-repo context is impractical.
  • Documented package boundaries, ownership maps, or architecture overviews.
  • Permission to configure multi-directory or scoped working sets in Claude Code.
  • Representative tasks spanning one package—not the entire tree.
  • A draft `.mcp.json`, `~/.claude.json` entry, plugin-provided MCP server, claude.ai connector plan, or managed-mcp.json deployment to review.
  • The server documentation, package or repository source, expected transport, command or URL, environment variables, headers, OAuth behavior, and tool list.
  • A test machine or disposable Claude Code profile where the configuration can be loaded with non-production data.
  • A named owner who can approve the rollout, publish the final configuration, and revoke credentials or block servers if the rollout fails.
Install
Config
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed
Open 4 picks in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.