Configure CLAUDE.md files with appropriate hierarchy, scoping, and modular organization
Learning objectives
By the end of this topic, you should be able to:
- Place personal, team and directory-specific instructions at an appropriate scope.
- Organize shared guidance with imports and focused rule files.
- Distinguish files that exist from instructions actually loaded into a session.
- Diagnose missing or conflicting guidance without confusing Markdown instructions with permission settings.
Choose the audience and scope first
CLAUDE.md supplies persistent contextual guidance to Claude Code. Typical content includes project structure, coding conventions, useful commands and review expectations. It is not an access-control system merely because it contains words such as "must" or "never."
The source describes these useful scopes:
| Scope | Example location | Appropriate purpose |
|---|---|---|
| User | ~/.claude/CLAUDE.md |
Personal preferences used across that user's projects. |
| Shared project | Root CLAUDE.md or .claude/CLAUDE.md |
Team-maintained guidance distributed with the repository. |
| Directory | A package or subdirectory's CLAUDE.md |
Conventions relevant to that part of the project. |
| Personal project-local | CLAUDE.local.md |
Private project-specific notes, excluded from shared source control as appropriate. |
An organization may also distribute managed guidance and settings. Keep their functions distinct: behavioral guidance explains expected work; supported permission and sandbox settings enforce access boundaries. Do not copy scalar/array merge rules from a settings schema and apply them mechanically to Markdown prose.
Shared guidance must be in shared material
A new teammate does not receive another developer's home-directory instructions simply by cloning a repository. Put team conventions in a committed project file and commit its required shared imports too. Keep personal machine paths and credentials out of that shared guidance.
Directory-specific guidance should refine the relevant work without pretending to revoke an organizational access restriction. If instructions conflict, identify their authority and intended scope rather than blending incompatible requirements. Inspect the actual project root and worktree before concluding that the intended file was discovered.
A gitignored local instruction file may exist only in the worktree where it was created. Do not assume it is present in another checkout or on a teammate's machine. A private import can support a personal setup, but it cannot be a required hidden dependency for a reproducible team workflow.
Use actual import syntax and resolve its path correctly
An import reference uses an at-prefixed path such as:
@docs/testing-standards.md
@docs/api-conventions.md
Place these references in the appropriate instruction file. A relative path is resolved relative to the file containing the reference, not whichever directory happens to be current when the session runs. This matters when a package-level instruction file imports a shared standard elsewhere in the repository.
The supplied material distinguishes actual references from examples inside Markdown code spans or fenced blocks. A code-formatted @docs/testing-standards.md in explanatory prose is a literal example, not a request to import the file. Inspect the actual instruction text when a supposed import is missing.
Keep import chains shallow and inspect the client's supported recursion behavior. An import improves organization but does not eliminate the tokens of the imported content when it is loaded. Importing every package standard into the root file can recreate a monolithic context burden.
Split large guidance into maintained topics
Use .claude/rules/ for focused Markdown rules, for example testing, API design and deployment conventions. Give each file a coherent purpose and an owner or maintenance context. Keep stable shared requirements in one authoritative place rather than copying slightly different versions into several files.
Rules without conditional path metadata apply broadly in the described loading model. Path-scoped rules can restrict when relevant guidance is loaded. A directory tree under .claude/rules/ is organization, not by itself a condition on which source files receive those rules.
The more specific rule still needs enough context to be understood. Do not reduce a testing rule to an unexplained command if users need to know which suite it runs or what failure means. Conversely, avoid loading unrelated deployment detail for every small source edit.
Verify loading as well as storage
The source describes ancestor instructions loaded as a session starts and deeper directory guidance loaded when relevant files are inspected. Exact behavior can depend on the client's configuration and selected sources. A file being available on disk does not establish that it influenced the current response.
Use the described /memory interface to inspect or manage memory/instruction file locations. Use /context or the corresponding current-session inspection mechanism to examine what is actually in context. Distinguish editing a file from proving that the active session has incorporated it.
When behavior differs across sessions, check the project root, file scope, included imports, active configuration sources and current context. If needed, test a representative task with an expected convention and inspect its result. Do not infer correct loading solely because the model confidently describes the rule.
Worked example: a team convention stored in the wrong place
In this invented repository, a maintainer requires tests for public API changes but records that requirement only in their personal ~/.claude/CLAUDE.md. A teammate clones the repository and does not receive the convention.
A supported repair is to place shared guidance in the repository and organize its details explicitly:
CLAUDE.md
docs/
testing-standards.md
.claude/
rules/
api-conventions.md
packages/
reports/
CLAUDE.md
The root instruction file can import @docs/testing-standards.md. The reports package's instruction file carries only its package-specific conventions. The maintainer keeps personal editor preferences in their user file and does not make the shared import depend on that private path.
The acceptance check is concrete: on the teammate's checkout, the shared files exist, the import resolves, the applicable guidance is loaded for a representative public-API task, and the resulting plan includes the required tests. If the file appears in a management menu but not in the active context, loading still needs diagnosis.
This is an expected configuration and verification workflow, not a claim that a live Claude Code session or teammate environment was tested.
Source-scoped details and unresolved limits
These details describe the supplied source snapshot. Its cited original anchor documents were not supplied for independent inspection, and no current-client loading test was performed. They should be checked against the actual supported client before use.
The snapshot lists managed guidance at these OS-specific locations:
| Environment | Managed instruction file |
|---|---|
| macOS | /Library/Application Support/ClaudeCode/CLAUDE.md |
| Linux and WSL | /etc/claude-code/CLAUDE.md |
| Windows | C:\Program Files\ClaudeCode\CLAUDE.md |
Managed guidance is an organization-wide source in that model; its presence does not turn Markdown into hard enforcement. The snapshot also describes embedding behavioral text under claudeMd in managed-settings.json. It says this key is honored only in managed/policy settings, with no effect in user, project or local settings. The following JSON illustrates that narrow role:
{
"claudeMd": "Use the team's documented review criteria."
}
For mandatory restrictions, the snapshot instead identifies supported settings such as permissions.deny for tools/commands/paths, sandbox.enabled for isolation, env for environment and provider routing, and forceLoginMethod/forceLoginOrgUUID for login/organization restrictions. Configure them only within actual authority and supported policy. Scalar override and array concatenation describe structured settings contracts; they do not define deterministic merging of contradictory Markdown.
The source advises keeping an individual CLAUDE.md under roughly 200 lines for clarity/adherence. This is an editorial target, not a hard file limit, total context cap or Auto memory limit. Imported contents still consume context when loaded. Recursive imports are supported in the described model, but U01—the source's exact four-hop cutoff—remains explicitly pending. This article does not independently confirm that number or require reliance on it. U02's advanced glob expansion limits also remain pending in the separate path-rule topic.
Complete modular-rule example
In the snapshot, all .md files under .claude/rules/ are discovered recursively. Unscoped rules load at launch with the same project priority as root .claude/CLAUDE.md; only supported path metadata makes a rule conditional. The original rendered --/list-marker fragments are malformed frontmatter. These are repaired, illustrative files, not observed successful configuration:
File: .claude/rules/team.md
# Team conventions
State which checks were actually run and identify any untested change.
File: .claude/rules/testing/tests.md
---
paths:
- "**/*.test.ts"
- "tests/**/*.ts"
---
# Testing conventions
Give each test a descriptive behavior name and replace live external services with fixtures.
Under the declared project-root pattern model, reading src/cart.test.ts or tests/cart.ts is expected to make the testing rule applicable. Reading src/cart.ts is not. Merely listing src/cart.test.ts is not the matching read trigger. The unscoped team rule is startup guidance for all three cases, assuming the project source is enabled. These sample conventions are choices for this invented team, not universal React/pytest or examination obligations. Validate accepted YAML, exact path match, actual included rule and observed behavior separately.
The snapshot says excluding project from --setting-sources skips project rules. It reports a pre-v2.1.211 inconsistency in which on-demand and nested rules could still load despite that exclusion. Treat this as a source-attributed version condition: check the installed release, source selection and relevant file read before diagnosing absence, nonmatch or a broken rule. Neither file existence nor a release number is a runtime result.
Imports, private files and saved memory
The described import mechanism also accepts absolute references, within the actual permitted filesystem scope. Moving the containing CLAUDE.md can change the meaning of each relative reference; re-resolve and verify its intended target. A path string does not itself supply access or prove ingestion.
Adding CLAUDE.local.md to .gitignore does not untrack a previously committed file or undo a separate copy/publication. Inspect the actual tracking state and recipients. An ignored local file remains local to its worktree; an accessible authorized personal home import can serve multiple worktrees, while a required team dependency belongs in shared committed material.
Explicit instruction files differ from Auto memory: the former contain developer-authored guidance, while the latter contains notes Claude generates from corrections/preferences in the source model. To target explicit storage, request "add this to CLAUDE.md" or edit that file deliberately rather than assume a general preference went there. The snapshot describes Auto memory toggles/folder access in /memory; these controls and defaults are client-specific.
/memory can list potential locations even when their files do not yet exist. Selecting one may create and open it. File entry, existence, editor opening, saved bytes, current loading and actual compliance are separate states. Use /context's current Memory files view to inspect loading, then inspect the relevant file and conflicts. A menu entry is not ingestion evidence.
For editing, the snapshot says GUI editors permit continued session interaction, whereas a terminal editor occupies the terminal until exit. It reports that before v2.1.216, /memory waited for the opened file to close. Qualify that interface detail to the installed client, save the intended content and inspect subsequent inclusion. No editor was opened or file saved by this example.
Finally, replace an ambiguous instruction such as "format code nicely" with the actual intended convention, for example "Use two-space indentation in this package." Reconcile incompatible text and keep it consistent with actual mandatory policy. Check loading and a representative result after any authorized edit; precise wording improves guidance but does not guarantee obedience.
Guidance load order and policy authority
The supplied snapshot describes broad-to-specific instruction inclusion as managed → user → project → local, with project guidance appearing after user guidance. Applicable directory instructions refine the relevant subtree when their actual loading condition is met. This describes guidance ordering and refinement; it is not a JSON scalar/array merge rule or a deterministic resolution of contradictory Markdown. Supported client-enforced managed permission and sandbox settings retain their real priority: later project or local prose cannot grant an otherwise forbidden action. Check actual enabled sources and loaded context before claiming that this described order occurred in a session.
Interpret examples and evidence explicitly
The supplied terminology registry names Path Scoping through YAML paths frontmatter. Its Path Scoping entry has needs_review: true; the YAML entry has needs_review: false. Both prohibit automatic promotion to an authoritative anchor. Those are editorial registry statuses, not tests of a parser, a current release, matching reads or effective permissions. The detailed domain description supplies the positive loading conditions; the registry helps name them. Here CLI means Command Line Interface, not an independent source of version support.
The snapshot's concrete import examples include @docs/workflow-guide.md and @src/standards.md. Its selective package example uses @docs/api-standards.md, @src/package-specific-style.md and @README.md. A maintainer chooses the relevant documents deliberately; a README or package metadata file does not gain authority to override mandatory policy merely by being referenced. The snapshot also describes /init with a personal option for setting up local preferences. Treat that as an attributed interface option: inspect the actual saved file and Git tracking state before assuming it exists or is private. No such command is run here.
Import resolution: declared inputs and expected results
Assume an authorized illustrative project at /workspace/shop, an instruction file at /workspace/shop/CLAUDE.md, and a session launched at /workspace/shop/packages/reports. The following is the proposed complete instruction-file content. Its fence is literal within this article; it would be active text only if deliberately saved outside code markup in the instruction file:
# Shared review guidance
@docs/testing-standards.md
Assume the permitted target /workspace/shop/docs/testing-standards.md exists with this complete illustrative content:
# Public API changes
Plan a behavior test for each changed public API and report whether the test was actually run.
| Declared input or event | Expected resolution or conclusion | Evidence still needed |
|---|---|---|
| Root instruction file above, permitted existing target, enabled supported source | Resolve the target to /workspace/shop/docs/testing-standards.md, irrespective of the deeper launch directory. |
Inspect current included content; this paper example reports no session ingestion. |
| The same reference inside a valid code span or fenced block in that instruction file | Treat it as literal text, not an active import. | Inspect actual saved markup; rendered appearance alone is insufficient. |
Containing file moved to /workspace/shop/packages/reports/CLAUDE.md, unchanged relative reference |
The proposed target becomes /workspace/shop/packages/reports/docs/testing-standards.md; if absent, do not count the old root standard as included. |
Re-resolve the intended authorized target and inspect the supported client's actual result. |
| Absolute target outside the granted filesystem scope | A path string grants no access; do not assert the content was read. | Obtain any necessary authorization through the actual access mechanism before reading. |
| Intended target absent, inaccessible or source enablement unknown | Inclusion is unverified; preserve the missing/access/unknown distinction. | Inspect the relevant failure or configuration evidence; do not fabricate an exact client error string. |
Rule loading and teammate handoff: complete expected cases
For the two complete rule files above, assume the supported corrected-release branch, project-root pattern base and authorized readable files. These are expected outcomes, not a client test:
| Enabled source, input and event | Expected rule content | Expected status |
|---|---|---|
| Project enabled; launch only | Unscoped team rule is startup guidance; the testing rule is not inferred from launch alone. | Inspect actual context before claiming inclusion. |
Project enabled; read src/cart.test.ts |
Team rule plus the testing conventions, under the declared matching model. | Expected matching-read applicability. |
Project enabled; read tests/cart.ts |
Team rule plus testing conventions. | Expected second positive case. |
Project enabled; read src/cart.ts |
Team rule; the two supplied test patterns do not select this path. | Expected negative testing-rule case. |
Project enabled; only list src/cart.test.ts |
Do not infer the matching-read trigger from a listing. | Testing inclusion remains unverified. |
Project excluded in the corrected-release branch; read src/cart.test.ts |
Neither of these project rules should be counted as included through that excluded source. | Expected source-exclusion case; earlier reported releases need separate inspection. |
| Source selection or installed release unknown | Do not choose the corrected-release outcome by assumption. | Unresolved until the actual selection/release and context are inspected. |
Required rule file missing, or frontmatter still the malformed -- fragment |
Do not claim the promised scoped instruction was configured or loaded. | Inspect file/parser evidence and repair only within authority; no invented runtime diagnostic. |
| File saved and expected match, but absent from current Memory files view | The source model's current-inclusion criterion is not met. | Continue source/path/trigger diagnostics; saving is not proof of loading. |
For the invented teammate's public-API change, use the shared file contents above, the authorized task "Plan the reports API change without editing code," and an assumed verified inclusion of the applicable guidance. A complete expected plan is: "Identify the changed public API; plan a behavior test covering its changed behavior; report that no test was run during this planning-only task." This supplies the promised test-planning output while staying within the requested action. If the instruction is only in another user's home file, do not claim that cloning delivered it. If expected shared guidance is missing from actual context, diagnose its placement, committed dependencies, enabled source and read trigger before attributing a root cause. No teammate session, commit, source edit, test, editor or configuration deployment occurred in this article.
Summary
Scope guidance by its audience, commit shared dependencies and resolve imports from their containing files. Use focused rules without assuming that splitting files alone reduces active context. Verify what was actually loaded, and keep contextual instructions separate from enforceable permissions and settings.
