Course contents
AI coding rules in monorepos: per-package AGENTS.md, rules and skills
On this page
The idea: root for shared facts, packages for specifics
repo/
├── AGENTS.md # workspace commands, layout, boundaries
├── CLAUDE.md # @AGENTS.md
├── apps/
│ └── web/
│ ├── AGENTS.md # Next.js specifics for this app
│ └── .agents/skills/
│ └── nextjs-code-review/SKILL.md
└── packages/
└── db/
├── AGENTS.md # Prisma specifics
└── .claude/rules/
└── prisma.md
The root file covers how to work in the whole repo: the package manager, how to run one package's tests, what not to touch. Each package file covers its own stack.
How each tool handles nesting
This is where monorepos get tricky. The tools behave differently:
| Tool | Nested AGENTS.md | Nested skills |
|---|---|---|
| Codex | Reads every file from the repo root down to the folder you started in | Scans .agents/skills/ from the start folder up to the root |
| Cursor | Applies a folder's file when working on files there | .cursor/skills/ or .agents/skills/ in a subfolder are auto-scoped to that folder |
| Claude Code | Loads a subfolder's CLAUDE.md (or AGENTS.md) when it reads a file there | Loads a subfolder's .claude/skills/ the first time it works on a file there |
| Copilot | Uses the nearest AGENTS.md | .github/skills/, .claude/skills/, .agents/skills/ at the root; subfolder skills aren't documented |
| Devin | Reads from the workspace root down to the folder it's working in | Not documented; keep skills at the root |
| Antigravity CLI | Reads from the start folder up to the root; never loads subfolders | Same: start folder up to the root |
What that means in practice
- Codex and Antigravity depend on where you start. Start them in
apps/web/to get the app's file and skills. Started at the root, Codex won't readapps/web/AGENTS.md, and Antigravity won't either. - Cursor and Claude Code follow the files. Start at the root and they pick up package guidance as they touch package files.
Install presets per package
Use --cwd to install into a package folder:
npx presets-dev add nextjs --tool codex --cwd apps/webnpx presets-dev add prisma --tool claude --cwd packages/dbThe first appends a Next.js section to apps/web/AGENTS.md and writes apps/web/.agents/skills/nextjs-code-review/SKILL.md. The second writes Claude Code's rule and skill under packages/db/.claude/.
Package-level AGENTS.md files also help with Codex's 32 KiB limit: each run only concatenates the files on its path.
Watch the globs
Presets' rule globs are written relative to the project root they're installed in. A Next.js rule with app/**/*.tsx installed at the repo root won't match apps/web/app/page.tsx. Install it with --cwd apps/web (for tools that read nested rule folders), or edit the globs to apps/web/app/**/*.tsx. Claude Code patterns are relative to the folder that contains .claude.
Keep other teams' rules out
In big repos you sometimes pick up guidance you don't want:
- Claude Code:
claudeMdExcludesskips specificCLAUDE.mdfiles or rule folders (memory docs). - Codex: add
AGENTS.override.mdin a folder to replace the inheritedAGENTS.mdat that level. - Cline: toggle individual rules off in the Rules panel.
Common mistakes
- One giant root file. It loads everywhere and hits Codex's limit. Push stack details into packages.
- Rules at the root with package-relative globs. They never match.
- Expecting Antigravity to load package files from the root. It only looks up from where you started.
- Same skill name in root and package folders. Claude Code disambiguates (
/apps/web:deploy), but other tools may not. Give package skills distinct names.
Recap
- Root file for workspace-wide facts; package files for stack specifics.
- Codex and Antigravity load by start folder; Cursor and Claude Code load as they touch files.
- Install presets per package with
--cwd, and check that globs match from where they're installed. - Use excludes and overrides to keep out guidance you don't want.
Next step
Maintaining presets: keep rules and skills accurate as your code changes.