opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: Auto-inject subdirectory CLAUDE.md files on read operations

Open allisoneer opened this issue 1 week ago • 1 comments

Feature hasn't been suggested before.

  • [x] I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

In Claude Code, CLAUDE.md files located in subdirectories are auto-injected into context when a read tool is called anywhere along that path. Specifically, additional read tool calls are injected for each CLAUDE.md found in the path hierarchy.

Example Directory Structure

CLAUDE.md
dir_1/
├── CLAUDE.md
├── src/
│   ├── CLAUDE.md
│   └── project2/
│       └── other_file.txt
└── other_dir/
    └── example_file.txt
dir_2/
├── CLAUDE.md
└── path/
    └── to/
        └── deeply/
            ├── CLAUDE.md
            └── nested/
                └── dir/

Current Behavior (Claude Code)

By default, the root CLAUDE.md is injected into the system prompt.

When a read tool call is made, Claude Code walks up from that file's directory and injects additional read tool calls for any CLAUDE.md files found along the path.


Example 1: Reading a file in dir_1/other_dir/

read(dir_1/other_dir/example_file.txt)  # original call
read(dir_1/CLAUDE.md)                   # injected

Example 2: Subsequently reading a file in dir_1/src/project2/

read(dir_1/src/project2/other_file.txt)  # original call
read(dir_1/src/CLAUDE.md)                # injected
# dir_1/CLAUDE.md is NOT injected (already read this session)

Example 3: Reading a deeply nested file in dir_2/

read(dir_2/path/to/deeply/nested/dir/somefile.txt)  # original call
read(dir_2/path/to/deeply/CLAUDE.md)                # injected
read(dir_2/CLAUDE.md)                               # injected

Additional Note

I believe you also traverse backwards up the filesystem outside the working directory. Claude Code does not do this.

For example, if the above structure lived at /home/allison/git/repo_1/example/, and repo_1/ (the git root) contained a CLAUDE.md, Claude Code would not inject a read for /home/allison/git/repo_1/CLAUDE.md—but I think your implementation would.

I don't personally need that behavior, but I'd really like subdirectory CLAUDE.md injection support.

Reference Implementation

I emulated the full complexity of this CLAUDE.md injection behavior here, which you can optionally use as a reference:

https://github.com/allisoneer/agentic_auxilary/blob/e8a053d09fca0f0d8e1106baf734c73d3771e003/gpt5_reasoner/src/engine/memory.rs#L27-L154


Does that make the tool-call injection clearer? I can also add explicit comments like # injected tool call if you want to hammer it home even more.

allisoneer avatar Jan 08 '26 18:01 allisoneer