Back to DevOps & CI/CD

turborepo-caching

Turborepomonorepocachingbuild optimizationCI/CDDevOpsworkflowJavaScript
⭐ 36.8kπŸ“„ MITπŸ•’ 2026-06-16Source β†—

Install this skill

npx skills add wshobson/agents

Works across Claude Code, Cursor, Codex, Copilot & Antigravity

Turborepo caching manages incremental builds in monorepos by identifying file changes and reusing previously computed output. By defining dependencies, inputs, and output paths within turbo.json, the system avoids redundant work across internal workspaces. It maintains a hash-based record of past tasks, allowing developers to skip execution for packages that remain unchanged since the last successful build. This functionality extends to CI/CD environments through remote caching, where build artifacts are stored on a centralized server or cloud provider to benefit the entire team. By strictly controlling what triggers a re-runβ€”via environment variables, source code patterns, or dependency treesβ€”the build system reduces cycle times significantly in multi-package environments. Proper configuration prevents cache invalidation and ensures consistency between local development and automated deployment pipelines.

When to Use This Skill

  • β€’Accelerating CI/CD pipelines by fetching previously built artifacts
  • β€’Reducing local build times in large monorepos with dozens of sub-packages
  • β€’Standardizing build logic across disparate internal teams
  • β€’Ensuring production builds only run on packages affected by recent commits

How to Invoke This Skill

Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:

  • β€œconfigure turbo caching for my monorepo
  • β€œhow to speed up builds with turborepo
  • β€œset up remote caching for turborepo on github actions
  • β€œtroubleshoot turborepo cache misses
  • β€œdefine input and output patterns in turbo.json

Pro Tips

  • πŸ’‘Prioritize `outputs` carefully: Be explicit and minimal with `outputs` in `turbo.json`. Caching too many unnecessary files can lead to larger cache sizes and slower restore times, while missing critical outputs causes unnecessary re-builds. Focus on actual build artifacts.
  • πŸ’‘Leverage `globalDependencies` & `globalEnv`: Don't forget to include global files (like `.env.*`) or environment variables (e.g., `NODE_ENV`) that impact *all* tasks' cache keys. This prevents unexpected cache misses when these global factors change.
  • πŸ’‘Implement a robust remote cache: For team environments or CI/CD, always set up a remote cache (e.g., Vercel Remote Cache, S3, GCS) to share cache artifacts across machines, drastically reducing build times for subsequent runs and improving consistency.

What this skill does

  • β€’Defines fine-grained dependency trees between local workspaces
  • β€’Maps input source patterns to specific output directories for caching
  • β€’Integrates remote storage providers to share build artifacts across machines
  • β€’Supports scoped task execution using complex workspace filtering
  • β€’Configures global environment variable tracking to manage build consistency

When not to use it

  • βœ•Simple repositories with no internal dependencies or package modularity
  • βœ•Projects where build outputs are non-deterministic and cannot be safely cached

Example workflow

  1. Define build, test, and lint tasks inside the root turbo.json file
  2. Specify input file patterns for each workspace to trigger cache invalidation accurately
  3. Configure remote cache tokens for CI integration with Vercel or a custom server
  4. Execute build commands using the --filter flag to limit scope to affected packages
  5. Monitor task output logs to verify hits and misses during CI execution

Prerequisites

  • –Turborepo CLI installed locally
  • –A workspace-based monorepo structure
  • –Node.js environment

Pitfalls & limitations

  • !Over-broad input patterns that trigger unnecessary rebuilds
  • !Forgetting to include environment variables in the globalEnv config, causing cache drift
  • !Non-deterministic build outputs that cause inconsistent behavior across machines

FAQ

Why is my cache missing despite no changes to code?
Check if your inputs or globalEnv configurations are missing critical environment variables or external configuration files that affect build output.
Can I use self-hosted storage for remote caching?
Yes, you can implement a custom Express server that conforms to the V8 artifact API to host your own cache storage.
What is the difference between a local and remote cache?
Local cache stores build artifacts in your machine's node_modules/.cache, while remote cache uploads these files to a shared provider for use by other developers and CI agents.
How do I ignore specific files from triggering a cache miss?
You can use specific exclude patterns in your input definitions or modify the globalDependencies array in turbo.json.

How it compares

