How precedence works
The closest AGENTS.md to the file being edited takes effect. Explicit user chat prompts override everything.
- A file in
packages/api/src/routes/users.tswill usepackages/api/AGENTS.mdif it exists, otherwise fall back to the rootAGENTS.md. - A root AGENTS.md sets defaults for the whole repo.
- A package-level AGENTS.md overrides or extends those defaults for that package.
- User chat prompts always take the highest priority — they override any AGENTS.md instructions.
Directory tree resolution
Agents resolve instructions by walking from the edited file upward:What to put in the root AGENTS.md
The root file should cover conventions that apply across the entire repo:- How the monorepo is structured (where apps and packages live)
- Top-level install and bootstrap commands
- Shared tooling (linter, formatter, CI)
- Commit and PR conventions
- Security policies
What to put in package-level AGENTS.md files
Package files should cover what’s specific to that package — and avoid repeating what the root already says:- How to run that package’s dev server
- Package-specific test commands
- Local code style or architectural constraints
- Gotchas unique to that package
When to add a nested AGENTS.md
Add a package-level AGENTS.md when:- The package uses a different language or framework than the rest of the repo
- The test command is different from the root-level command
- There are architectural rules or gotchas specific to that package
- The package is large enough that its own context would get lost in the root file
Best practices
- Don’t repeat yourself. If a rule is in the root AGENTS.md, don’t copy it into every package file. Only override what’s different.
- Keep commands accurate. An agent that runs the wrong command wastes time. Verify commands match what’s actually in
package.json. - Update files when workflows change. If you change the test runner or rename a script, update the relevant AGENTS.md at the same time.
- Co-locate with the code. Commit AGENTS.md files alongside the code they describe. They’re part of the project, not meta-documentation.
