A repository has several AGENTS.md files in different folders. Which one takes precedence?
Why B is the answer
The nearest one in the directory tree
GitHub says the nearest AGENTS.md in the directory tree takes precedence while Copilot works.
In detail
- The nearest AGENTS.md in the directory tree takes precedence.
- That lets each folder set its own rules.
- Put shared rules at the root, and specific ones nearby.
Use case
An illustrative scenario, not a real incident.
A monorepo has an AGENTS.md at the root and one in each service. In the payments folder, Copilot uses the payments file.
See it in different ways
flowchart TD
A{"What do you need?"} -->|"Rules for the whole repo"| B[".github/copilot-instructions.md"]
A -->|"Rules for some paths"| C[".github/instructions/NAME.instructions.md"]
A -->|"Rules for agents"| D["AGENTS.md"]
A -->|"A task you start yourself"| E["Prompt file"]mindmap
root((Instructions))
Repository wide
copilot-instructions.md
One path
NAME.instructions.md
Agents
Nearest AGENTS.md
Chosen by hand
Prompt filesflowchart LR S0["Root AGENTS.md"] --> S1["Service AGENTS.md"] --> S2["Copilot uses the nearest"]
Key point: The nearest AGENTS.md wins.
Why the other options are wrong
- A. The one at the root, which always overrides the others
- The root file does not always win.
- C. The oldest one, based on the date of its first commit
- Age is not the rule.
- D. The longest one, because it has the most detail in it
- Length is not the rule.

