---
name: set-up-turborepo-monorepo
description: Sets up a pnpm workspace and Turborepo so apps and shared packages build in dependency order and skip tasks whose inputs did not change. Use when the user wants a Turborepo monorepo, a turbo.json task graph, or pnpm workspaces across several packages.
license: MIT
metadata:
  category: deployment
  tags: "monorepo,nodejs"
  author: johnny-bravo
  version: "1.0"
  updated: "2026-11-15"
  status: published
  aliases: "monorepo-management, turbo.json, pnpm workspaces, turborepo"
  source_url: "https://github.com/wshobson/agents/tree/7e2fb559cf4b824b27f1fec49fe88f7511066d26/plugins/developer-essentials/skills/monorepo-management"
  source_license: MIT
  copyright: "Copyright (c) 2024 Seth Hobson"
  original_author: "Seth Hobson (wshobson/agents, monorepo-management)"
  modified: "Adapted by TheSkillVault: narrowed to a pnpm plus Turborepo setup (workspace file, tasks graph, cache, remote-cache token); dropped Nx, Changesets and the CI workflow; added cycle and phantom-dependency gotchas and done-when."
  imported_on: "2026-11-15"
---

# Set up a Turborepo monorepo

One repository can hold several apps and the packages they share. Turborepo builds dependencies first. It skips a task whose inputs did not change. This skill uses pnpm as the installer.

## When to use
- You are starting a repository with more than one app.
- You want Turborepo to order builds and cache them.
- Shared code is copied between repositories and should become a package.

## When not to use
- You have one app and nothing shared. A normal repository is enough.
- You only need a CI file. Use configure-github-actions-ci.

## Steps
1. Create a private root package.json. Pin pnpm with the packageManager field. Do not publish the root.
2. Add pnpm-workspace.yaml. pnpm will not see packages listed only in package.json.
3. Put runnable apps in apps/ and shared code in packages/. Give each folder its own package.json and a name such as @repo/ui.
4. Depend on a sibling with the workspace protocol. Install it with pnpm add and a filter for the app that needs it.
5. Add turbo.json with a tasks key. Turborepo 2 rejects the old pipeline key. Move a 1.x file with npx @turbo/codemod migrate.
6. Make build depend on ^build so dependencies build first. List real outputs, such as dist, and exclude tool caches.
7. Mark dev as uncached and persistent. A dev server must not be replayed from cache.
8. Point the root scripts at turbo run build, turbo run dev and turbo run test.
9. Keep the graph free of cycles. Declare every import in that package's own package.json. A phantom dependency fails in CI.
10. If you enable a remote cache, keep the token in the host secret store. Do not commit it.

```yaml
packages:
  - "apps/*"
  - "packages/*"
```

```json
{
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**", ".next/**", "!.next/cache/**"]
    },
    "dev": { "cache": false, "persistent": true }
  }
}
```

## Gotchas
- A missing outputs list caches nothing useful. A missing input can replay a stale build.
- Hoisting every dependency hides packages you forgot to declare. Leave pnpm strict.
- Do not commit env files. You may list them as global dependencies so a value change busts the cache.
- A package that only one app needs can stay inside that app. Sharing it adds coupling.
- The root package stays private. Publishing it by mistake ships a workspace you did not mean to ship.

## Portability
This path uses pnpm and Turborepo. If you use npm or Yarn workspaces, keep the same folder split and task order. Nx is another build tool with the same idea. A single package does not need either.

## Done when
- pnpm-workspace.yaml lists the apps and packages, and install links them.
- turbo.json uses tasks, and turbo run build builds dependencies first.
- A second build is a cache hit when inputs did not change.
- No cache token and no env file is committed.

## Example prompt
"Set up a Turborepo monorepo with pnpm. One web app, one shared UI package, and a turbo.json that builds dependencies first."

---
Adapted from "monorepo-management" in wshobson/agents (MIT, Copyright (c) 2024 Seth Hobson). See LICENSE.txt.
