Skip to main content
skill CX Codex

monorepo-ci-optimizer — Claude Code skill: what it does

monorepo-ci-optimizer — a CI skill for monorepos: it works out which packages a change touches and runs builds and tests only for those. Useful when every PR runs the whole workspace.

MIT 264 installs ★ 64 updated 2026-01-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add patricio0312rev/skills --skill monorepo-ci-optimizer -a claude-code
Open on GitHub

What monorepo-ci-optimizer does

The skill hands the agent ready-made CI blocks for a monorepo. With Turborepo the tasks get filtered through --filter='...[origin/main]'. With Nx you run nx affected after nrwl/nx-set-shas@v4 sets the diff range. A third route is a TypeScript script that walks packages/*, matches changed files against package paths and adds the packages that depend on them.

Caching and parallelism have their own sections: a .turbo cache keyed on the lockfile, Nx Cloud with NX_CLOUD_ACCESS_TOKEN, packages/*/dist restored by hash, --parallel for builds, and a job matrix with one entry per package.

Detection reads git history, so actions/checkout has to run with fetch-depth: 0. A shallow clone leaves the diff empty and nothing gets marked as affected. On a merge into main the skill advises a full build instead.

What it helps with

  • Cut a pipeline down to the packages a change touches
  • Wire nx affected to the right base and head SHAs
  • Turn on a remote Turborepo cache so repeat builds reuse earlier work
  • Split tests across a per-package job matrix
  • Write a TypeScript affected-detection script when neither Turborepo nor Nx is in play

Example prompts for the agent

  • Set up CI for this monorepo so only the packages a PR touches get built and tested
  • Rewrite .github/workflows/ci.yml around nx affected with nrwl/nx-set-shas@v4
  • Add a job matrix over the changed packages and cache packages/*/dist

How to install monorepo-ci-optimizer

1Skills CLI (Vercel)

npx skills add patricio0312rev/skills --skill monorepo-ci-optimizer -a claude-code

2Manually: put the files in place

~/.claude/skills/monorepo-ci-optimizer/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/monorepo-ci-optimizer/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about monorepo-ci-optimizer

How do I install monorepo-ci-optimizer in Claude Code?

Run npx skills add patricio0312rev/skills --skill monorepo-ci-optimizer -a claude-code. The skill lands at ~/.claude/skills/monorepo-ci-optimizer/SKILL.md.

What does monorepo-ci-optimizer do?

It helps the agent trim a CI workflow to the packages a change touches, with recipes for Turborepo, Nx and a hand-rolled TypeScript detector.

Why does affected detection come back empty?

Usually because actions/checkout runs without fetch-depth: 0. The detector diffs against origin/main, and a shallow clone gives it nothing to compare.

Source text

SKILL.md · MIT
---
name: monorepo-ci-optimizer
description: Optimizes CI pipelines for monorepos by detecting affected packages/apps and running only necessary builds and tests. Includes Turborepo/Nx strategies, caching, and parallel execution. Use for "monorepo CI", "affected detection", "incremental builds", or "workspace optimization".
---

# Monorepo CI Optimizer

Run only affected builds and tests in monorepos for faster CI.

## Affected Detection Strategy

### Using Turborepo

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

on:
  pull_request:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # Need full history for affected detection

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

      - run: pnpm install

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

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

      - name: Lint affected
        run: |
          pnpm turbo run lint --filter='...[origin/main]'
```

### Using Nx

```yaml
build:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0

    - uses: nrwl/nx-set-shas@v4

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

    - run: npm ci

    - name: Build affected projects
      run: npx nx affected:build --base=$NX_BASE --head=$NX_HEAD

    - name: Test affected projects
      run: npx nx affected:test --base=$NX_BASE --head=$NX_HEAD --parallel=3

    - name: Lint affected projects
      run: npx nx affected:lint --base=$NX_BASE --head=$NX_HEAD
```

## Remote Caching (Turborepo)

```yaml
- name: Setup Turborepo cache
  uses: actions/cache@v3
  with:
    path: .turbo
    key: ${{ runner.os }}-turbo-${{ github.sha }}
    restore-keys: |
      ${{ runner.os }}-turbo-

- name: Build with remote cache
  run: pnpm turbo run build
  env:
    TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
    TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
```

## Nx Cloud Integration

```yaml
- name: Setup Nx Cloud
  run: |
    npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js"
  env:
    NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

- name: Run affected
  run: |
    npx nx affected --target=build --parallel=3
    npx nx affected --target=test --parallel=3
    npx nx affected --target=lint --parallel=3
```

## Manual Affected Detection

```typescript
// scripts/get-affected.ts
import * as path from "path";
import { execSync } from "child_process";
import * as fs from "fs";

interface Package {
  name: string;
  path: string;
  dependencies: string[];
}

function getChangedFiles(base: string = "origin/main"): string[] {
  const output = execSync(`git diff --name-only ${base}...HEAD`, {
    encoding: "utf-8",
  });
  return output.split("\n").filter(Boolean);
}

function getPackages(): Package[] {
  const packagesDir = path.join(process.cwd(), "packages");
  return fs.readdirSync(packagesDir).map((name) => {
    const packageJson = JSON.parse(
      fs.readFileSync(path.join(packagesDir, name, "package.json"), "utf-8")
    );
    return {
      name: packageJson.name,
      path: `packages/${name}`,
      dependencies: [
        ...Object.keys(packageJson.dependencies || {}),
        ...Object.keys(packageJson.devDependencies || {}),
      ],
    };
  });
}

function getAffectedPackages(): string[] {
  const changedFiles = getChangedFiles();
  const packages = getPackages();
  const affected = new Set<string>();

  // Direct changes
  changedFiles.forEach((file) => {
    packages.forEach((pkg) => {
      if (file.startsWith(pkg.path)) {
        affected.add(pkg.name);
      }
    });
  });

  // Dependent packages
  let changed = true;
  while (changed) {
    changed = false;
    packages.forEach((pkg) => {
      if (!affected.has(pkg.name)) {
        const hasAffectedDep = pkg.dependencies.some((dep) =>
          affected.has(dep)
        );
        if (hasAffectedDep) {
          affected.add(pkg.name);
          changed = true;
        }
      }
    });
  }

  return Array.from(affected);
}

// Output for GitHub Actions
const affected = getAffectedPackages();
console.log(`::set-output name=packages::${affected.join(",")}`);
console.log(`Affected packages: ${affected.join(", ")}`);
```

## Matrix Strategy for Affected Packages

```yaml
detect-affected:
  runs-on: ubuntu-latest
  outputs:
    packages: ${{ steps.affected.outputs.packages }}
  steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0

    - id: affected
      run: |
        PACKAGES=$(node scripts/get-affected.ts)
        echo "packages=$PACKAGES" >> $GITHUB_OUTPUT

test-affected:
  needs: detect-affected
  if: needs.detect-affected.outputs.packages != ''
  runs-on: ubuntu-latest
  strategy:
    matrix:
      package: ${{ fromJSON(needs.detect-affected.outputs.packages) }}
  steps:
    - uses: actions/checkout@v4

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

    - run: pnpm install

    - name: Test ${{ matrix.package }}
      run: pnpm --filter ${{ matrix.package }} test
```

## Workspace-aware Caching

```yaml
- name: Cache workspace builds
  uses: actions/cache@v3
  with:
    path: |
      packages/*/dist
      packages/*/node_modules/.cache
    key: ${{ runner.os }}-workspace-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('packages/**/*.ts') }}
    restore-keys: |
      ${{ runner.os }}-workspace-${{ hashFiles('**/pnpm-lock.yaml') }}-
      ${{ runner.os }}-workspace-
