Skip to content

Guide

How to keep your Mac awake during a build

macOS sleeps an idle Mac even while a long build or download is running in Terminal. `caffeinate`, which comes with macOS, keeps it awake for exactly as long as the task takes.

By the iKnowMyMac team · Updated · 5 min read

The short answer

Put caffeinate -i in front of the command: caffeinate -i make build keeps the Mac from idle sleeping until the build finishes, then lets it sleep normally. Use caffeinate -i -w <pid> to wait for a process that is already running, or caffeinate -i -t 3600 for a set time. Check it with pmset -g assertions. Closing a MacBook's lid still puts it to sleep unless it's in clamshell mode with power and an external display.

On this page

Wrap the command with caffeinate

Stay awake until the build ends
caffeinate -i xcodebuild -scheme App build

caffeinate holds a power assertion while the command runs and releases it when the command exits, so you never forget to turn it off. -i prevents idle sleep; the display can still turn off, which saves power.

  • -i

    What it does
    Prevent idle system sleep. The usual choice for builds and downloads
  • -d

    What it does
    Keep the display on too, for a dashboard you're watching
  • -s

    What it does
    Prevent system sleep, only while on AC power
  • -t <seconds>

    What it does
    Stay awake for a set time
  • -w <pid>

    What it does
    Stay awake until the process with this ID exits
The caffeinate options you'll use

For a task that's already running

Find the process ID, then wait for it
pgrep -n node
caffeinate -i -w 48213

Check that it worked

Power assertions, by process
pmset -g assertions | grep -A1 caffeinate

caffeinate appears under Listed by owning process with PreventUserIdleSystemSleep while it's active. See sleep assertion for the other types.

What a closed lid does

Closing a MacBook's lid puts it to sleep whatever caffeinate says, unless the Mac is connected to power and an external display (clamshell mode). Leave the lid open for long builds on battery, and turn the display brightness down instead.

The faster way: Keep awake in iKnowMyMac

Know why your Mac is slow.

macOS 15 Sequoia or later · Apple silicon. A 4.2 MB native app, notarized by Apple. No account, no analytics, no telemetry.

One-time purchase · every feature · 14-day refund