[FEATURE]: Auto-selection of nested AGENTS.md based on file/directory context #4584

Closed
opened 2026-02-16 17:44:41 -05:00 by yindo · 3 comments
Owner

Originally created by @YourTechBud on GitHub (Jan 10, 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

I’ve been working in a monorepo and noticed that the agent often misses the specific instructions we have in subdirectories because it mostly sticks to the root AGENTS.md file.

I’d love it if the agent could just "auto-pick" the nearest AGENTS.md file whenever it starts working in a specific part of the tree.

Specifically:

  • If the agent is reading or writing a file inside a subdirectory, the agent should automatically check for a local AGENTS.md in that folder (or the closest parent) and pull that context in.
  • If I mention a specific folder or path in my prompt, it should be smart enough to go grab the instructions for that area before it starts.

Right now, it’s a bit of a manual process to make sure the agent is following the right local rules for different parts of the repo. It would be much smoother if this happened automatically based on whatever files or folders I'm actually touching.

Originally created by @YourTechBud on GitHub (Jan 10, 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 I’ve been working in a monorepo and noticed that the agent often misses the specific instructions we have in subdirectories because it mostly sticks to the root AGENTS.md file. I’d love it if the agent could just "auto-pick" the nearest AGENTS.md file whenever it starts working in a specific part of the tree. Specifically: - If the agent is reading or writing a file inside a subdirectory, the agent should automatically check for a local AGENTS.md in that folder (or the closest parent) and pull that context in. - If I mention a specific folder or path in my prompt, it should be smart enough to go grab the instructions for that area before it starts. Right now, it’s a bit of a manual process to make sure the agent is following the right local rules for different parts of the repo. It would be much smoother if this happened automatically based on whatever files or folders I'm actually touching.
yindo added the discussion label 2026-02-16 17:44:41 -05:00
yindo closed this issue 2026-02-16 17:44:41 -05:00
Author
Owner

@YourTechBud commented on GitHub (Jan 10, 2026):

Just checked. This is supposed to be a part of the Agents.md spec as well.

4. Large monorepo? Use nested AGENTS.md files for subprojects

Place another AGENTS.md inside each package. Agents automatically read the nearest file in the directory tree, so the closest one takes precedence and every subproject can ship tailored instructions. For example, at time of writing the main OpenAI repo has 88 AGENTS.md files.

@YourTechBud commented on GitHub (Jan 10, 2026): Just checked. This is supposed to be a part of the [Agents.md](https://agents.md/) spec as well. > #### 4. Large monorepo? Use nested AGENTS.md files for subprojects > Place another AGENTS.md inside each package. Agents automatically read the nearest file in the directory tree, so the closest one takes precedence and every subproject can ship tailored instructions. For example, at time of writing the main OpenAI repo has 88 AGENTS.md files.
Author
Owner

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

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

  • #6316: [FEATURE]: Context Auto-Discovery: Load AGENTS.md from Directories When Accessing Files - Very similar feature request with detailed implementation proposal for auto-discovery of nested AGENTS.md
  • #7361: [FEATURE]: Auto-inject subdirectory CLAUDE.md files on read operations - Proposes injecting nested instruction files on read operations, similar use case
  • #4479: [FEATURE]: Configurable instruction file search boundary and file types - Requests configurability of instruction file search behavior for monorepos

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 10, 2026): This issue might be a duplicate of existing issues. Please check: - #6316: [FEATURE]: Context Auto-Discovery: Load AGENTS.md from Directories When Accessing Files - Very similar feature request with detailed implementation proposal for auto-discovery of nested AGENTS.md - #7361: [FEATURE]: Auto-inject subdirectory CLAUDE.md files on read operations - Proposes injecting nested instruction files on read operations, similar use case - #4479: [FEATURE]: Configurable instruction file search boundary and file types - Requests configurability of instruction file search behavior for monorepos Feel free to ignore if none of these address your specific case.
Author
Owner

@YourTechBud commented on GitHub (Jan 10, 2026):

Seems like #6316 already exists for this

@YourTechBud commented on GitHub (Jan 10, 2026): Seems like #6316 already exists for this
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4584