AGENTS.md for a TypeScript monorepo (pnpm workspaces + Turborepo)
A free AGENTS.md for TypeScript monorepos on pnpm workspaces and Turborepo: turbo run with --filter and --affected, dependencies in the package that uses them, workspace:* links, catalogs, env vars in turbo.json and a done checklist.
- Install
AGENTS.md (repository root)- Last tested
- Codex / Copilot / Cursor, pnpm 12.23 + Turborepo 2.11 docs · 2026-11-26
Agents make a predictable set of mistakes in a JavaScript monorepo: installing a dependency in the root instead of the package that imports it, importing another package through ../../packages/ui/src, running npm in a pnpm repo, adding a script Turborepo never runs, or reading a new environment variable that Turborepo's Strict Mode filters out. This AGENTS.md gives them the pnpm and Turborepo way to do each of those.
It follows the official docs, checked on November 26, 2026, when pnpm 12.23.0 and turbo 2.11.13 were the latest releases on npm. Turborepo's docs recommend installing dependencies where they're used and keeping only repo tools like turbo, husky and lint-staged in the root, linking internal packages with workspace:*, and avoiding ../ across package boundaries. Its configuring-tasks page explains dependsOn with ^build and why a task without outputs restores no files on a cache hit, and its environment variables page says Strict Mode is the default, framework prefixes like NEXT_PUBLIC_ are inferred, and turbo doesn't load .env files. pnpm's docs cover --filter, -w for root installs, the catalog: protocol, the CI lockfile check and the allowBuilds list for install scripts.
Fill in the [bracketed] package names, folders and commands. Codex, Cursor and GitHub Copilot all read nested AGENTS.md files, so add apps/web/AGENTS.md for app-specific commands, and Claude Code reads AGENTS.md too when the repo has no CLAUDE.md. Our post on agent instructions in a monorepo explains how each tool picks up nested files. Using Python instead? See our AGENTS.md for a uv workspace.
AGENTS.md# AGENTS.md
Instructions for AI coding agents working in this repository. This is a TypeScript monorepo: pnpm workspaces manage the packages and dependencies, and Turborepo runs the tasks. There is one `pnpm-lock.yaml` at the root.
## Layout
- `pnpm-workspace.yaml` lists the packages (`[apps/*, packages/*]`). Every folder with a `package.json` in those directories is a workspace package.
- `[apps/]`: deployable applications, e.g. `[apps/web]` (Next.js) and `[apps/api]`.
- `[packages/]`: internal packages shared by the apps, e.g. `[packages/ui]`, `[packages/db]`, `[packages/typescript-config]` and `[packages/eslint-config]`.
- Internal packages are named `[@repo]/<name>` and expose their entry points through the `exports` field in their `package.json`.
- `turbo.json` at the root defines the tasks. A package may have its own `turbo.json` that extends the root one.
- A package folder may contain its own `AGENTS.md` with extra rules. When you work inside it, follow the nearest one as well as this file.
## Commands
Run everything from the repository root with pnpm. Don't use npm, yarn or npx, and don't switch package managers.
- Install: `pnpm install`
- All tasks: `[pnpm turbo run build lint check-types test]`
- One package: `pnpm turbo run <task> --filter=<package-name>` (example: `pnpm turbo run test --filter=@repo/ui`)
- A package and everything it depends on: `--filter=<package-name>...`
- A package and everything that depends on it: `--filter=...<package-name>`
- Only what this branch changed: `pnpm turbo run build lint test --affected`
- Dev server for one app: `[pnpm turbo run dev --filter=web]`
- In CI, `pnpm install` fails if `pnpm-lock.yaml` needs an update, so commit the lockfile with every dependency change.
## Dependencies
- Install a dependency in the package that imports it, not in the root: `pnpm add <dep> --filter <package-name>` (add `--save-dev` for dev tools).
- The root `package.json` only holds repository tools such as `turbo`, `[husky]` and `[lint-staged]`. Adding to the root needs `-w`; ask before doing it.
- One workspace package depending on another uses the workspace protocol: `"@repo/ui": "workspace:*"`. Never import another package through a relative path like `../../packages/ui/src`, and never reach into its `src` past what `exports` exposes.
- If `pnpm-workspace.yaml` has a `catalog`, use `"<dep>": "catalog:"` for dependencies listed there instead of a version range.
- Never edit `pnpm-lock.yaml` by hand. Don't upgrade unrelated packages, and ask before running `pnpm up --recursive` or `--latest`.
- Don't add packages to `allowBuilds` in `pnpm-workspace.yaml` or pass `--allow-build` without asking. Those let a dependency's install scripts run.
## Tasks and caching (turbo.json)
- A new script that should run through Turborepo needs a matching key under `tasks` in `turbo.json`, with the same name as the script in the package's `package.json`.
- Build tasks depend on their dependencies' builds (`"dependsOn": ["^build"]`) and list their files in `outputs` (for Next.js: `[".next/**", "!.next/cache/**", "!.next/dev/**"]`; for tsc or Vite: `["dist/**"]`). Without `outputs`, a cache hit restores no files.
- Turborepo runs tasks in Strict Mode by default: a task only sees environment variables listed in its `env` (or `globalEnv`). When code starts reading a new variable, add it to the `env` list of every task that needs it. Framework prefixes such as `NEXT_PUBLIC_*` and `VITE_*` are added automatically.
- Turborepo does not load `.env` files. Keep them in the app that uses them, never in the root, and never commit real values.
- Long-running tasks such as `dev` are `"persistent": true` and `"cache": false`. Nothing can depend on them.
## Boundaries
- `[packages/*]` must not import from `[apps/*]`. Apps may import packages.
- Shared UI goes in `[packages/ui]`, shared types and schemas in `[packages/[shared]]`. Don't copy them into an app.
- Each package has its own `tsconfig.json` that extends `[@repo/typescript-config]`. Don't add a root `tsconfig.json` to make an import work.
## Before you say you're done
1. Run `pnpm turbo run lint check-types test --affected` and fix what fails.
2. If you changed dependencies, run `pnpm install` and include `pnpm-lock.yaml` in the change.
3. If you added an environment variable, check that it's in `turbo.json` and documented in the app's `.env.example`.
4. Summarize which packages you changed and anything you couldn't verify.