CLAUDE.md template for Monorepo
Several apps and shared packages in one repository.
CLAUDE.md
# Monorepo A JavaScript or TypeScript monorepo with several apps and shared packages in one repository. Change any command below that differs from the workspace tool you use (pnpm, npm workspaces, turbo, nx). ## Commands ```bash pnpm install # install every workspace's dependencies pnpm --filter <package> test # run one package's tests pnpm -r lint # lint every package pnpm -r test # run the tests in every package pnpm -r build # build every package, run before calling a change done ``` Run the tests and the linter after every code change, and fix failures before saying a task is done. ## Layout - Deployable apps live in apps/ and shared libraries in packages/. Each has its own package.json and its own tests. - Work inside the package you were asked about. Run commands with a filter for that package, not across the whole repo, until the final check. - Apps import shared code through the package name, never through relative paths that cross a package boundary. ## Conventions - A change to a shared package can break every app that uses it. Check who imports it before changing a public export. - Keep dependencies declared in the package that uses them. Do not add root-level dependencies for a single package. - Match the style of the file you are editing. Do not reformat files you did not change. ## Database - Database schema and migrations belong to one package. Change them only there, with a new migration file. - Never edit a migration that has shipped, and never run destructive commands (drop, reset) against a shared or production database. ## Secrets - Never read, print, edit or commit .env files, credentials, API keys or private keys. - Use placeholder values in examples and tests. If a secret shows up in a file or a log, stop and tell me. ## Deploys - Never deploy any app to production. I run production deploys myself. - Do not change CI workflows, build pipeline config or per-app deployment settings without asking. ## Git - Make small commits on a branch and write messages that say why the change was made. - Never run git push --force, git reset --hard, git clean, git checkout -- <file>, git stash or git rebase, and never use --no-verify. Ask first. - Do not push unless I ask. ## Do not touch - The root lockfile and workspace config (pnpm-workspace.yaml, turbo.json, nx.json): do not edit without asking. - Packages outside the one you were asked to change, unless the task says so. - Build output folders (dist/, .turbo/, node_modules/) and anything marked generated or do not edit.
AGENTS.md
# AGENTS.md: Monorepo Instructions for any coding agent working in this repository. A JavaScript or TypeScript monorepo with several apps and shared packages in one repository. Change any command below that differs from the workspace tool you use (pnpm, npm workspaces, turbo, nx). ## Commands ```bash pnpm install # install every workspace's dependencies pnpm --filter <package> test # run one package's tests pnpm -r lint # lint every package pnpm -r test # run the tests in every package pnpm -r build # build every package, run before calling a change done ``` Run the tests and the linter after every code change, and fix failures before saying a task is done. ## Layout - Deployable apps live in apps/ and shared libraries in packages/. Each has its own package.json and its own tests. - Work inside the package you were asked about. Run commands with a filter for that package, not across the whole repo, until the final check. - Apps import shared code through the package name, never through relative paths that cross a package boundary. ## Conventions - A change to a shared package can break every app that uses it. Check who imports it before changing a public export. - Keep dependencies declared in the package that uses them. Do not add root-level dependencies for a single package. - Match the style of the file you are editing. Do not reformat files you did not change. ## Database - Database schema and migrations belong to one package. Change them only there, with a new migration file. - Never edit a migration that has shipped, and never run destructive commands (drop, reset) against a shared or production database. ## Secrets - Never read, print, edit or commit .env files, credentials, API keys or private keys. - Use placeholder values in examples and tests. If a secret shows up in a file or a log, stop and tell me. ## Deploys - Never deploy any app to production. I run production deploys myself. - Do not change CI workflows, build pipeline config or per-app deployment settings without asking. ## Git - Make small commits on a branch and write messages that say why the change was made. - Never run git push --force, git reset --hard, git clean, git checkout -- <file>, git stash or git rebase, and never use --no-verify. Ask first. - Do not push unless I ask. ## Do not touch - The root lockfile and workspace config (pnpm-workspace.yaml, turbo.json, nx.json): do not edit without asking. - Packages outside the one you were asked to change, unless the task says so. - Build output folders (dist/, .turbo/, node_modules/) and anything marked generated or do not edit.
Why it says what it says
Scope to one package
In a monorepo the agent's biggest risk is wandering into unrelated packages. Naming the scope keeps diffs reviewable.
Filtered commands
Running every package's tests after each small edit is slow. Filtered commands first, full run at the end.
Shared packages
A change to a shared export breaks other apps quietly. The rule asks the agent to look at importers first.
Single owner for the schema
When several apps touch the database, migrations drift. One owning package keeps a single history.
Workspace config is off limits
Root config and the lockfile affect every package at once, so changes there deserve a human decision.