[FEATURE REQUEST] Nested CLAUDE.md context
Nested context
Problem
Caude does not "see" the CLAUDE.md further up the file tree than the current directory. When I work with git worktrees, this means having to re-init claude in every individual worktree direcotry (i.e. it does not see project/CLAUDE.md when launching in project/branch1).
At the moment I am fixing this by cd .. before launching claude and giving instructions in the project/CLAUDE.md for it to hook into my IDE mcp, check what worktree directory I am working on, then only make changes in that directory. This is a dirty hack and it does not spark joy.
Desired solution
Claude code should scan recursively up the filetree from where it is launched, adding all encountered CLAUDE.md files to its context. This will allow for a more general "project wide" CLAUDE.md file in the root of the project, and more specific CLAUDE.md files in various other places, be that branches, monorepo apps or libs, or just features that want to provide more context. I am imagining this in a similar way to how .gitignore files work, where they are picked up recursively and only apply to the directory they exist in.
5 Comments
I like this idea, but I think it should be restricted to a given "workspace" (which isn't really a concept as far as I know except the "workspace" being the directory you open Claude in, since Claude can supposedly see nested
CLAUDE.mdfiles in sub-directories). The disanalogy I see with.gitignoreis that it is scoped to a given repository. AFAIK, you're not supposed to have nested .git repos, and adding a.gitignorein a parent directory outside the repo root does not affect the repo (just tested that).gitignore_globalis the only exception... so there would need to be some notion of a Claude workspace beyond the directory where you start the session, I think(?). (Maybe you could configure the workspace to be the git repo itself.) Another potential issue I see is to do with permissions, since you would have to give Claude permission to find and read files basically anywhere up the directory tree.I guess I don't see much of a use case for this outside of a specific monorepo, e.g., since you can use global preferences in
~/.claude. I mean, would you really need an intermediate file between $HOME and a particular repo? Like "This is the folder where I store Python projects. Always use Pydantic in the sub-directories of this folder." You can put in that in the globalCLAUDE.mdbasically.So, just to refine it a little, what do you think about allowing a git repo to be a Claude workspace? I guess alternatively, you could loosen the safeguards and allow files named
CLAUDE.mdanywhere in the system, but this seems a little risky.or maybe add a config analogous to "dontCrawlDirectory" like "dontCrawlUpwardDirectories"(?)
@fkalny-groupon hey i don't know if this is a new change, but the docs site says that Claude will recursively search up the directory tree:
link
This is implemented. It may not always work correctly due to instruction following issues, but that is a separate issue.
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.