Materials / Practices

AGENTS.md templates for seven stacks

Seven starting files of about forty lines each, one per common stack, with real commands for each tool. Copy the closest one, replace what is not yours, and run every command before you commit it.

14 min read11 Nov 2026Ilia Poliakov

How to use these templates

Each template below describes a fictional service in a common stack. The services are invented; the commands are the real ones for each tool. None of them is meant to be committed as it stands. They are a shape to fill in, and a reminder of the questions an agent needs answered. AGENTS.md: writing instructions for AI agents explains the format itself.

  1. Copy the closest templateSave it as AGENTS.md at the root of the repository.
  2. Replace the commands and run each oneUse your package.json scripts, Makefile targets or Gradle tasks. A command that does not work is worse than no command: the agent will run it, fail, and guess.
  3. Delete the rules you do not haveA rule about a queue you do not use is noise the agent still reads every session.
  4. Add rules from real mistakesAfter a week of agents working in the repository, add a line for each mistake you saw twice.
  5. Commit it and change it by pull requestFor Claude Code, add a CLAUDE.md with the line @AGENTS.md if the repository also needs Claude-only lines; see CLAUDE.md in a team repository.

Every template has the same sections: a one-line description, Commands, Structure, Rules, Tests, Boundaries and Handoff. Commands come first. The "before handoff" line must be what CI runs, or the agent will hand over work that CI rejects.

JavaScript and TypeScript

A Node.js service

A notification service: it sends email, SMS and push messages from a job queue.

# notify: email, SMS and push delivery (Node.js 22, TypeScript, PostgreSQL, BullMQ)

## Commands
- Install: `pnpm install`
- Run: `docker compose up -d postgres redis && pnpm dev`
- All tests: `pnpm test`
- One file: `pnpm vitest run src/delivery/retry.test.ts`
- One test: `pnpm vitest run -t "gives up after the fifth attempt"`
- Types: `pnpm tsc --noEmit`
- Lint and fix: `pnpm eslint . --fix`
- Before handoff (as CI): `pnpm tsc --noEmit && pnpm eslint . && pnpm test`

## Structure
- `src/http/`: routes and input validation (zod); no business logic
- `src/jobs/`: queue handlers, one file per job type
- `src/providers/`: the only code that calls email, SMS or push vendors
- `src/db/`: queries; nothing else imports the database client
- `src/config.ts`: the only place that reads `process.env`

## Rules
- Every job handler is idempotent: the job id is the message id.
- Never log a full address or phone number; use `maskRecipient()`.
- Every outbound HTTP call has a timeout.
- Throw `DeliveryError` from `src/errors.ts`, not bare `Error`.

## Tests
- A behavior change comes with a test; a bug fix starts with a failing one.
- Vendor APIs are mocked with `msw`; no test reaches the network.
- Do not delete, skip or weaken an existing test.

## Boundaries
- No migration unless the task asks for one.
- Do not edit `.env*` files or CI secrets.
- No new dependency without a reason in the pull request.
- Changing a public endpoint: stop and propose the change first.

## Handoff
- Branch `feat/<ticket>-short-name`; the pull request says what changed and how it was verified.

What to adapt:

A React frontend

A customer console: a single-page app built with Vite that talks to a REST API.

# console: customer web app (React 19, TypeScript, Vite, TanStack Query)

## Commands
- Install: `pnpm install`
- Run: `pnpm dev` (expects the API at `VITE_API_URL`)
- Unit tests: `pnpm vitest run`
- One file: `pnpm vitest run src/features/team/InviteForm.test.tsx`
- End-to-end, one spec: `pnpm exec playwright test tests/e2e/invite.spec.ts`
- Regenerate the API client: `pnpm api:generate`
- Before handoff (as CI): `pnpm tsc --noEmit && pnpm eslint . && pnpm vitest run`

## Structure
- `src/features/<feature>/`: components, hooks and tests of one feature
- `src/shared/ui/`: components used by two or more features
- `src/shared/api/`: generated from `openapi.yaml`; never edited by hand
- `tests/e2e/`: Playwright specs, one per user journey

## Rules
- Server data goes through TanStack Query; no `fetch` inside `useEffect`.
- A feature does not import from another feature; share via `src/shared/`.
- Colors and spacing come from tokens in `src/shared/ui/tokens.css`.
- All visible text goes through `t('key')`; keys live in `src/i18n/en.json`.
- Every control works with a keyboard and has an accessible name.

## Tests
- Testing Library queries by role and visible text, not by class or test id.
- A new user journey gets a Playwright spec.
- Do not update snapshots without looking at what changed.

## Boundaries
- Do not edit `src/shared/api/`; change `openapi.yaml` and regenerate.
- Do not change `vite.config.ts` or add a UI library unless the task says so.

## Handoff
- A UI change includes a screenshot or a short recording in the pull request.

What to adapt:

Python with FastAPI and uv

A demand forecasting API that serves weekly forecasts to other services.

# forecast: demand forecasts API (Python 3.12, FastAPI, SQLAlchemy 2, PostgreSQL)

