All jobs

Make Turborepo CI Check Only the Packages a Pull Request Changed

Yes. An agent switches your pull request jobs to turbo run --affected, keeps full runs on main, checks the selection with --dry=json and opens a pull request.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the monorepo into its own sandbox and reads how CI runs today. In t3-oss/create-t3-turbo, .github/workflows/ci.yml has three jobs, lint, format and typecheck, triggered on pull requests into any branch, on pushes to main and on merge_group. Each job checks out the repository with actions/checkout@v5 at its default depth and calls the composite action in tooling/github/setup/action.yml, which runs pnpm/action-setup@v4, actions/setup-node@v6 with .nvmrc (22.21.0), pnpm add -g turbo and pnpm install. The workflow already passes TURBO_TEAM and TURBO_TOKEN for remote caching, so unchanged tasks can be cache hits, but every package is still scheduled on every pull request.

Then it reads the scripts the jobs call, because that is where a flag goes wrong. The root package.json defines lint as turbo run lint --continue -- --cache --cache-location .cache/.eslintcache, and format the same way for Prettier. Running pnpm lint --affected would put the flag after --, where ESLint receives it instead of turbo. So the workflow calls turbo directly, pnpm turbo run lint --affected --continue -- --cache --cache-location .cache/.eslintcache, and likewise for format and typecheck. pnpm lint:ws runs sherif over the whole workspace and is not a per-package task, so it stays as it is.

Turborepo's --affected compares main with HEAD by default and needs everything between them in the checkout; a shallow clone makes every package count as changed. The agent sets fetch-depth: 0 and filter: blob:none on actions/checkout, and because this workflow runs for pull requests into any branch, sets TURBO_SCM_BASE to the pull request's base branch as fetched (origin/${{ github.base_ref }}). Pushes to main and merge_group runs keep the full pnpm lint, pnpm format and pnpm typecheck, so what lands on main is always checked whole.

Before pushing, it proves the selection in the sandbox. It makes a local branch that touches only packages/validators, and another that touches turbo.json, and runs pnpm turbo run lint typecheck --affected --dry=json on each, reading which packages and tasks turbo would schedule. lint and typecheck depend on ^topo and ^build in turbo.json, so the dry run also shows the upstream builds that come along. It then runs the real --affected commands once to confirm they exit cleanly, and deletes the scratch branches.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Make the pull request jobs in .github/workflows/ci.yml check only the packages a pull request affects. Read ci.yml, tooling/github/setup/action.yml, the root package.json scripts, turbo.json and pnpm-workspace.yaml first. On pull_request events, run lint, format and typecheck through turbo run <task> --affected, calling turbo directly so the flag is not passed after -- to ESLint or Prettier, and keep their existing -- arguments. Check out with fetch-depth: 0 and filter: blob:none, and set TURBO_SCM_BASE to the pull request's base branch because the workflow runs for pull requests into any branch. Keep full runs on push to main and on merge_group, keep pnpm lint:ws unchanged, and keep the remote cache settings. Prove the selection with turbo run lint typecheck --affected --dry=json on a scratch branch that changes only packages/validators and on one that changes turbo.json, and put both package lists in the pull request. Change no package code. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  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

What comes back is a pull request that changes .github/workflows/ci.yml and nothing else. Each job's checkout gains fetch-depth: 0 and filter: blob:none, the task step branches on github.event_name, and pull requests run the --affected commands with TURBO_SCM_BASE set. The description shows the before and after commands per job and the two --dry=json package lists, so a reviewer sees what a change to one package would schedule and what a change to a root config file would.

The pull request's own checks are the first run of the new workflow on GitHub, and their logs show which packages turbo scheduled for a change that touches only .github/. The session transcript keeps every dry run, the real runs in the sandbox and their exit codes.

Before merging, a reviewer checks that the merge_group and main paths still run everything, that no --affected landed after a --, and that a full clone is acceptable for checkout time on this repository. If the remote cache is not configured in your fork, the full-run jobs on main take as long as they do today; only pull requests get faster.

Run it on every monorepo that adopts Turborepo

Teams usually meet this the week a monorepo's CI starts taking longer than its reviews. Start the run from a script with POST /o/{org}/sessions, the repository in resources, and come back to it: the sandbox parks when the turn ends, and a follow-up to POST /o/{org}/sessions/{id}/messages such as "also add the build job" wakes it with the checkout and its installed workspace still there.

For an organisation with several Turborepo repositories, the same script sends one session per repository, each with its own resources URL. Set a webhook_url on the key and Rush posts run.completed when each turn finishes, with a session_url whose pr_url is that repository's pull request.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Testing an --affected setup on a laptop means rewriting branches and history in the copy you are working in, and the only real proof, a pull request's own CI, needs a push. In a Rush sandbox the agent makes throwaway branches, runs --dry=json against each, installs the full pnpm workspace and runs the real tasks, all on a machine that exists for this run and none of it in your clone.

The record is what makes the change safe to merge. The transcript holds each dry-run selection and every command's output, and the pull request carries the package lists for a one-package change and a root-config change. A reviewer judges the selection from evidence, not from reading turbo's documentation again.

Frequently asked questions

Will a change to the lockfile or turbo.json skip tests it should run?

That is exactly what the second dry run checks. The agent changes turbo.json on a scratch branch and records which packages --affected selects, and the list is in the pull request. If the selection is narrower than you want for root files, ask in a follow-up and the agent can run the full set when those files change.

Does it still work with Vercel Remote Cache?

Yes. TURBO_TEAM and TURBO_TOKEN stay in the workflow's env. --affected decides which packages are scheduled; the remote cache still skips any scheduled task whose inputs it has seen.

Why does the checkout need the full history?

--affected compares the base branch with HEAD, and Turborepo's documentation says everything between them must be in the checkout; with a shallow clone it treats every package as changed. filter: blob:none keeps the full history while fetching file contents only when needed.

We use npm workspaces, not pnpm. Does that change anything?

Only the commands. The agent reads your root package.json and lockfile and writes npx turbo run or npm exec turbo run instead of pnpm turbo run; the checkout depth, TURBO_SCM_BASE and the dry runs are the same.

More Turborepo jobs

More jobs like this: Hand off a long task

Keep reading