[BUG] CLAUDE.md files in subdirectories are not being automatically loaded
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: Claude Code CLI
- Claude CLI version: <!-- output of
claude --version--> latest version - Operating System: macOS
- Terminal: <!-- not specified in post -->
Bug Description
CLAUDE.md files in subdirectories are not being automatically loaded when accessing files in those directories, contrary to what the documentation states. The memory system only loads CLAUDE.md files from parent directories (recursively up), but not from the current working directory when reading files.
Steps to Reproduce
- Create a project structure:
- /project/
- CLAUDE.md
- src/
- credits/
- CLAUDE.md
- error.ts
- Add content to
/project/CLAUDE.md(root level) - Add test content to
/project/src/credits/CLAUDE.md(subdirectory level) - Ask Claude to review the file
/src/credits/error.ts - Check Claude's context/memory
Expected Behavior
According to the official documentation, when working in /project/src/credits/ or reading files in that directory, Claude should load:
/project/CLAUDE.md(recursively up) ✅/project/src/credits/CLAUDE.md(current directory) ✅
The docs specifically state: "When reading files in subdirs: /project/src/feature/subdir/CLAUDE.md ✅ (loaded on access)"
Actual Behavior
- Claude only loads the root
/project/CLAUDE.md✅ - Claude does NOT automatically load
/project/src/credits/CLAUDE.md❌ - The subdirectory CLAUDE.md file must be manually attached to the conversation
Additional Context
This behavior contradicts the documented memory loading pattern. The documentation suggests that CLAUDE.md files should be loaded from the directory containing the file being accessed, but in practice, only parent directory CLAUDE.md files are being loaded.
This significantly impacts the ability to use directory-specific context and instructions, which is a key feature of the memory system for organizing large projects.
[EDIT]: Creating this again because it's not solved.
Claude Code team: Please, don't just close bug reports on rapid-fire style... that doesn't solve the issues, just bury them and leave the user (the client) with a pretty bad feeling for the product and company 🙏🏻
30 Comments
Proof:
!Image
!Image
Here's a simple script to reproduce.
Ran similar tests to those outlined above and came to the same conclusion. Any updates here? This is a really critical piece of functionality for monorepo style codebases where you run claude code from the root directory.
My temporary workaround is to simply reference the nested claude.md files within the root claude.md. This loses the dynamic loading functionality (less context efficiency) but for now this is working okay for me.
Agree. I am hoping though that the new subagents functionality reduces the need for this.
I want to add some clarity to this ticket.
Claude Code _DOES_ in fact load
CLAUDE.mdfiles in subdirectories whenever it invokes theRead()tool to read a file (e.g. if you say "Please inspect ./path/to/file and tell me how many lines it contains").HOWEVER, if the user uses
@path/to/filewithin their prompt to inject the file into the context, it WILL NOT have the same behavior.This is unexpected and contrary to what the documentation would suggest and I believe it qualifies as a bug.
I currently get around this by specifically telling Claude to gather sub-directory context where I know it exists. (e.g. "if I ask you about anything in
path/todirectory, ALWAYS readpath/to/CLAUDE.mdfirst if you do not have it in your context window")@mikegreiling Thenk you for the analysis. However when I tested the behavior, it does not read the subdirectory CLAUDE.md file whether I mention the file or not.
At least in 1.0.72.
This is the test script I used. I hope this can help CC team to reproduce the issue.
Just tested and same behaviour (running
1.0.79version.The behaviour I see matches @mikegreiling's.
The problem is with the
@mentions not including theCLAUDE.md's along the path.I have a gist with a workaround.
TL;DR; just tell Claude on the root
CLAUDE.mdabout this bug and that it needs to manually perform the reads anyway.@icorderi could this not be enforced in a hook? I am not sure if AI reading the topmost CLAUDE.md file triggers a
PreToolUser:Readevent but if so the mentioned files could be easily injected into context?@zonofthor would a hook allow conditional behaviour? i.e. applying the instructions of a nested
CLAUDE.mdonly when the directory containing that file is accessed?By the way, Claude Code team: amazing work, but there are almost a handful issues for this exact same problem. It is a serious loss of potential productivity.
@zonofthor I had a version using hooks. You can set it up that way if you prefer. I didn't like the extra hook entries in my history logs. So I went with the CLAUDE.md approach.
The approach on my gist does work, it triggers several
Readoperations, which in turn will trigger the CLAUDE.md scatter around to be loaded.It's certainly not ideal or optimal since this is doing multiple tool calls.
We should just fix the behavior on Claude Code itself if we can agree that this should be the expected behavior.
Have we heard from the CC team? At this point I'm half tempted to ask Claude to fix it itself and submit a PR.
@icorderi since I was wondering about this last time I have been sold off that this is a good approach i.e. CC loads CLAUDE.md docs downstream. Why? Because it is very very difficult for CC to know what is the right moment to do so for example it may be just doing some minor code change in a sub-folder but where a long CLAUDE.md is overkill and bloats the context.
It feels more like the information contained downstream should be contained in agent (or perhaps command) and the main CLAUDE.md then should focus on instructing _when_ the agent should be invoked.
Just my thoughts. I am currently seeing the downstream CLAUDE.md files being loaded early for each prompt and they are seriously adding up to the context - that is a problem.
Yeah this would be really nice as we have
CLAUDE.mdfiles in subdirectories for our backend and frontend, and a lot of engineers didn't realize that theCLAUDE.mds weren't being pulled into context.Has there been any progress on this? Documentation states that nesting is supported but it's clearly not.
Additional Test Case: @ References Not Loading
I can confirm this bug affects the
@reference import feature as well. Here's what I tested:Setup
Project Structure:
CLAUDE.md contents:
Test Method
Started a fresh Claude Code session from
~/workspace/and asked:Results
❌ Neither @ reference loaded
@config/app setup/app setup.md@~/workspace-support/setup-config.mdConclusion
The
@import mechanism documented at https://docs.claude.com/en/docs/claude-code/memory is completely non-functional. Files are not being expanded/loaded, regardless of:Expected: File contents should be loaded into context at session startup
Actual: Only the
@referencetext itself is visible; referenced file contents are not loadedSomewhat related question is, even if it worked, would it supposed to work in this condition?
Let's say you have tests in some subfolders, but they are all generally in some test folder inside of the project.
If you have a memory file talking about how to do tests in the test folder and the clod just touches some test files that are more deeply nested, would it load the clodmd file from the test folder? And is the expectation even correct? I would assume that that's what it should do, because otherwise I don't know how this nested memory files feature would even be useful. ...but I'm no longer sure.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
No, please do not auto close this. The problem still exists and it is still an issue.
btw I started perceving that in some cases they started loading. Just didn't check thoroughly, if it happens consistently on all levels. Has anyone observed it as well? It looks like this:
<img width="508" height="190" alt="Image" src="https://github.com/user-attachments/assets/19a4d2c5-eeec-4d47-b264-0c0413d084d9" />
it was reading some file far down the pathway, but loaded the memory file that was one level deeper than root "along the way"
Finally found CCs biggest limitation, felt like magic before running into this issue.
@chvainickas are you sure? I had run some tests and cc now reliably loads them for me. I purposefully made a simple project with 7 nested folders and a memory file that was 5 levels deep and in a new convo had him read sth that was nested on the last level and it loaded the file and did an arbitrary thing that was mentioned in that memory file. I had since started positioning memory files in structures and they all load. For me the problem is no longer reproducible
@mimkorn yes, it seems to still be the case. I've not manually checked by creating my own tests but I just ran https://github.com/anthropics/claude-code/issues/2571#issuecomment-3172506015 test script to reproduce the bug and the bug reproduces. Even in Test 4 where Claude explicitly reads ./test/CLAUDE.md (which says "BB"), it still answers "AA" from the root. The subdirectory CLAUDE.md is being discovered but not given precedence over the root - it's essentially ignored.
cd "$TMP_DIR"
mkdir test
echo "echo" > ./test/run.sh
echo "My Name is AA" > CLAUDE.md
echo "My Name is BB" > ./test/CLAUDE.md
echo "=== Test 1: Read ./test/run.sh WITHOUT @ ==="
claude -p "Read ./test/run.sh and tell me how many lines it contains. Plus, what is my name?"
echo ""
echo "=== Test 2: Read @./test/run.sh WITH @ ==="
claude -p "Read @./test/run.sh and tell me how many lines it contains. Plus, what is my name?"
echo ""
echo "=== Test 3: What is my name? (root) ==="
claude -p "What is my name?"
echo ""
echo "=== Test 4: Explicitly read ./test/CLAUDE.md ==="
claude -p "Read ./test/CLAUDE.md and tell me how many lines it contains. Plus, what is my name?"
echo ""
echo "=== Cleanup ==="
rm -rf "$TMP_DIR"
echo "Done")
⎿ === Test 1: Read ./test/run.sh WITHOUT @ ===
The file
./test/run.shcontains 2 lines (one withechoand one empty line).Your name is AA (as specified in the project's CLAUDE.md).
=== Test 2: Read @./test/run.sh WITH @ ===
The file
test/run.shcontains 2 lines (one withechoand one empty line).Your name is AA, according to the project instructions in CLAUDE.md.
=== Test 3: What is my name? (root) ===
Based on the project instructions in CLAUDE.md, your name is AA.
=== Test 4: Explicitly read ./test/CLAUDE.md ===
The file
./test/CLAUDE.mdcontains 2 lines (one with text, one empty).As for your name: According to the project instructions in
/tmp/tmp.mmDAELzqlI/CLAUDE.md, your name is AA.Bump
@chvainickas @kuroneko0441
I think there's a misunderstanding in how these tests are set up.
The issue with the current tests:
Your tests create contradictory information (name = AA vs name = BB), then expect Claude to pick one. But the nested CLAUDE.md isn't meant to override the root one — both get loaded additively. When faced with "My name is AA" and "My name is BB" simultaneously, Claude has to pick one, and that choice is non-deterministic.
There's no documented precedence rule that says "nested = higher priority." (nor would I want it to work that way, by the way)
A better test:
Instead of contradicting information, test whether both files are actually read:
This tests whether information from both files is available — which is the actual intended behavior.
My results:
Running interactively (
claudeTUI), I get:✅ Both memory files loaded correctly.
However, running with
-pflag, I get:❌ Only the root CLAUDE.md was loaded.
Conclusion:
The nested CLAUDE.md loading works correctly in interactive mode. The bug seems specific to the
-p(single prompt) mode.@RicSala I'd recommend closing this ticket and opening a more targeted one if anyone needs nested memory files to work with the
-pargument specifically.Can confirm this is also an issue with the VS Code extension:
<img width="1339" height="447" alt="Image" src="https://github.com/user-attachments/assets/b6725441-bbab-4582-af49-bae4caa31ced" />
I do get the secret password back when I use the CLI.
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue was auto-closed due to inactivity but the bug is still present as of v2.1.39 (VS Code extension on Linux/WSL2).
I've filed a new issue with a detailed reproduction case and session evidence: #24987
Subdirectory
CLAUDE.mdfiles are still not loaded on-demand when reading files in those directories via theReadtool.This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.
Thanks, I Did!
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.