## Commands
- Install: `uv sync`
- Run: `docker compose up -d db && uv run uvicorn forecast.main:app --reload`
- All tests: `uv run pytest`
- One test: `uv run pytest tests/services/test_seasonality.py::test_weekly_peak`
- By keyword: `uv run pytest -k holiday`
- Lint and format: `uv run ruff check . --fix && uv run ruff format .`
- Types: `uv run mypy src`
- Before handoff (as CI):
  `uv run ruff check . && uv run ruff format --check . && uv run mypy src && uv run pytest`

## Structure
- `src/forecast/api/`: routes; validate input, call a service, return
- `src/forecast/services/`: business logic
- `src/forecast/models/`: forecasting code; the only place that imports pandas
- `src/forecast/db/`: SQLAlchemy models and repositories
- `migrations/`: Alembic; `tests/` mirrors `src/forecast/`

## Rules
- Datetimes are timezone-aware UTC; weeks are ISO weeks starting Monday.
- Routes never touch the database; they call services.
- Everything is type-annotated; `Any` only with a comment saying why.
- Settings come from `forecast/config.py` (pydantic-settings).
- New dependency: `uv add <package>`, and say why in the pull request.

## Tests
- A change comes with a test; shared fixtures live in `tests/conftest.py`.
- No `pytest.mark.skip` to get a change through.

## Boundaries
- Create a migration only when the task asks:
  `uv run alembic revision --autogenerate -m "..."`, then read what it generated.
- Do not change the ruff or mypy settings in `pyproject.toml`.
- Never run migrations against a shared database.

## Handoff
- Branch `feat/<ticket>-short-name`; the pull request names the spec and the tests added.

What to adapt:

Go

A telemetry service: devices stream readings over gRPC, and an HTTP API serves them.

# telemetry: device readings ingest (Go, gRPC and HTTP, PostgreSQL)

## Commands
- Build: `go build ./...`
- All tests: `go test ./...`
- One test, no cache: `go test ./internal/ingest -run TestDecodeFrame -count=1`
- Race detector: `go test -race ./...`
- Integration tests: `docker compose up -d && go test -tags=integration ./...`
- Lint: `golangci-lint run`
- Format check: `gofmt -l .` (must print nothing)
- Generate code from `api/proto/`: `make generate`
- Before handoff (as CI): `go vet ./... && golangci-lint run && go test -race ./...`

## Structure
- `cmd/telemetry/`: entry point; wiring only, no logic
- `internal/ingest/`, `internal/query/`: domain packages
- `internal/platform/`: database, logging, config
- `api/gen/`: generated; never edited by hand
- `migrations/`: SQL migrations

## Rules
- Wrap errors with context: `fmt.Errorf("decode frame: %w", err)`.
- Never discard an error; handle it or return it.
- `context.Context` is the first parameter of anything that does I/O.
- No package-level mutable state; no `init()` with side effects.
- Declare interfaces where they are used, not where they are implemented.
- Device clocks are not trusted: order by `received_at`; keep `device_time` as data.

## Tests
- Table-driven tests for anything with more than two cases.
- Integration tests carry `//go:build integration` and need docker compose.

## Boundaries
- Do not edit `api/gen/`; change the proto and run `make generate`.
- No migration unless the task asks for one.
- Changing a public gRPC message or service: stop and propose it first.

## Handoff
- Branch `feat/<ticket>-short-name`; the pull request lists the tests run.

What to adapt:

Java and Kotlin with Spring Boot

An inventory service: stock levels and reservations for a set of warehouses.

# inventory: stock and reservations (Java 21, Spring Boot 3, PostgreSQL, Gradle)

## Commands
- Build with tests: `./gradlew build`
- Run: `docker compose up -d postgres && ./gradlew bootRun`
- All tests: `./gradlew test`
- One class: `./gradlew test --tests 'com.example.inventory.stock.ReservationServiceTest'`
- One method: `./gradlew test --tests 'com.example.inventory.stock.ReservationServiceTest.releasesExpiredHolds'`
- Before handoff (as CI): `./gradlew check`

## Structure
- `src/main/java/com/example/inventory/<module>/`: controller, service, repository per module
- `src/main/resources/db/migration/`: Flyway, `V<n>__<description>.sql`
- `docs/adr/`: decisions; read before changing a module boundary

## Rules
- Constructor injection only; no `@Autowired` on fields.
- Transactions live on service methods, not controllers or repositories.
- Stock never goes negative: reservations update rows under a lock or `@Version`.
- Controllers return DTOs; JPA entities never leave the service layer.
- Time comes from an injected `Clock`, never `LocalDateTime.now()`.

## Tests
- Unit tests with JUnit 5 and Mockito; database tests with Testcontainers.
- No `@Disabled` to get a change through.

## Boundaries
- Never edit an applied Flyway migration; add a new version.
- Do not change `application-prod.yml` or CI files.
- Changing a public REST endpoint: stop and propose it first.

## Handoff
- Branch `feat/<ticket>-short-name`; the pull request names the tests added.

