# Agents.md isolated within a subdirectory is applied to root?

**URL:** <https://forum.cursor.com/t/agents-md-isolated-within-a-subdirectory-is-applied-to-root/160773>\
**Category:** Help\
**Tags:** large-codebases, context, rules\
**Created:** [May 15, 2026, 4:55pm UTC](https://forum.cursor.com/t/agents-md-isolated-within-a-subdirectory-is-applied-to-root/160773 "2026-05-15T16:55:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Satoshi](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/satoshi/32/108510_2.png) [@Satoshi](https://forum.cursor.com/u/Satoshi)\
**Post date:** [May 15, 2026, 4:55pm UTC](https://forum.cursor.com/t/agents-md-isolated-within-a-subdirectory-is-applied-to-root/160773/1 "2026-05-15T16:55:56Z")

</div>

Hi, how can I solve this:

I have a large repo opened as a single workspace in Cursor. Some subprojects have their own AGENTS.md (e.g. subproject\_A/blabla/AGENTS.md) with instructions that only make sense for that subtree.

What I want: Those instructions should apply when I’m working on files under that subproject, and not affect conversations or edits that are only about other parts of the repo.

What I’m unsure about: How does Cursor decide which AGENTS.md files are included in Agent context—is it strictly based on the files I’m editing / have in context, or can nested AGENTS.md files still influence unrelated work elsewhere in the same workspace? Is there a supported way to restrict agent instructions only to a subdirectory (e.g. only root AGENTS.md, or an explicit setting)? I know with rules I can add it in the .md file but I guess the same does not apply for AGENTS.md?

What I’ve considered: Using .cursor/rules with globs instead of AGENTS.md, or opening subfolders as separate workspaces. I’d like to know the intended behavior for nested AGENTS.md and any recommended pattern for monorepos.

---

<div class="post-metadata">

**Author:** ![deanrie](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/deanrie/32/1263_2.png) [@deanrie](https://forum.cursor.com/u/deanrie)\
**Post date:** [May 17, 2026, 5:31pm UTC](https://forum.cursor.com/t/agents-md-isolated-within-a-subdirectory-is-applied-to-root/160773/6 "2026-05-17T17:31:16Z")

</div>

Hey, short answer: nested `AGENTS.md` files are designed to automatically scope to the folder they live in. A file at `subproject_A/blabla/AGENTS.md` is treated like a rule that always applies with an implicit glob pattern `subproject_A/blabla/**`, so it only gets added to the agent context when the agent works with files inside that subtree, including files it reads or edits during the chat. It should not affect chats that only touch other parts of the repo.

The exception is the root `AGENTS.md`. It applies to the whole workspace, so it is best to keep it to repo wide guidance.

A few useful notes:

- Unlike `.cursor/rules/*.mdc`, `AGENTS.md` does not support frontmatter or globs. Scope is determined only by where the file sits in the tree. There is no setting to load only the root `AGENTS.md`.
- For monorepos with subproject specific instructions, your current setup with a nested `AGENTS.md` per subproject is the intended and recommended pattern.
- If you need more explicit control like descriptions, custom globs, or conditional behavior, use `.cursor/rules/*.mdc` with an explicit `globs:`.
- Opening a subfolder as its own workspace gives the strongest isolation if the subprojects are truly independent.

Are you seeing a real leak where instructions from a nested `AGENTS.md` show up in chats that do not touch that subtree? If yes, it is worth investigating. Share your Cursor version and a minimal repro and I will take a look. There is also a known issue in the opposite direction where nested files do not load when they should, so it is important to confirm which way your issue shows up.

Docs link: [Rules | Cursor Docs](https://cursor.com/docs/rules)

---

<div class="post-metadata">

**Author:** ![Satoshi](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/satoshi/32/108510_2.png) [@Satoshi](https://forum.cursor.com/u/Satoshi)\
**Post date:** [May 21, 2026, 4:19pm UTC](https://forum.cursor.com/t/agents-md-isolated-within-a-subdirectory-is-applied-to-root/160773/7 "2026-05-21T16:19:51Z")

</div>

Thanks! It seems like the issue was that the user asked the LLM to specifically search for coding guidlines in the repo and review changes accordingly. So, then it found agents.md in the subdirectory and applied it.

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/system/32/127254_2.png) [@system](https://forum.cursor.com/u/system)\
**Post date:** [May 23, 2026, 4:20pm UTC](https://forum.cursor.com/t/agents-md-isolated-within-a-subdirectory-is-applied-to-root/160773/9 "2026-05-23T16:20:23Z")

</div>

Closed on May 23, 2026, 4:20pm UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
