Which CLAUDE.md Applies in a Monorepo?
Use a read-only, two-folder test to see which Claude Code instructions load and catch conflicts between repository and package guidance.
Claude Code can load several CLAUDE.md files in the same session. In a monorepo, put shared instructions at the root and keep package-specific instructions next to the package. Check which files actually loaded before drawing conclusions about which instruction Claude followed.
What loads when you start from the repository root?
Anthropic documents that Claude Code loads applicable CLAUDE.md and CLAUDE.local.md files from the working directory and its ancestors at launch. Nested instructions can load when Claude reads files in those directories. Starting inside a package therefore gives you a different starting context from opening the repository root and entering the package later. A nested file can add guidance alongside the root file. Avoid relying on it to resolve contradictory directions automatically.
Test with two folders and no code changes
- In a disposable repository or branch, put a harmless shared convention in the root CLAUDE.md. Add separate CLAUDE.md files under frontend and backend. Give each a distinctive instruction for read-only summaries, such as reporting the relevant package name.
- Open a fresh Claude Code session from the root. Run /memory to inspect instruction locations. Ask Claude to read a specific file in frontend using its file-reading tool and summarize it without editing anything. Check whether it follows the package convention and the root convention.
- Repeat from the root in another fresh session with a file in backend. Separate sessions help you tell which instructions come from the current task rather than earlier turns. If you need an audit of load events, Anthropic documents the InstructionsLoaded hook. Use an existing approved audit setup where available.
- Compare the two results with the instructions you wrote. If one file loads but Claude ignores a rule, simplify the wording or remove the conflict. If a file does not load, check the working directory, filename, the file actually read, and any exclusions before changing the instructions.
Fictional example
A monorepo asks for every review to include a short risk summary. The frontend package also asks reviewers to mention keyboard access when reviewing a UI component. The backend package asks reviewers to name any migration risk when reviewing a database change. Those rules can coexist. If the root says every package uses npm but a package explicitly uses pnpm, move the package-manager choice into the relevant package guidance. Then repeat the read-only test and confirm Claude describes the correct command without running it.
Questions people ask
Does the nearest CLAUDE.md replace the root file?
Start by assuming both can be relevant and inspect what is loaded. Put genuine repository-wide conventions at the root. Put local details in package instructions or use documented path-scoped rules. If both files give conflicting directions, rewrite them so each scope is unambiguous.
Why did my test work in the terminal but differ elsewhere?
Record the client, version, working directory, and how Claude accessed the package file. A community report describes different loading behavior depending on the tool used. It does not establish the cause in your environment. Repeat the same read-only test before concluding that the instruction file is broken.
Can I exclude an ancestor file for a local test?
Anthropic documents local exclusions through claudeMdExcludes, with managed CLAUDE.md files outside that feature’s scope. Prefer checking the natural loading behavior first. Use a local exclusion only for a permitted test where you can explain precisely which instruction file is being removed and why.
Sources
Claude Code documentation — project instructions and load behavior
GitHub discussion — ancestor instructions in subdirectories
GitHub report — nested instruction loading and tool differences