What to adapt:

PHP and Laravel

An online academy: courses, enrollments and payments for them.

# academy: courses and enrollments (PHP 8.3, Laravel, MySQL)

## Commands
- Install: `composer install && cp .env.example .env && php artisan key:generate`
- Run: `php artisan serve`
- All tests: `php artisan test`
- One test class: `php artisan test --filter=EnrollmentTest`
- In parallel: `php artisan test --parallel`
- Style check: `./vendor/bin/pint --test` (fix: `./vendor/bin/pint`)
- Static analysis: `./vendor/bin/phpstan analyse --memory-limit=2G`
- Before handoff (as CI): `./vendor/bin/pint --test && ./vendor/bin/phpstan analyse && php artisan test`

## Structure
- `app/Http/Controllers/`: thin; validate through a Form Request, call a service
- `app/Services/`: business logic
- `app/Models/`, `app/Policies/`: Eloquent models and authorization
- `database/migrations/`, `database/factories/`
- `tests/Feature/`, `tests/Unit/`

## Rules
- Validation lives in Form Requests, authorization in Policies.
- No queries inside loops; eager-load with `with()`.
- Prices are integer cents, never floats.
- User-facing text goes through `__('key')`, with strings in `lang/`.
- Email and other slow work runs in queued jobs.
- New package: `composer require`, and say why in the pull request.

## Tests
- Every endpoint has a feature test; non-trivial logic has a unit test.
- Test data comes from factories.
- Do not delete or weaken an existing test.

## Boundaries
- Create a migration only when the task asks; never edit an applied one.
- Never run `migrate:fresh`, `migrate:reset` or `db:wipe`.
- Do not edit `.env` or production config.

## Handoff
- Branch `feat/<ticket>-short-name`; the pull request lists the tests run.

What to adapt:

A monorepo: root file and one nested file

A TypeScript monorepo with pnpm workspaces and Turborepo. The root file holds what every package shares; each app with its own rules adds a nested file.

# shipyard monorepo (pnpm workspaces, Turborepo, TypeScript)

## Commands
- Install: `pnpm install`
- Build everything: `pnpm turbo run build`
- Changed packages and their dependents:
  `pnpm turbo run lint typecheck test --filter=...[origin/main]`
- One package: `pnpm --filter @shipyard/api test`
- Add a dependency to one package: `pnpm --filter @shipyard/web add <package>`
- Before handoff (as CI): `pnpm turbo run lint typecheck test --filter=...[origin/main]`

## Structure
- `apps/web`, `apps/api`, `apps/worker`: deployable apps
- `packages/ui`, `packages/contracts`, `packages/config`: shared code
- Apps never import from each other; shared code moves to `packages/`.

## Rules
- A change to a package is tested in every package that depends on it.
- Shared dependency versions are pinned in the root `package.json`.
- Each app's own `AGENTS.md` adds to this file; where it differs, it says so.

## Boundaries
- Do not change `turbo.json`, `pnpm-workspace.yaml` or CI unless asked.
- `packages/contracts` is used by several teams: propose a change there first.
# apps/api: public REST API (Fastify, PostgreSQL)
# The root AGENTS.md applies; this file adds to it.

## Commands
- Run: `docker compose up -d db && pnpm --filter @shipyard/api dev`
- Tests: `pnpm --filter @shipyard/api test`
- Migrations live in `apps/api/migrations/` and run with `pnpm --filter @shipyard/api migrate`

## Rules
- Request and response types come from `@shipyard/contracts`; never redefine them here.
- Calls to the payment provider go through `src/providers/` only.
- Test doubles live in `test/doubles/`.

## Differs from the root
- Branches for this app start with `api/` instead of `feat/`.

What to adapt:

Checking that a template works

A file is only finished when an agent follows it. Give an agent a small, real task and watch four things:

CheckWhat you expect
CommandsThe agent runs your commands, including the one-test form, instead of inventing its own.
PlacementNew code lands where a colleague would have put it.
BoundariesAsked for something that needs a migration or an API change, the agent stops and proposes a plan.
HandoffEvery check in the "before handoff" line passes, and CI agrees.

Leave out what a tool already does (formatting rules), generic wishes ("write clean code"), the project's history, and anything secret: tokens, internal hostnames, customer data. The file is committed and read by every tool you connect.

Questions

Where can I find AGENTS.md examples for my stack?

Start from the template above that is closest to your stack, then replace every command with yours and run it. Examples from other projects carry their rules, not yours.

What language should AGENTS.md be written in?

The language the team works in. Keep commands, paths and identifiers exactly as they are in the code.

Do I need nested AGENTS.md files in a monorepo?

When packages differ in stack, commands or rules, yes. Agents use the file nearest to the code they are editing, so the root file holds shared rules and each nested file only what is local.

How do I make these work with Claude Code?

Recent Claude Code versions read AGENTS.md directly when the repository has no CLAUDE.md. If you also need a CLAUDE.md, put @AGENTS.md on its first line so both tools share one set of rules.