Stop Claude Code loading other teams' CLAUDE.md files with claudeMdExcludes
Keep a monorepo root or another team's CLAUDE.md out of your context with claudeMdExcludes: pattern syntax, which settings file to use, what cannot be excluded, and how to verify.
Contents
Start claude inside a large monorepo and you often get the repository root's CLAUDE.md, plus files from other teams' directories, loaded into your context. Claude Code walks upward from the current directory looking for CLAUDE.md, so this is by design, but it means instructions that have nothing to do with your work take up context and can conflict with your own.
In short: list the files you do not want under claudeMdExcludes in a settings file, as absolute paths or glob patterns, and Claude Code skips just those files when it loads memory.
KEY POINT
What you will learn
- How to write
claudeMdExcludes, and that patterns match against absolute paths - Which settings file to put it in, and how multiple layers combine
- What cannot be excluded (managed policy files) and how to verify the result
What is happening
At startup Claude Code loads every CLAUDE.md and CLAUDE.local.md from the current directory and all of its parents, concatenates them, and puts them into context. Files in subdirectories below the current directory are added later, when Claude reads files in those directories.
So launching in monorepo/teams/payments/ always loads monorepo/CLAUDE.md, and touching anything under monorepo/teams/search/ pulls in monorepo/teams/search/CLAUDE.md too. The loading rules themselves are covered in When does Claude Code load a CLAUDE.md in a subdirectory?.
用語解説
Memory files: the instruction files Claude Code loads at the start of every session: CLAUDE.md, CLAUDE.local.md, and the rule files under .claude/rules/.
Writing claudeMdExcludes
claudeMdExcludes is an array of strings. Each entry is a glob pattern or an absolute path, and patterns are matched against the file's absolute path. A bare repository-relative path will not match.
{
"claudeMdExcludes": [
"**/monorepo/CLAUDE.md",
"/home/user/monorepo/teams/search/.claude/rules/**"
]
}
| Item | Value or example | Notes |
|---|---|---|
| Type | array of strings | glob patterns or absolute paths |
| Matched against | the file's absolute path | lead with **/ as in **/vendor/**/CLAUDE.md |
| Default | unset | every CLAUDE.md found is loaded |
| Where | any settings file | arrays merge across layers |
The official example excludes a top-level file with "**/monorepo/CLAUDE.md" and another team's rules directory with an absolute path such as "/home/user/monorepo/other-team/.claude/rules/**". Rule files under .claude/rules/ are excluded with the same key.
Which settings file to use
Because the files you are excluding are irrelevant to your work, the docs suggest .claude/settings.local.json, which keeps the exclusion on your machine and out of your teammates' sessions. For something the whole team wants out, such as vendored code, .claude/settings.json checked into the repository is fine too. The settings layers are described in Designing permissions in settings.json.
When the key appears in more than one layer, the arrays are merged, not overridden. A project settings file cannot re-enable a file your user settings exclude.
Managed policy files cannot be excluded
Exclusions apply only to user, project, and local memory files. A CLAUDE.md your organization deploys to the managed policy location, or instructions injected through the claudeMd key in managed-settings.json, still load no matter what you list in claudeMdExcludes.
Verifying it worked
Start a new session and run /context. If the excluded file no longer appears under Memory files, the setting is working. If it is still listed, the pattern is not matching the absolute path: add a leading **/ or write the full path.
If the real problem is that instructions are in the wrong place rather than the wrong file being loaded, revisit the hierarchy guidance in How to write CLAUDE.md first. Splitting root and package files properly often removes the need for exclusions altogether.
Summary
- In a monorepo, loading the root and other teams' CLAUDE.md is expected.
claudeMdExcludesskips specific files - Patterns match absolute paths: lead with
**/or write the full path - Put personal exclusions in
.claude/settings.local.json; arrays merge across layers - Managed policy CLAUDE.md and
claudeMdinstructions cannot be excluded - Verify with the Memory files list in
/context
FAQ
- Which settings file should claudeMdExcludes go in?
- Any of them: user, project, local, or managed. For an exclusion that only affects you, .claude/settings.local.json is the right place. Arrays merge across layers.
- Can I exclude a CLAUDE.md deployed by my organization?
- No. Exclusions apply only to user, project, and local memory files. Managed policy CLAUDE.md files always load.
- How do I check that the exclusion works?
- Run /context in a session and confirm the file is missing from the Memory files list.
Primary sources
This article was drafted by AI from official documentation and reviewed by the site operator before publishing. Found a mistake? Let us know via the contact page.