Turborepo Skill
Build system guidance for JavaScript and TypeScript monorepos using Turborepo.
Core Rules
- Create package tasks, not root tasks.
- Register task behavior in
turbo.json.
- Let root
package.json delegate with turbo run <task>.
- Use
turbo <task> only for interactive one-off terminal commands, not in committed code.
- Declare workspace dependencies in
package.json so dependsOn: ["^build"] can resolve actual package relationships.
Baseline Pattern
// apps/web/package.json
{
"scripts": {
"build": "next build",
"lint": "eslint .",
"test": "vitest"
}
}
// turbo.json
{
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"lint": {},
"test": {
"dependsOn": ["build"]
}
}
}
// root package.json
{
"scripts": {
"build": "turbo run build",
"lint": "turbo run lint",
"test": "turbo run test"
}
}
Quick Routing
Read only the reference files needed for the task:
| Need |
Read |
Task definitions, dependsOn, outputs, persistent, package overrides |
references/configuration/RULE.md, references/configuration/tasks.md |
| Global options, daemon, cacheDir, env mode |
references/configuration/global-options.md |
| Cache misses or remote cache |
references/caching/RULE.md, references/caching/gotchas.md, references/caching/remote-cache.md |
Env vars, .env, strict vs loose mode |
references/environment/RULE.md, references/environment/modes.md, references/environment/gotchas.md |
--affected, --filter, package selection |
references/filtering/RULE.md, references/filtering/patterns.md |
CI, GitHub Actions, Vercel, turbo-ignore |
references/ci/RULE.md, references/ci/github-actions.md, references/ci/vercel.md, references/ci/patterns.md, references/cli/commands.md |
| Repo structure, package creation, dependency management |
references/best-practices/RULE.md, references/best-practices/structure.md, references/best-practices/packages.md, references/best-practices/dependencies.md |
| Watch mode and long-running dev tasks |
references/watch/RULE.md, references/configuration/tasks.md |
| Package boundaries and isolation |
references/boundaries/RULE.md |
Decision Trees
Configure a Task
Configure a task?
├─ Define dependencies or outputs → configuration/tasks.md
├─ Handle environment variables → environment/RULE.md
├─ Set package-specific overrides → configuration/RULE.md#package-configurations
├─ Add persistent/watch behavior → configuration/tasks.md + watch/RULE.md
└─ Tune global options → configuration/global-options.md
Debug Caching
Cache issue?
├─ Outputs not restored → add or fix `outputs`
├─ Unexpected misses → caching/gotchas.md
├─ Remote cache issue → caching/remote-cache.md
└─ Env or .env drift → environment/gotchas.md
Run Only Changed Work
Need changed packages only?
├─ Default path → `turbo run <task> --affected`
├─ Custom comparison base → add `--affected-base=...`
└─ Custom package selection → filtering/RULE.md + filtering/patterns.md
Set Up CI
CI setup?
├─ GitHub Actions → ci/github-actions.md
├─ Vercel deployment → ci/vercel.md
├─ Remote cache in CI → caching/remote-cache.md
└─ Skip unchanged work → ci/patterns.md + cli/commands.md
Structure the Monorepo
Repo/package structure?
├─ apps/ vs packages/ layout → best-practices/RULE.md
├─ Create internal package → best-practices/packages.md
├─ Workspace dependency management → best-practices/dependencies.md
└─ Enforce package boundaries → boundaries/RULE.md
High-Signal Anti-Patterns
- Root scripts that bypass Turborepo entirely. Root scripts should delegate with
turbo run, not embed app-specific task logic.
- Committed
turbo build or turbo lint commands in package.json, CI, or scripts. Use turbo run ... in committed code.
- Manual
prebuild chains that compile sibling packages instead of declaring workspace dependencies and using ^build.
- Missing
outputs on tasks that write files. Read the actual script before deciding whether a task is cacheable.
- Environment variables omitted from
env or .env files omitted from inputs, causing stale cache hits.
- Root-level
.env files in a monorepo, which create hidden coupling between packages.
- Relative imports or file traversal across package boundaries instead of importing through package APIs.
- Package-specific overrides cluttering root
turbo.json instead of using per-package turbo.json files.
See the detailed examples in:
references/configuration/gotchas.md
references/caching/gotchas.md
references/environment/gotchas.md
references/best-practices/structure.md
references/best-practices/packages.md
Common Configurations
Standard Build + Dev
{
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"dev": {
"cache": false,
"persistent": true
}
}
}
Transit Node for Parallel Tasks With Correct Cache Invalidation
{
"tasks": {
"transit": {
"dependsOn": ["^transit"]
},
"lint": {
"dependsOn": ["transit"]
}
}
}
Use this when a task can run in parallel but still needs dependency source changes to invalidate its cache.
Watch Mode Pattern
Use turbo watch for file-change loops, not turbo run ... --watch patterns improvised in scripts. Read references/watch/RULE.md before configuring persistent, interruptible, or with.
Validation Checklist
- Every committed command in code or CI uses
turbo run ....
- Tasks live in package scripts; root scripts only delegate.
dependsOn matches the actual dependency relationship: ^task for upstream packages, task for same-package prerequisites.
- Cacheable file-producing tasks declare
outputs.
- Relevant environment variables are in
env or globalEnv.
- Relevant
.env files are represented in inputs.
- Workspace packages import each other through package names, not relative source paths.
- CI uses
--affected or filters when appropriate instead of rebuilding everything by default.
Source Documentation
Based on official Turborepo docs (library v2.9.7-canary.12): apps/docs/content/docs/ — https://turborepo.dev/docs
1---2name: turborepo3description: Turborepo monorepo build system guidance. Triggers on: `turbo.json`, task pipelines, `dependsOn`, caching, remote cache, the `turbo` CLI, `--filter`, `--affected`, CI optimization, environment variables, internal packages, monorepo structure, and package boundaries. Use when the user configures tasks or workflows, creates packages, sets up a monorepo, shares code between apps, runs changed packages, debugs cache behavior, or works in an `apps/` plus `packages/` workspace.4---5
6# Turborepo Skill
7
8Build system guidance for JavaScript and TypeScript monorepos using Turborepo.
9
10## Core Rules
11
121. Create package tasks, not root tasks.
132. Register task behavior in `turbo.json`.
143. Let root `package.json` delegate with `turbo run <task>`.
154. Use `turbo <task>` only for interactive one-off terminal commands, not in committed code.
165. Declare workspace dependencies in `package.json` so `dependsOn: ["^build"]` can resolve actual package relationships.
17
18## Baseline Pattern
19
20```json
21// apps/web/package.json
22{
23 "scripts": {
24 "build": "next build",
25 "lint": "eslint .",
26 "test": "vitest"
27 }
28}
29```
30
31```json
32// turbo.json
33{
34 "tasks": {
35 "build": {
36 "dependsOn": ["^build"],
37 "outputs": ["dist/**", ".next/**", "!.next/cache/**"]
38 },
39 "lint": {},
40 "test": {
41 "dependsOn": ["build"]
42 }
43 }
44}
45```
46
47```json
48// root package.json
49{
50 "scripts": {
51 "build": "turbo run build",
52 "lint": "turbo run lint",
53 "test": "turbo run test"
54 }
55}
56```
57
58## Quick Routing
59
60Read only the reference files needed for the task:
61
62| Need | Read |
63| --- | --- |
64| Task definitions, `dependsOn`, `outputs`, `persistent`, package overrides | `references/configuration/RULE.md`, `references/configuration/tasks.md` |
65| Global options, daemon, cacheDir, env mode | `references/configuration/global-options.md` |
66| Cache misses or remote cache | `references/caching/RULE.md`, `references/caching/gotchas.md`, `references/caching/remote-cache.md` |
67| Env vars, `.env`, strict vs loose mode | `references/environment/RULE.md`, `references/environment/modes.md`, `references/environment/gotchas.md` |
68| `--affected`, `--filter`, package selection | `references/filtering/RULE.md`, `references/filtering/patterns.md` |
69| CI, GitHub Actions, Vercel, `turbo-ignore` | `references/ci/RULE.md`, `references/ci/github-actions.md`, `references/ci/vercel.md`, `references/ci/patterns.md`, `references/cli/commands.md` |
70| Repo structure, package creation, dependency management | `references/best-practices/RULE.md`, `references/best-practices/structure.md`, `references/best-practices/packages.md`, `references/best-practices/dependencies.md` |
71| Watch mode and long-running dev tasks | `references/watch/RULE.md`, `references/configuration/tasks.md` |
72| Package boundaries and isolation | `references/boundaries/RULE.md` |
73
74## Decision Trees
75
76### Configure a Task
77
78```
79Configure a task?
80├─ Define dependencies or outputs → configuration/tasks.md
81├─ Handle environment variables → environment/RULE.md
82├─ Set package-specific overrides → configuration/RULE.md#package-configurations
83├─ Add persistent/watch behavior → configuration/tasks.md + watch/RULE.md
84└─ Tune global options → configuration/global-options.md
85```
86
87### Debug Caching
88
89```
90Cache issue?
91├─ Outputs not restored → add or fix `outputs`
92├─ Unexpected misses → caching/gotchas.md
93├─ Remote cache issue → caching/remote-cache.md
94└─ Env or .env drift → environment/gotchas.md
95```
96
97### Run Only Changed Work
98
99```
100Need changed packages only?
101├─ Default path → `turbo run <task> --affected`
102├─ Custom comparison base → add `--affected-base=...`
103└─ Custom package selection → filtering/RULE.md + filtering/patterns.md
104```
105
106### Set Up CI
107
108```
109CI setup?
110├─ GitHub Actions → ci/github-actions.md
111├─ Vercel deployment → ci/vercel.md
112├─ Remote cache in CI → caching/remote-cache.md
113└─ Skip unchanged work → ci/patterns.md + cli/commands.md
114```
115
116### Structure the Monorepo
117
118```
119Repo/package structure?
120├─ apps/ vs packages/ layout → best-practices/RULE.md
121├─ Create internal package → best-practices/packages.md
122├─ Workspace dependency management → best-practices/dependencies.md
123└─ Enforce package boundaries → boundaries/RULE.md
124```
125
126## High-Signal Anti-Patterns
127
128- Root scripts that bypass Turborepo entirely. Root scripts should delegate with `turbo run`, not embed app-specific task logic.
129- Committed `turbo build` or `turbo lint` commands in `package.json`, CI, or scripts. Use `turbo run ...` in committed code.
130- Manual `prebuild` chains that compile sibling packages instead of declaring workspace dependencies and using `^build`.
131- Missing `outputs` on tasks that write files. Read the actual script before deciding whether a task is cacheable.
132- Environment variables omitted from `env` or `.env` files omitted from `inputs`, causing stale cache hits.
133- Root-level `.env` files in a monorepo, which create hidden coupling between packages.
134- Relative imports or file traversal across package boundaries instead of importing through package APIs.
135- Package-specific overrides cluttering root `turbo.json` instead of using per-package `turbo.json` files.
136
137See the detailed examples in:
138
139- `references/configuration/gotchas.md`
140- `references/caching/gotchas.md`
141- `references/environment/gotchas.md`
142- `references/best-practices/structure.md`
143- `references/best-practices/packages.md`
144
145## Common Configurations
146
147### Standard Build + Dev
148
149```json
150{
151 "tasks": {
152 "build": {
153 "dependsOn": ["^build"],
154 "outputs": ["dist/**", ".next/**", "!.next/cache/**"]
155 },
156 "dev": {
157 "cache": false,
158 "persistent": true
159 }
160 }
161}
162```
163
164### Transit Node for Parallel Tasks With Correct Cache Invalidation
165
166```json
167{
168 "tasks": {
169 "transit": {
170 "dependsOn": ["^transit"]
171 },
172 "lint": {
173 "dependsOn": ["transit"]
174 }
175 }
176}
177```
178
179Use this when a task can run in parallel but still needs dependency source changes to invalidate its cache.
180
181### Watch Mode Pattern
182
183Use `turbo watch` for file-change loops, not `turbo run ... --watch` patterns improvised in scripts. Read `references/watch/RULE.md` before configuring `persistent`, `interruptible`, or `with`.
184
185## Validation Checklist
186
187- Every committed command in code or CI uses `turbo run ...`.
188- Tasks live in package scripts; root scripts only delegate.
189- `dependsOn` matches the actual dependency relationship: `^task` for upstream packages, `task` for same-package prerequisites.
190- Cacheable file-producing tasks declare `outputs`.
191- Relevant environment variables are in `env` or `globalEnv`.
192- Relevant `.env` files are represented in `inputs`.
193- Workspace packages import each other through package names, not relative source paths.
194- CI uses `--affected` or filters when appropriate instead of rebuilding everything by default.
195
196## Source Documentation
197
198Based on official Turborepo docs (library v2.9.7-canary.12): `apps/docs/content/docs/` — https://turborepo.dev/docs