The flag that didn't speed up our CI
We cut a monorepo's PR build step from 200 seconds to 1.2 with Nx's local cache and GitHub Actions. The env var I credited for it turned out to be dead on arrival.
- ci
- nx
- monorepo
Today I opened a PR that deletes one line from our CI config:
env:
NX_REJECT_UNKNOWN_LOCAL_CACHE: '0'Five months ago I would have told you that line was the reason our pull request checks stopped taking forever. It turns out it had been doing nothing since the day it shipped. Here's the whole story, including the part that actually worked.

The problem
Our monorepo is an Nx workspace: a few deployable apps, about forty library packages underneath them, and seven example projects. The Check PR workflow runs on every push and has a handful of jobs: build the libraries, run the tests, build and deploy the apps to a preview, build the examples.
A normal run took around fifteen minutes. The bad ones took fifty, or died.
Two things were wrong.
- Every job built from scratch.
build-libsbuilt all the libraries. Thendeployrannx run-manyon the apps, and because the apps depend on nearly every library, Nx built the whole dependency tree again on a fresh runner. Same code, same output, twice. - The examples job built all seven at once. Seven bundlers on one runner meant swap thrashing, 20-minute runs, and the occasional out-of-memory kill.
What Nx Cloud would have done
Nx already caches task outputs locally. Run nx build foo twice and the second run replays from .nx/cache in about a second. The problem on CI is that every job is a new machine, so that local cache is empty every time.
Nx's answer is Nx Cloud: a remote cache shared by every runner and every developer. It's good. It's also a paid service, and I wanted to see how far I could get without it.
The fix
The idea is simple: use GitHub's own cache as the shared drive for Nx's local cache.

1. Make the build target cacheable in nx.json, and tell Nx where the outputs land:
"build": {
"cache": true,
"outputs": ["{projectRoot}/dist"]
}2. Persist both cache folders with actions/cache in the job that builds the libraries. .nx/cache holds the task outputs. .nx/workspace-data holds the database that indexes them. Cache one without the other and Nx won't recognise anything.
- uses: actions/cache@v4
with:
path: |
.nx/cache
.nx/workspace-data
key: ${{ runner.os }}-nx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-nx-Keying on the commit SHA means a downstream job in the same run gets an exact hit. The restore-keys fallback means the next push to the PR starts from the most recent cache instead of from nothing.
3. Restore read-only in downstream jobs. deploy uses actions/cache/restore with the same key and fallback. It never writes, so it can't race with the job that does.
For the examples I capped the fan-out with concurrently --max-processes 3 and gave each build a --max-old-space-size=4096 heap, so three bundlers share the runner instead of seven fighting over it.
Numbers
Measured from the Actions logs on a warm cache:
build-libs build step 200s → 1.2s
build-libs whole job ~240s → 58s
deploy client build 232s → 35s
deploy whole job ~230s → 92sThe build step going from 200 seconds to 1.2 is Nx replaying forty unchanged libraries from cache. The deploy job now compiles exactly three apps, the ones that actually ship.
The whole workflow's median didn't move as much, because other jobs run in parallel and set the wall time. What disappeared was the tail. In the weeks before the change, the worst runs took 46, 88 and 95 minutes. After it, the worst runs mostly sit under 20.
The flag
Now, the line I deleted.
When I first tried this, our workspace was on Nx 16. Nx 16's cache was file-based, and it refused to use any artifact created on a different machine. Restore the cache on a new runner and you'd get an "Unrecognized Cache Artifacts" error and a full rebuild. The escape hatch was NX_REJECT_UNKNOWN_LOCAL_CACHE=0.
Nx's docs are blunt about it. They compare it to NODE_TLS_REJECT_UNAUTHORIZED=0, and they're right to. The scenario they're worried about is a shared network drive, where every CI run can read and overwrite every previous artifact. If someone poisons one cached output, every machine downstream replays it. The flag turns off the only check that would have noticed.
I was comfortable with it on GitHub Actions because that cache isn't a network drive. Entries are immutable once written, scoped to the branch, and only our own workflow runs write them. Still, I had turned off a safety check, and I wrote it up as a caveat in the PR.
Then two things happened. Nx 20 replaced the file cache with a database-backed one that recognises artifacts from other machines on its own, and Nx 21 removed the old cache entirely. Somewhere in between, our workspace jumped from Nx 16 to Nx 22.
So by the time my speedup PR merged, the flag was already dead. Nx 22 ignores it and prints a warning on every run pointing at the deprecation page. The cache sharing worked anyway, because the database cache does what the flag used to force, without disabling anything.
I only noticed because the warning finally annoyed me enough to read it.
What I'd tell you to do
If you're on Nx 21 or later, you don't need the flag and shouldn't set it. Cache .nx/cache and .nx/workspace-data together, mark your targets cacheable, key on the SHA with a prefix fallback, and restore read-only downstream. That's the whole thing.
If you want a real remote cache without Nx Cloud, Nx has shipped free self-hosted cache plugins for S3, GCS, Azure and shared filesystems since early 2025. I haven't needed them yet. A few lines of actions/cache got us to a 1.2 second build step.
And read your CI warnings. The one I ignored for five months was telling me that the flag which had been my fix on Nx 16 had retired before the PR even merged.