How to Set Up Nx and Turborepo Remote Caching in CI
Nx and Turborepo both hash task inputs and can restore outputs from a shared cache. Wired into CI, that turns a full monorepo build into a handful of changed tasks.
Both tools compute a hash per task from its inputs. A remote cache lets CI reuse outputs produced by any previous run, on any machine, so only genuinely changed tasks execute.
1. Turborepo: set the remote cache token
Turborepo reads TURBO_TOKEN and TURBO_TEAM from the environment and uploads task outputs to the remote cache.
- run: pnpm turbo run build test
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}2. Nx: enable a remote cache
Nx restores cached task outputs automatically once a remote cache is configured. Run only what changed against the base branch.
- run: npx nx affected -t build test --base=origin/main3. Combine with affected detection
Remote caching restores outputs; affected detection skips scheduling untouched tasks entirely. Together they keep PR builds proportional to the diff.
4. Keep cache storage close to the runner
A remote cache only helps if downloading the output is faster than rebuilding it. On Latchkey managed runners the cache lives next to the warm pool, so restores stay fast even for large dist directories.
Key takeaways
- Both tools hash task inputs, so a remote cache makes unchanged tasks free across machines.
- Pair remote caching with affected detection to skip untouched tasks entirely.
- Cache restore only wins when it is faster than the rebuild it replaces.