```

## Parallel Execution

```yaml
- name: Build all packages in parallel
  run: pnpm turbo run build --parallel

- name: Test with controlled parallelism
  run: pnpm turbo run test --concurrency=3
```

## Optimization Metrics

```markdown
## Before Optimization

- Full build: 25 minutes
- All tests: 15 minutes
- Total: 40 minutes
- Runs on every PR

## After Affected Detection

- Affected build: 5 minutes (80% reduction)
- Affected tests: 3 minutes (80% reduction)
- Total: 8 minutes (80% reduction)
- Only runs necessary checks

## With Remote Caching

- Cache hit build: 30 seconds (98% reduction)
- Cache hit tests: 1 minute (93% reduction)
- Total: 1.5 minutes (96% reduction)
```

## Best Practices

1. **Fetch full history**: `fetch-depth: 0` for accurate diffs
2. **Topological order**: Build dependencies first
3. **Remote caching**: Share cache across CI runs
4. **Parallel execution**: Run independent tasks concurrently
5. **Incremental builds**: Only rebuild what changed
6. **Dependency graph**: Track package relationships
7. **Force full build**: On main branch merges

## Output Checklist

- [ ] Affected detection implemented
- [ ] Turborepo or Nx configured
- [ ] Remote caching enabled
- [ ] Parallel execution optimized
- [ ] Matrix strategy for packages
- [ ] Workspace-aware caching
- [ ] Dependency graph documented
- [ ] Before/after metrics tracked

© patricio0312rev · MIT · patricio0312rev/skills

Similar skills

All skills for DevOps and infrastructure →

From the same set148

The whole set →
deployment-checklist-generator deployment-checklist-generator generates deployment runbooks, pre-release checklists, smoke-test scripts, and post-launch verification plans. CX Codex +1 264installs api-versioning-deprecation-planner The api-versioning-deprecation-planner is a Claude Code skill for planning API version changes and client migrations. It covers releases of a new version while existing clients still rely on the old one. CX Codex +1 264installs state-ux-flow-builder The state-ux-flow-builder skill structures loading, error, empty, and success states for data-driven screens. Use it when a UI flow has several views or state transitions. CX Codex +1 264installs zustand-state-builder zustand-state-builder — a skill for managing app state with Zustand: minimal API, full TypeScript support, persistence, and devtools. Runs on Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, and OpenCode. CX Codex +1 264installs coverage-strategist The coverage-strategist skill helps set test priorities and coverage goals across a project. Use it when deciding which paths need tests and which code can be left out. CX Codex +1 263installs auth-module-builder auth-module-builder lays out a full authentication module: login and registration routes, JWT signing, bcrypt hashing, Redis sessions and a threat model. Useful when the login flow starts from an empty file. CX Codex +1 263installs kubernetes-manifest-generator kubernetes-manifest-generator produces production-grade Kubernetes YAML manifests with hardening, autoscaling, and networking defaults. Useful when preparing workloads for cluster deployment. CX Codex +1 262installs caching-cdn-strategy-planner caching-cdn-strategy-planner is a Claude Code skill for planning CDN and server-side caching, response headers, and invalidation. Use it in API design. CX Codex +1 262installs

Project sponsors

Companies that keep this analytics open