turborepo-monorepo
Configure pipelines, set up local/remote caching, and run scoped tasks in a Turborepo monorepo. Use when you say: 'enable remote caching', 'optimize pipeline inputs/outputs', or 'filter builds to affected packages'.
git clone --depth 1 https://github.com/monkilabs/opencastle /tmp/turborepo-monorepo && cp -r /tmp/turborepo-monorepo/src/orchestrator/plugins/turborepo ~/.claude/skills/turborepo-monorepoSKILL.md
<!-- ⚠️ This file is managed by OpenCastle. Edits will be overwritten on update. Customize in the .opencastle/ directory instead. -->
# Turborepo Monorepo
## Commands
### Running Tasks
```bash
turbo run build # Build all packages
turbo run test # Test all packages
turbo run lint # Lint all packages
turbo run build --filter=web # Build specific package
turbo run build --filter=./apps/* # Build all apps
turbo run build --filter=...[HEAD~1] # Only affected since last commit
```
### Common Patterns
```bash
turbo run build test lint # Run multiple tasks
turbo run build --dry-run # Preview what would run
turbo run build --graph # Visualize task graph
turbo run build --force # Ignore cache, rebuild all
turbo run build --concurrency=4 # Limit parallelism
```
### Forbidden Commands
```bash
# NEVER use these directly — always go through turbo:
npm run build # Skips caching and parallelism
cd apps/web && npm test # Skips dependency resolution
```
## Pipeline Configuration (turbo.json)
```json
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"test": {
"dependsOn": ["build"],
"inputs": ["src/**", "test/**"]
},
"lint": {
"dependsOn": ["^build"]
},
"dev": {
"cache": false,
"persistent": true
}
}
}
```
### Key Concepts
- `^build` — run `build` in dependencies first (topological)
- `dependsOn` — declare task dependencies
- `outputs` — files to cache (miss = rebuild)
- `inputs` — files to hash for cache key (default: all tracked files)
- `cache: false` — never cache (use for `dev`, `start`)
- `persistent: true` — long-running tasks (dev servers)
## Caching
### Local Cache
Turborepo caches task outputs automatically in `node_modules/.cache/turbo`. Cache keys are computed from:
1. Task inputs (source files)
2. Environment variables
3. Dependencies' build outputs
4. `turbo.json` configuration
### Remote Cache
```bash
turbo login # Authenticate
turbo link # Link project to remote cache
turbo run build --remote-only # Force remote cache usage
```
- Shares cache across CI and team members
- Vercel Remote Cache or self-hosted (Ducktape, TurboCache)
- Set `TURBO_TOKEN` and `TURBO_TEAM` in CI environment
## Quick Workflow: Setup remote caching in CI
1. Add `TURBO_TOKEN` and `TURBO_TEAM` to your CI secrets.
2. Locally run `turbo login` and `turbo link` to verify the project is linked.
3. Add `turbo run build --remote` to the CI pipeline and watch for cache hit/miss logs.
4. If cache misses persist: verify `inputs`/`outputs` in `turbo.json`, stable env vars, then re-run.
**Validation (recommended):** run `turbo run build --dry-run` locally or in CI to preview the task graph and catch misconfigured inputs/outputs before executing.
See REFERENCE.md for CI snippets and advanced cache tuning.
## Package Workspace Structure
```
monorepo/
├── turbo.json
├── package.json # Root workspace config
├── apps/
│ ├── web/ # Next.js app
│ └── docs/ # Documentation site
├── packages/
│ ├── ui/ # Shared UI components
│ ├── config/ # Shared config (ESLint, TS)
│ └── utils/ # Shared utilities
```
## Best Practices
- Always use `turbo run` instead of directly invoking package scripts
- Define `outputs` for every cacheable task — missing outputs mean missing cache
- Use `--filter` to scope commands to affected packages
- Set `inputs` to narrow cache keys and avoid unnecessary rebuilds
- Use `--dry-run` to debug pipeline configuration
- Add `TURBO_TOKEN` and `TURBO_TEAM` to CI for remote caching
- Never commit `.turbo/` or `node_modules/.cache/turbo`
Further reading: see REFERENCE.md in this directory for CI snippets and advanced cache tuning.Creates pages/layouts, defines content collections, configures hydration directives, and wires integrations. Use when adding or modifying Astro pages, layouts, components, or content collections. Trigger terms: Astro, content collection, client:load, client:visible, astro:content
Drive real browsers via Chrome DevTools MCP: navigate pages, capture snapshots, run responsive checks, and collect console/perf traces. Use when the user mentions: 'validate UI change in Chrome', 'capture a screenshot', 'run responsive checks', or 'collect console logs'. Trigger terms: browser testing, DevTools, console logs, screenshot, responsive testing
Creates and deploys Cloudflare Workers, configures wrangler.toml bindings, sets up KV/D1/R2 storage and Durable Objects, manages Pages deployments, and implements edge function patterns. Use when building or deploying Cloudflare Workers, setting up Pages, working with KV/D1/R2 storage, configuring wrangler.toml, or deploying edge applications.
Creates Contentful content types, queries entries via GraphQL/REST, runs CLI migrations, and manages assets and locales. Use when building or modifying Contentful content models, writing queries, or migrating content.
Convex reactive database patterns, schema design, real-time queries, mutations, actions, authentication, migrations, performance optimization, and component creation. Use when designing Convex schemas, writing queries/mutations, managing the Convex backend, setting up auth, migrating data, optimizing performance, or building Convex components.
Deploys applications, databases, and services on self-hosted Coolify instances, manages environments and env vars, runs infrastructure diagnostics, and performs batch operations. Use when deploying apps to Coolify, managing Coolify servers, debugging deployment issues, setting up databases, or managing Coolify infrastructure.
Writes Cypress E2E/component tests, configures `cy.intercept()` and `cy.session()`, authors custom commands, and wires CI artifacts. Use when creating E2E specs, component tests, or CI test pipelines. Trigger terms: cypress, e2e, component test, cy.intercept, cy.session
Drizzle ORM schema definition, type-safe queries, relational queries, CRUD operations, transactions, migrations with drizzle-kit, and database setup for PostgreSQL, MySQL, and SQLite. Use when defining database schemas, writing queries or joins, managing migrations, setting up a new Drizzle project, or working with drizzle-kit.