agentic repository readiness
rule
- repository root and every package:
AGENTS.md+CLAUDE.md. AGENTS.mdowns the instructions;CLAUDE.mdonly points to the siblingAGENTS.md, never duplicates it.- an instruction file owns only its directory tree:
- root file: repository-wide rules + table of contents.
- package file: that package's purpose, boundaries, commands, local conventions.
- nested file: only rules narrower than its parent can own.
- root contract is a router, not a knowledge base: durable law links to its standards corpus, repeatable mechanics link to their procedure, package commands stay with the package. when a correction grows into several conditions, examples, or commands, move it to that owner and keep only the trigger and link.
read first, then code
- mindset: read first, then code. before changing a scoped file, an agent reads the nearest
AGENTS.md, the target file heading, the owning specification, and the directly related code — then states the intended boundary and verifies the changed behavior. - this prevents treating a directory listing, prompt fragment, or single call site as the whole system.
- consequences of skipping the contract read:
- edits without knowing ownership or invariants — read-only caches, generated artifacts, coordination boundaries get modified.
- concurrent agents make conflicting assumptions about the same subsystem.
- features built from one file's local logic violate stability guarantees or ownership boundaries.
- completion claimed while unrelated work breaks elsewhere.
- with concurrent agents, the contract is the only shared authority preventing silent conflicts; without it, every agent rediscovers the same constraints from scattered comments and never establishes common ground.
why
- an agent that edits without a scoped contract learns the system from a directory listing and one call site, then makes ownership and invariant decisions on that partial map: editing generated artifacts, crossing boundaries that need coordination, claiming completion over broken neighbors.
- a small read-first
AGENTS.mdper scope makes the shared authority explicit before the first edit. - invariant protected: scope, ownership, and verification boundary are stated before code changes.
AGENTS.md # repository contract and table of contentsCLAUDE.md # read AGENTS.md firstapps/frontend/AGENTS.md # frontend-only contractCLAUDE.md # read AGENTS.md firstpackages/base/AGENTS.md # base-package-only contractCLAUDE.md # read AGENTS.md first
- root table of contents links to each package instruction file, the specification index, domain glossary, architecture decisions, commands, and deployment owner. a navigation map, not a second copy of package rules.
- temporary probes, downloaded inputs, generated intermediates, logs, caches, one-off scripts stay outside the repository unless an approved product artifact. the machine-level contract names the exact temporary root; project instructions do not invent another scratch location.
minimum contents
| file | must say |
|---|---|
root AGENTS.md | project purpose, source-of-truth order, scope map, read-first sequence, shared commands, verification boundary, links to owning standards/procedures/package contracts. |
package AGENTS.md | package purpose, owned folders and generated boundaries, local dependencies, commands, local verification, links back to the root contract. |
CLAUDE.md | read and follow the sibling AGENTS.md; no duplicate rules. |
- use exact paths and commands.
- remove stale instructions in the same forward-only change that replaces them.
- a generic policy an agent cannot turn into the next correct action is not a useful instruction.
CLAUDE.md template
read and follow the sibling `AGENTS.md` before inspecting or editing thisscope. it is the complete instruction contract for this directory tree.
- one
AGENTS.mdreference in plain text. it is a repository entry file in Markdown, not a corpus document — it does not link into the published collection.
good and bad
bad
AGENTS.md (bloated):
# Monorepo... 200 lines covering everything ...Frontend section:- Color tokens: primary=#2563eb, secondary=#6366f1- tailwind config in apps/frontend/tailwind.config.ts- Next.js version must match apps/frontend/package.json- dev server: pnpm --filter frontend dev- build output: apps/frontend/.nextDatabase section:- migrations in apps/backend/drizzle/migrations- run: drizzle-kit generate then wrangler d1 migrations apply- schema tables: users, orders, payments- Drizzle ORM, D1 database, TypeORM for legacyDeployment section:- frontend: vercel deploy from main- backend: wrangler publish from apps/backend- database: migrate production with [command]- ...
- a frontend agent must read database and deployment sections it does not own; seeing
apps/backend/drizzle/migrations, it cannot tell whether a backend script runs them or a separate command is required. - a migration-bug agent reads "drizzle-kit generate then wrangler d1" in the root, then the backend package's actual process — two instructions now own conflicting authority.
- a third agent adds a tool and updates the root without checking the backend package's dependency on it — hidden incompatibility.
good
AGENTS.md (root contract, ~80 lines):
# MonorepoRepository purpose, source-of-truth order, links to standards and procedures.Workspace Map:| Package | Role | Contract || ------------- | -------------------------- | -------------------------------------------------- || apps/frontend | SSR Next.js web app | [apps/frontend/AGENTS.md](apps/frontend/AGENTS.md) || apps/backend | Cloudflare Worker API | [apps/backend/AGENTS.md](apps/backend/AGENTS.md) || packages/base | Shared types and contracts | [packages/base/AGENTS.md](packages/base/AGENTS.md) |Commands:root coordinates the task graph:pnpm install && turbo run generate format build lint typecheckeach package runs its own lifecycle scripts; see the package contract.Standards:project standards at /workspace/project; this project applies guru standards per [AGENTS.md](CLAUDE.md).
apps/frontend/AGENTS.md (self-contained):
# Frontend (Next.js App)Purpose: SSR public web experience on localhost:20000, deployed via OpenNext.Local Commands:- pnpm --filter @scope/frontend dev- pnpm --filter @scope/frontend build- pnpm --filter @scope/frontend lintTailwind and Design Tokens:semantic-token system at src/tokens; see [design.mdx](../../docs/content/domains/design.mdx).Dependencies:see apps/frontend/package.json; root manages only turbo and the workspace.
apps/backend/AGENTS.md (self-contained):
# Backend (Cloudflare Worker + D1)Purpose: Hono API worker, deployed to worker.example.comMigrations:migrations live in src/infra/drizzle-orm/migrations.pnpm --filter @scope/backend generate # outputs openapi.jsonwrangler d1 migrations apply --localsee [backend.mdx](../../docs/content/domains/backend.mdx#database-migrations) for schema authority.
- a frontend-bug agent reads only
apps/frontend/AGENTS.mdand knows its scope; backend dependencies name their owner. - a backend agent sees the exact invocation, not a generic summary.
- the root file is a map, not a second copy of package knowledge.
verification
- every repository root and package has both files.
- each
CLAUDE.mdpoints only to its siblingAGENTS.md. - a package contract read without the root explains that package only.
- every root-table-of-contents link resolves to its owner.
- before editing, the read-first sequence is possible from the scoped instructions alone.