# Review Pull Requests on a Turborepo Monorepo

Yes. For each pull request the agent runs the affected packages' tasks and the builds CI skips, checks the task graph and env wiring, and posts one review.

[Run this on Rush](https://cloud.getrush.ai/run/review-pull-requests/turborepo/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

A pull request in a monorepo can pass in the package it touches and break the one that imports it. So the agent starts from the graph, not the diff. In a Turborepo like t3-oss/create-t3-turbo there are three apps (`apps/nextjs`, `apps/tanstack-start`, `apps/expo`), five packages (`api`, `auth`, `db`, `ui`, `validators`) and shared tooling under `tooling/`. `turbo.json` makes `lint` and `typecheck` depend on `^topo` and `^build`, because `packages/api`, `packages/db` and `packages/validators` export their types from `dist` and have a `build` script of `tsc` that emits declarations. `.github/workflows/ci.yml` runs `pnpm lint && pnpm lint:ws`, `pnpm format` and `pnpm typecheck` in three jobs and builds no app.

On the pull request's branch the agent installs with the pnpm version in `packageManager`, which also runs the root `postinstall`, a `sherif` check of the manifests. It then runs `lint`, `format` and `typecheck` through Turborepo filtered to what changed since the base branch and everything that depends on it, `--filter=...[origin/main]`, and quotes each failure with its package and file. After that it does what CI does not: with `.env` copied from `.env.example` and `CI` set, which makes the `env.ts` files skip validation, it runs `pnpm build`, so a change in `@acme/api` that type-checks but breaks `next build` or `vite build` is caught before merge.

Then it reads the diff against the conventions the repository encodes. A new environment variable has to appear in three places: the zod schema in an `env.ts`, since `restrictEnvAccess` in `tooling/eslint/base.ts` forbids `process.env` anywhere else in the two web apps and in `packages/auth`; `globalEnv` or a task's `env` in `turbo.json`, or a cached build will be replayed for a different value; and `.env.example`. A dependency used by more than one package belongs in the `catalog:` of `pnpm-workspace.yaml`, not as a second range. A new file in `packages/ui/src` needs its own line in that package's `exports` map, which lists each component by path. A task that writes files needs `outputs` that cover them, the way `apps/nextjs/turbo.json` lists `.next/**` without `.next/cache/**`, or a cache hit restores nothing.

Some findings are about what the diff does not show. The schema in `packages/db/src/schema.ts` is applied with `drizzle-kit push`, so there are no migration files to read; when a pull request adds a `notNull` column with no default to `Post`, the review states what that push would do to a table that already has rows. `packages/db/src/auth-schema.ts` is written by `pnpm auth:generate`, and a hand edit there is flagged. In `packages/api/src/router`, a new mutation built on `publicProcedure` gets a question, because the existing `create` and `delete` use `protectedProcedure`. The agent posts all of it as one review and pushes nothing.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Review this pull request to our Turborepo monorepo. Read the root package.json, pnpm-workspace.yaml, turbo.json and each app's turbo.json, .github/workflows/ci.yml, tooling/eslint/base.ts and the package.json of every workspace the diff touches. Install with the pinned pnpm on the pull request's branch and report anything the postinstall workspace check prints. Run lint, format and typecheck through turbo with --filter=...[origin/main] and quote every failure with its package, file and line. Copy .env.example to .env, set CI=1 and run pnpm build; report any app that fails to build. Then read the diff: a new environment variable must be in an env.ts schema, in turbo.json under globalEnv or the task's env, and in .env.example; a dependency shared by packages must use the pnpm catalog; a new file in packages/ui/src needs an exports entry; a task that writes files needs outputs; a change to packages/db/src/schema.ts gets a note on what drizzle-kit push would do to existing rows; packages/db/src/auth-schema.ts is generated and must not be edited by hand; a new mutation on publicProcedure needs a reason. Post one review on the pull request with the command results first and then findings by file and line. Do not push commits.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app/pull/42"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

One review on the pull request. It opens with a results block: install and workspace check, `lint`, `format`, `typecheck` over the affected packages, and the build of each app, each marked pass or fail with the lines that failed. Under it are findings by file and line, each naming the convention it departs from and where the repository already follows it, such as the `globalEnv` list or a sibling `exports` entry.

The affected-package list is part of the review, because it tells the author how far the change reaches: a one-line edit in `packages/validators` can put every app in scope. When a finding depends on a command, the output is quoted, and the rest of it is in the session's transcript at `GET /o/{org}/sessions/{id}/messages`.

The review comments; it does not approve or request changes for the team. A maintainer still decides whether the feature belongs, whether a pushed schema change is acceptable for the size of the real table, and how the Expo app behaves on a device, which a type check cannot show.

## Run it on every pull request

An automation in the Project that holds the repository, with this prompt, read-only switched on and a `github` trigger on `pull_request.opened` and `pull_request.synchronize`, starts one review when a pull request opens and another on each push to it. `branch_patterns` set to `main` keeps stacked branches out. The trigger places the pull request after the prompt and fills in nothing; read-only means the run can comment and cannot push.

The automation's max runs per hour is shared by both events, so a branch that receives many small pushes queues its later reviews instead of starting them all. Pull requests from forks never fire the trigger, and a fork's branch is not in the repository the URL names. For those a maintainer pushes the contributor's commits to a branch in the repository itself and opens a pull request from it, which starts the review like any other.

## Why run it on Rush?

A careful monorepo review means installing the whole workspace, working out which packages a change reaches, running three tasks across them and then building every app. Few reviewers do that for each pull request on their own machine, and CI here stops at the type check. The agent does it per pull request in a fresh sandbox, several at once when a queue has formed, and leaves the commands and their output in the run's record.

It also checks the wiring people forget because nothing fails right away: an env var missing from `turbo.json` only shows up later as a stale cached build, and a missing `exports` line only when another package imports the new file. Finding those at review time is cheaper than finding them after a deploy.

## Frequently asked questions

### Does it run every package's tasks on every pull request?

No. It uses Turborepo's filter for packages changed since the base branch plus their dependents, so a change to one app runs that app's tasks and a change to a shared package runs everything that imports it. The build is the exception: it runs for all apps, since that is the check CI lacks.

### Why does it build when our CI does not?

Because a type check and a bundler disagree often enough to matter: a server-only import that reaches a client component, or a route file the framework rejects, passes `tsc` and fails `next build`. Running the build in the sandbox costs the reviewer nothing and the result is one line in the review.

### Can it use our remote cache?

The workflow reads `TURBO_TEAM` and `TURBO_TOKEN` from the repository's variables and secrets, which a sandbox does not have, so the review runs with a cold local cache. That is slower and has one advantage: nothing is replayed from a cache entry that predates the change.

### Will it flag style issues?

Only what the repository's own tools flag. Prettier and ESLint are run with the shared configs under `tooling/`, and their output is quoted as is. The agent adds no rules of its own and does not comment on formatting the tools accept.

## More Turborepo jobs

- [Make Turborepo CI Check Only the Packages a Pull Request Changed](https://getrush.ai/run/run-ci-on-changed-packages/turborepo/)
- [Upgrade npm Dependencies in a Turborepo Monorepo](https://getrush.ai/run/upgrade-npm-dependencies/turborepo/)
- [Write Vitest Tests for a Turborepo Monorepo](https://getrush.ai/run/write-vitest-tests/turborepo/)

## The same job on other stacks

- [Review Pull Requests on a Typer CLI](https://getrush.ai/run/review-pull-requests/typer/)
- [Review Every Pull Request on a VS Code Extension Repository](https://getrush.ai/run/review-pull-requests/vscode-extension/)
- [Review Pull Requests Automatically in a Vue App](https://getrush.ai/run/review-pull-requests/vue/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
