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