[FEATURE REQUEST] Nested CLAUDE.md context

Status Fixed / completed
Maintainer reply ✓ Yes — wolffiex
Activity 5 comments · opened Apr 4, 2025 · closed Apr 15, 2025
💡 Likely answer: A maintainer (wolffiex, collaborator) responded on this thread — see the highlighted reply below.

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.

View original on GitHub ↗

5 Comments

hesreallyhim · 1 year ago

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.md files in sub-directories). The disanalogy I see with .gitignore is that it is scoped to a given repository. AFAIK, you're not supposed to have nested .git repos, and adding a .gitignore in a parent directory outside the repo root does not affect the repo (just tested that). gitignore_global is 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 global CLAUDE.md basically.

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.md anywhere in the system, but this seems a little risky.

hesreallyhim · 1 year ago

or maybe add a config analogous to "dontCrawlDirectory" like "dontCrawlUpwardDirectories"(?)

hesreallyhim · 1 year ago

@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:

Claude Code reads memories recursively: starting in the cwd, Claude Code recurses up to / and reads any CLAUDE.md or CLAUDE.local.md files it finds. This is especially convenient when working in large repositories where you run Claude Code in foo/bar/, and have memories in both foo/CLAUDE.md and foo/bar/CLAUDE.md.

​link

wolffiex collaborator · 1 year ago

This is implemented. It may not always work correctly due to instruction following issues, but that is a separate issue.

github-actions[bot] · 1 year ago

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.