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

Closed
opened 2026-02-16 17:43:48 -05:00 by yindo · 2 comments
Owner

Originally created by @allisoneer on GitHub (Jan 8, 2026).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • 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.

Originally created by @allisoneer on GitHub (Jan 8, 2026). Originally assigned to: @thdxr on GitHub. ### 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.
yindo added the discussion label 2026-02-16 17:43:48 -05:00
yindo closed this issue 2026-02-16 17:43:48 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 8, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #6316: Context Auto-Discovery: Load AGENTS.md from Directories When Accessing Files - proposes auto-discovery of AGENTS.md files when reading/writing files in subdirectories
  • #4479: Configurable instruction file search boundary and file types - requests searching for instruction files in parent directories and loading multiple file types

Feel free to ignore if your specific use case isn't addressed by these issues.

@github-actions[bot] commented on GitHub (Jan 8, 2026): This issue might be a duplicate of existing issues. Please check: - #6316: Context Auto-Discovery: Load AGENTS.md from Directories When Accessing Files - proposes auto-discovery of AGENTS.md files when reading/writing files in subdirectories - #4479: Configurable instruction file search boundary and file types - requests searching for instruction files in parent directories and loading multiple file types Feel free to ignore if your specific use case isn't addressed by these issues.
Author
Owner

@allisoneer commented on GitHub (Feb 5, 2026):

You guys did this, thanks big dawgs

@allisoneer commented on GitHub (Feb 5, 2026): You guys did this, thanks big dawgs
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4449