Unlike manual scripts that require shell-level checks of folder hashes, Turborepo integrates directly into the execution lifecycle, automating dependency graph resolution and artifact distribution.

Source & trust

⭐ 37k starsπŸ“„ MITπŸ•’ Updated 2026-06-16
πŸ“„ Full skill instructions β€” original source: wshobson/agents
# Turborepo Caching

Production patterns for Turborepo build optimization.

## When to Use This Skill

- Setting up new Turborepo projects
- Configuring build pipelines
- Implementing remote caching
- Optimizing CI/CD performance
- Migrating from other monorepo tools
- Debugging cache misses

## Core Concepts

### 1. Turborepo Architecture

Workspace Root/
β”œβ”€β”€ apps/
β”‚ β”œβ”€β”€ web/
β”‚ β”‚ └── package.json
β”‚ └── docs/
β”‚ └── package.json
β”œβ”€β”€ packages/
β”‚ β”œβ”€β”€ ui/
β”‚ β”‚ └── package.json
β”‚ └── config/
β”‚ └── package.json
β”œβ”€β”€ turbo.json
└── package.json


### 2. Pipeline Concepts

| Concept | Description |
| -------------- | -------------------------------- |
| **dependsOn** | Tasks that must complete first |
| **cache** | Whether to cache outputs |
| **outputs** | Files to cache |
| **inputs** | Files that affect cache key |
| **persistent** | Long-running tasks (dev servers) |

## Templates

### Template 1: turbo.json Configuration

{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": [".env", ".env.local"],
"globalEnv": ["NODE_ENV", "VERCEL_URL"],
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"],
"env": ["API_URL", "NEXT_PUBLIC_*"]
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"],
"inputs": ["src/**/*.tsx", "src/**/*.ts", "test/**/*.ts"]
},
"lint": {
"outputs": [],
"cache": true
},
"typecheck": {
"dependsOn": ["^build"],
"outputs": []
},
"dev": {
"cache": false,
"persistent": true
},
"clean": {
"cache": false
}
}
}


### Template 2: Package-Specific Pipeline

// apps/web/turbo.json
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"],
"pipeline": {
"build": {
"outputs": [".next/**", "!.next/cache/**"],
"env": ["NEXT_PUBLIC_API_URL", "NEXT_PUBLIC_ANALYTICS_ID"]
},
"test": {
"outputs": ["coverage/**"],
"inputs": ["src/**", "tests/**", "jest.config.js"]
}
}
}


### Template 3: Remote Caching with Vercel

# Login to Vercel
npx turbo login

# Link to Vercel project
npx turbo link

# Run with remote cache
turbo build --remote-only

# CI environment variables
TURBO_TOKEN=your-token
TURBO_TEAM=your-team


# .github/workflows/ci.yml
name: CI

on:
push:
branches: [main]
pull_request:

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Build
run: npx turbo build --filter='...[origin/main]'

- name: Test
run: npx turbo test --filter='...[origin/main]'


### Template 4: Self-Hosted Remote Cache

// Custom remote cache server (Express)
import express from "express";
import { createReadStream, createWriteStream } from "fs";
import { mkdir } from "fs/promises";
import { join } from "path";

const app = express();
const CACHE_DIR = "./cache";

// Get artifact
app.get("/v8/artifacts/:hash", async (req, res) => {
const { hash } = req.params;
const team = req.query.teamId || "default";
const filePath = join(CACHE_DIR, team, hash);

try {
const stream = createReadStream(filePath);
stream.pipe(res);
} catch {
res.status(404).send("Not found");
}
});

