Stop your Mac sleeping during a long build
A clean Xcode build, a cold cargo compile, an npm install that has to fetch the world — these routinely run longer than the macOS idle sleep timer. Walk away, the Mac sleeps, and you come back to a build that stalled partway. Here is how to stop a Mac sleeping during a build without just disabling sleep and hoping for the best.
Why a build dies when you step away
The idle sleep timer does not know what a build is. It watches input and screen activity, not whether clang is halfway through a translation unit. A 40-minute cargo build with no keystrokes looks exactly like an idle machine, so macOS does the responsible thing and sleeps.
When it sleeps mid-build, the work pauses where it stood. Nothing is corrupted, but the compiler is frozen, and any incremental cache that was warming up stops warming. You wake the Mac, the build resumes or restarts, and the wait you thought was nearly over starts again.
It is most annoying on the long, quiet jobs: a full Xcode archive, a fresh node_modules, a release cargo build with optimizations on. Exactly the builds you most want to start and ignore are the ones the idle timer is most likely to interrupt.
Two ways to keep the build awake
The first way is hands-off. LidRun's Auto Mode watches for the dev tools you tell it about — by process name, or by command line for interpreters like node and python — and holds the Mac awake while they are actually working. A process only counts as active when its CPU is above a threshold, so an idle Terminal does not keep the Mac up; a compiler pegging a core does. A short holdoff keeps the assertion alive for a few seconds past the last busy sample so a brief lull between build phases does not drop the lock.
The second way is explicit. Wrap the build with lidrun -- <your build command> and LidRun holds a keep-awake assertion for exactly that command's lifetime, then releases it the moment the command exits. You get the exit code and duration back, so a script can tell whether the build passed. It is the cleanest fit for CI-style one-shots and overnight scripts where you know the command up front.
Auto Mode is better when builds come and go all day; the lidrun -- wrapper is better when you have one specific long command to babysit. Both end the keep-awake when the work ends, rather than leaving the Mac pinned awake indefinitely.
Related guideKeep your Mac awake only while it's actually workingThe safety governor still applies
Keeping a Mac awake for a long build is the easy part. Doing it without quietly cooking the battery or the chassis is the part worth getting right, and it is why LidRun does not just flip sleep off and walk away.
Every keep-awake decision is gated on battery level, thermal state, and whether you are on AC or running unattended. A heavy release build can push a fan-limited laptop warm; if thermal pressure climbs too high, or charge drops past the threshold you set, LidRun lets the Mac sleep instead of pushing the hardware. This helps reduce risk — it does not make overheating impossible, and airflow is still on you.
Those decisions get recorded in the Activity Log, so if a long build was cut short by a thermal or battery limit you can see why rather than guessing. A session timer of one, three, or eight hours also caps any run, so a build that hangs forever does not keep the Mac awake all night.
Setting it up for everyday builds
Run the Mac on a hard, flat surface with airflow underneath while a long build runs. A heavy compile generates real heat; a bed or a closed bag traps it, and no software setting changes that.
For the heaviest jobs — a full clean build, a big LTO pass — stay on power if you can. On battery LidRun will still keep the build awake, but mains power removes the drain question and lets the run finish without the battery floor stepping in.
If your builds run inside containers, the same idle-sleep problem applies there too; the Docker-build angle is covered separately. For native toolchains — Xcode, npm or pnpm, cargo, make — Auto Mode plus the lidrun -- wrapper covers almost everything you will hit day to day.
LidRun keeps your work running with the lid closed, with battery and thermal safety built in.
Frequently asked
No. With lidrun -- <command> the assertion is released the moment the command exits. In Auto Mode, once no watched process is busy above the CPU threshold (past the holdoff), LidRun lets the Mac sleep again.
It detects the dev tools you configure, by process name or by command line for interpreters. A process only counts as active when its CPU is above a threshold, so a real compile keeps the Mac awake while an idle shell does not.
If thermal pressure climbs too high, LidRun lets the Mac sleep rather than pushing the hardware, and records the decision. That helps reduce risk, but it cannot guarantee a Mac never overheats — placement and airflow are still your responsibility.
Yes, within the battery floor you set. When charge drops past that threshold LidRun ends the session cleanly instead of draining to zero. For the heaviest builds, staying on power is still the safer call.