c/agents › command
0votes

AGENTS.md for a monorepo

TemplateLow risk Tested
submitted by CommandVault editors to c/agents · 2 uses

One root AGENTS.md plus per-package overrides so Codex, Cursor, Jules and other agents work the same way everywhere.

Template · 8 variables
# AGENTS.md (root)

This repo is a monorepo managed with {{monorepo_tool}}.

## Packages
| Path | What | Owner |
|---|---|---|
| `apps/{{web_app}}` | Customer-facing web app | {{web_owner}} |
| `apps/{{api_app}}` | Public API | {{api_owner}} |
| `packages/ui` | Shared components | {{ui_owner}} |
| `packages/config` | Lint/TS/test config | platform |

## Working rules for agents
1. Run commands from the package you're changing: `{{test_one_package}}`.
2. Never change `packages/config` without saying so explicitly in your summary.
3. Shared code goes in `packages/*`; never import one app from another.
4. Keep PRs to one package unless the task says otherwise.

## Package-specific rules
Each package may have its own `AGENTS.md`. When it exists, it wins over this file for files inside that package.

## Before you finish
- `{{check_changed}}` passes.
- Summarize: what changed, how you verified it, open questions.
e.g. pnpm workspaces + Turborepo, Nx, or npm workspaces
Folder name under apps/, e.g. web
Team or person, e.g. @frontend
Folder name under apps/, e.g. api
Team or person, e.g. @platform
Team or person, e.g. @design-systems
Exact command, e.g. pnpm --filter <package> test, npx nx test <package>, or turbo run test --filter=<package>
Exact command that lints, tests and type-checks what changed, e.g. turbo run lint test typecheck --filter=...[origin/main] or npx nx affected -t lint test typecheck
0 commentsreport

Guide

What you get: A root AGENTS.md that tells coding agents how your monorepo is laid out and how to run commands per package, with room for each package's own AGENTS.md to add or override rules. In our test both Codex and Claude Code picked up the root file and the package file together when started inside the package. Best for Teams with a monorepo who use Codex, Claude Code or other agents that read AGENTS.md..

Before you start

  • A monorepo in a git repository
  • A task runner with a --filter style option (the commands as written match Turborepo)
  • Codex or another AGENTS.md-aware agent

Worked example (Oct 17, 2026, Claude Code 2.1.296; Codex 0.151.0 (gpt-5.6-sol))

Input

Root AGENTS.md filled with: monorepo_tool=turbo, web_app=saltmarsh-web, web_owner=team-storefront, api_app=saltmarsh-api, api_owner=team-gateway. Added apps/saltmarsh-web/AGENTS.md with its own test command (`turbo run test --filter saltmarsh-web -- --project=chromium-smoke`) and two package-only rules. Both tools were started inside apps/saltmarsh-web. Question: Without reading any files, answer from the project instructions you were given at startup: (1) What monorepo tool does this repo use, and which team owns apps/saltmarsh-web? (2) What exact command runs this package's tests? (3) Name one rule that applies only to this package. (4) Which instruction files were you given: the repo-root AGENTS.md, this package's AGENTS.md, both, or neither? If you have no such instructions, say so.

Result

Codex: "Monorepo tool: Turbo. Owner of apps/saltmarsh-web: team-storefront. Exact test command: `turbo run test --filter saltmarsh-web -- --project=chromium-smoke` ... Instruction files given: both the repo-root AGENTS.md and this package's AGENTS.md." Claude Code: "The repo uses turbo (Turborepo). apps/saltmarsh-web is owned by team-storefront... I was given both: the repo-root AGENTS.md and apps/saltmarsh-web/AGENTS.md. Inside this package, the package file wins where the two conflict."

Fresh copy of a Next.js 16 starter git repo with the root AGENTS.md replaced and empty apps/ and packages/ folders created; turbo itself was not installed, so the commands were not run. Codex: read-only sandbox, `codex exec` run with cwd apps/saltmarsh-web; no commands in its log. Claude Code 2.1.296: plan mode, cwd apps/saltmarsh-web, JSON output showed 1 turn (no file reads); with no CLAUDE.md present it still loaded both AGENTS.md files. Both answered with the root owner (root file) and the package test command and rule (nested file). After this test the Turborepo-only commands became fill-in fields that work with pnpm, Nx or Turborepo, and the UI owner became a field.

How to check it worked

  • Start the agent inside a package folder and ask, without reading files, for the package's test command and the team that owns it. The owner comes from the root file and the command from the package file, so a correct answer shows both loaded.
  • In Codex, run from the package folder; it collects AGENTS.md files from the git root down to the current folder.
  • In Claude Code, run /memory to see which instruction files are loaded.

Common problems

  • The agent only knows the package rules, not the root ones: Codex walks up to the git root, so if the folder isn't a git repo (or you started outside it) only the nearest file may load. Run from inside the repo.
  • The agent ignores package rules: you started it at the repo root. Nested AGENTS.md files apply when you work in or launch from that package; start the session in the package folder or tell the agent which package you're in.
  • Commands fail with your tool: `<tool> run test --filter <package>` is Turborepo syntax. pnpm wants `pnpm --filter <package> test`, Nx uses `nx run <project>:test`. Rewrite rule 1 and 'Before you finish' for your tool.
  • Agents that don't read AGENTS.md (or older versions) ignore it. Point their own config file at it, for example a CLAUDE.md containing `@AGENTS.md`.

Use this file with your AI tool

Each tool reads project instructions from a different file name. Fill in the blanks above, then save it where your tool looks.

One command
npx commandvault add agents-md-for-a-monorepo-e4aa4b99 --tool claude
Save as CLAUDE.md
# CLAUDE.md (root)

This repo is a monorepo managed with {{monorepo_tool}}.

## Packages
| Path | What | Owner |
|---|---|---|
| `apps/{{web_app}}` | Customer-facing web app | {{web_owner}} |
| `apps/{{api_app}}` | Public API | {{api_owner}} |
| `packages/ui` | Shared components | {{ui_owner}} |
| `packages/config` | Lint/TS/test config | platform |

## Working rules for agents
1. Run commands from the package you're changing: `{{test_one_package}}`.
2. Never change `packages/config` without saying so explicitly in your summary.
3. Shared code goes in `packages/*`; never import one app from another.
4. Keep PRs to one package unless the task says otherwise.

## Package-specific rules
Each package may have its own `AGENTS.md`. When it exists, it wins over this file for files inside that package.

## Before you finish
- `{{check_changed}}` passes.
- Summarize: what changed, how you verified it, open questions.

Use it: Claude Code loads it at the start of every session. Check with /context (Memory files).

Claude Code can also read an existing AGENTS.md; see its memory docs.

From Claude Code's docs , checked Oct 17, 2026.

More from c/agents

See all of c/agents →
0 comments

Log in to join the discussion.