// Put artifact
app.put("/v8/artifacts/:hash", async (req, res) => {
const { hash } = req.params;
const team = req.query.teamId || "default";
const dir = join(CACHE_DIR, team);
const filePath = join(dir, hash);

await mkdir(dir, { recursive: true });

const stream = createWriteStream(filePath);
req.pipe(stream);

stream.on("finish", () => {
res.json({
urls: [${req.protocol}://${req.get("host")}/v8/artifacts/${hash}],
});
});
});

// Check artifact exists
app.head("/v8/artifacts/:hash", async (req, res) => {
const { hash } = req.params;
const team = req.query.teamId || "default";
const filePath = join(CACHE_DIR, team, hash);

try {
await fs.access(filePath);
res.status(200).end();
} catch {
res.status(404).end();
}
});

app.listen(3000);


// turbo.json for self-hosted cache
{
"remoteCache": {
"signature": false
}
}


# Use self-hosted cache
turbo build --api="http://localhost:3000" --token="my-token" --team="my-team"


### Template 5: Filtering and Scoping

# Build specific package
turbo build --filter=@myorg/web

# Build package and its dependencies
turbo build --filter=@myorg/web...

# Build package and its dependents
turbo build --filter=...@myorg/ui

# Build changed packages since main
turbo build --filter='...[origin/main]'

# Build packages in directory
turbo build --filter='./apps/*'

# Combine filters
turbo build --filter=@myorg/web --filter=@myorg/docs

# Exclude package
turbo build --filter='!@myorg/docs'

# Include dependencies of changed
turbo build --filter='...[HEAD^1]...'


### Template 6: Advanced Pipeline Configuration

{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"],
"inputs": ["$TURBO_DEFAULT$", "!**/*.md", "!**/*.test.*"]
},
"test": {
"dependsOn": ["^build"],
"outputs": ["coverage/**"],
"inputs": ["src/**", "tests/**", "*.config.*"],
"env": ["CI", "NODE_ENV"]
},
"test:e2e": {
"dependsOn": ["build"],
"outputs": [],
"cache": false
},
"deploy": {
"dependsOn": ["build", "test", "lint"],
"outputs": [],
"cache": false
},
"db:generate": {
"cache": false
},
"db:push": {
"cache": false,
"dependsOn": ["db:generate"]
},
"@myorg/web#build": {
"dependsOn": ["^build", "@myorg/db#db:generate"],
"outputs": [".next/**"],
"env": ["NEXT_PUBLIC_*"]
}
}
}


### Template 7: Root package.json Setup

{
"name": "my-turborepo",
"private": true,
"workspaces": ["apps/*", "packages/*"],
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo lint",
"test": "turbo test",
"clean": "turbo clean && rm -rf node_modules",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"changeset": "changeset",
"version-packages": "changeset version",
"release": "turbo build --filter=./packages/* && changeset publish"
},
"devDependencies": {
"turbo": "^1.10.0",
"prettier": "^3.0.0",
"@changesets/cli": "^2.26.0"
},
"packageManager": "[email protected]"
}


## Debugging Cache

# Dry run to see what would run
turbo build --dry-run

# Verbose output with hashes
turbo build --verbosity=2

# Show task graph
turbo build --graph

# Force no cache
turbo build --force

# Show cache status
turbo build --summarize

# Debug specific task
TURBO_LOG_VERBOSITY=debug turbo build --filter=@myorg/web


## Best Practices

### Do's

- **Define explicit inputs** - Avoid cache invalidation
- **Use workspace protocol** - "@myorg/ui": "workspace:*"
- **Enable remote caching** - Share across CI and local
- **Filter in CI** - Build only affected packages
- **Cache build outputs** - Not source files

### Don'ts

- **Don't cache dev servers** - Use persistent: true
- **Don't include secrets in env** - Use runtime env vars
- **Don't ignore dependsOn** - Causes race conditions
- **Don't over-filter** - May miss dependencies

## Resources

- [Turborepo Documentation](https://turbo.build/repo/docs)
- [Caching Guide](https://turbo.build/repo/docs/core-concepts/caching)
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/turborepo-caching/
  3. Save the file as SKILL.md
  4. The agent will automatically discover the skill based on its description.

Option B: Global Installation (All Agents)

Save the file to these locations to make it available across all projects:

  • Claude Code: ~/.claude/skills/wshobson/agents/turborepo-caching/SKILL.md
  • Cursor: ~/.cursor/skills/wshobson/agents/turborepo-caching/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/wshobson/agents/turborepo-caching/SKILL.md

πŸš€ Install with CLI:
npx skills add wshobson/agents

Read the Master Guide: Mastering Agent Skills β†’

Recommended Rules

View more rules β†’

Recommended Workflows

View more workflows β†’

Recommended MCP Servers

View more MCP servers β†’

Take It Further

Maximize your productivity with these powerful resources

πŸ“‹

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
πŸ“–

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid devops & ci/cd issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under DevOps & CI/CD and is published by W. Shobson, maintained in wshobson/agents.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.