[FEATURE] Provide way to exclude parent CLAUDE.md files from auto-loading in subdirectories
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When working in a subdirectory of a large monorepo, Claude Code recursively loads all parent CLAUDE.md files into context with no way to opt out. This causes large irrelevant documentation to consume context tokens unnecessarily, thereby degrading performance and usefulness of Claude Code.
Per the memory documentation:
Claude Code reads memories recursively: starting in the cwd, Claude Code recurses up to (but not including) the root directory / and reads any CLAUDE.md or CLAUDE.local.md files it finds.
This behavior is problematic for monorepos with multiple teams/tech stacks where parent-level documentation is irrelevant to subdirectory work.
Example Scenario
monorepo/
├── CLAUDE.md (40k+ chars - Go microservices docs)
├── services/
│ ├── ui-app/ # Frontend app
│ │ ├── CLAUDE.md # Frontend-specific docs
│ │ └── packages/
│ │ └── app/ # <- Working directory
│ │ └── CLAUDE.md
Currently loaded: All 3 CLAUDE.md files, including backend Go service documentation that's irrelevant to the working directory.
Desired: Only load the 2 UI-related CLAUDE.md files, excluding the one in root directory.
Proposed Solution
The ideal solution is some sort of setting or configuration knob to customize CLAUDE.md loading, that can be checked in to main repo (something akin to a .gitignore).
Alternative Solutions
Tried denying permission to read from CLAUDE.md in .claude/settings.json - this doesn't work as this controls tool uses by Claude Code but not auto-loading CLAUDE.md into the context window.
Priority
High - Significant impact on productivity
Feature Category
Configuration and settings
Use Case Example
_No response_
Additional Context
Related issues:
- #3232 - Context duplication in worktrees (closed as not planned)
- #15332 - Conditionally skip
~/.claude/CLAUDE.mdbased on working directory (closed as duplicate of #3232)
Showing cached comments. Read the full discussion on GitHub ↗
9 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
+1 on this — this is causing real issues in our workflow.
We have a project structure like dev-env/src/shop/ where shop/ is a fully independent git repository with its own CLAUDE.md, AGENT.md, .claude/settings.local.json, etc.
When launching Claude Code from shop/, it traverses up to dev-env/ and loads directives from there that are completely unrelated to the current project. This causes confusion, conflicting instructions, and potential errors — Claude ends up mixing context from different projects.
The presence of a .git directory in shop/ should be a natural boundary, but it's completely ignored.
Suggested solutions (any of these would help):
A flag in .claude/settings.local.json like "disableParentTraversal": true
Respect .git boundaries by default — if the cwd has its own .git, stop traversing upward
A CLAUDE.md directive like # ROOT that tells Claude Code "this is the top level, don't go higher"
This is critical for anyone working in multi-project structures (monorepos, dev environments with multiple independent repos nested under a common folder). Without a way to control this, the memory system actively works against project isolation.
Needing this for similar reasons, we've got a repo for setting up multiple workspaces that can share infrastructure (e.g, share one postgres instance across multiple worktrees, each with their own DB). there's a CLAUDE.md in that repo root for working on the setup itself. the workspaces live in a gitignored folder within that repo - so when you're working within the workspace, we're ending up loading up irrelevant context from the infra sharing repo.
+1 to the problem statement, but I think the best fix is configurable resolution policy rather than only exclusions.
claudeMdExcludeshelps, but in monorepos/worktrees it can become ongoing maintenance. A frontmatter policy would be cleaner and deterministic:Key point: some users need parent inheritance, others need strict project isolation. A mode switch in the resolver supports both without breaking either.
+1 on this. Same problem in a nested project structure:
Three issues caused by this:
/memorylist becomes cluttered with unrelated parent CLAUDE.md files, making it harder to identify which memory is relevant.Current workaround is renaming the parent CLAUDE.md to a different name and using
@importwhen needed — works but is fragile.Related: #34209 covers the same inheritance problem specifically for
.claude/rules/files (not justCLAUDE.md). Includes detailed testing showing that selective symlinks and removing symlinks both fail to prevent parent rule loading, plus quantified context waste for multi-language governance setups./tmp/issue-20880-comment.md
Looks like an exclude feature has been added:
Exclude specific CLAUDE.md files
In large monorepos, ancestor CLAUDE.md files may contain instructions that aren’t relevant to your work. The
claudeMdExcludessetting lets you skip specific files by path or glob pattern.https://code.claude.com/docs/en/memory#exclude-specific-claude-md-files
+1. Please fix this!