Long builds, data migrations, and background scripts stall out if macOS drops into sleep mid-run. Both the built-in caffeinate command and the free menu bar app Amphetamine prevent unwanted sleep, though each fits different workflows.

Terminal-Native Control with caffeinate

caffeinate ships with macOS and runs straight from the terminal with zero setup. Core flags block display sleep (-d), system idle sleep (-i), disk idle sleep (-m), AC-power sleep (-s), or declare active user presence (-u). Combining a timeout (-t 3600) or process watch (-w PID) keeps the Mac awake only until a target job finishes.

Wrapping a command directly is straightforward: caffeinate -i npm run build blocks idle sleep for the exact duration of the build. Running caffeinate -i -s on wall power lets the display turn off while keeping background compute alive.

Amphetamine lives in the macOS menu bar and adds rich conditional triggers without touching the terminal. Sessions can start automatically on schedules, when specific apps launch, or while downloads remain active, as well as on environment signals like Wi-Fi SSIDs, Bluetooth devices, or battery thresholds.

Its Drive Keep Alive feature writes tiny periodic heartbeats so external drives do not spin down, and an optional cursor jiggler prevents corporate screen-lock timers from interrupting monitoring views. When sleep rules depend on changing hardware or network state, GUI triggers beat shell wrappers.

Closed-Clamshell Differences and Thermal Caution

Behavior diverges sharply when you close the MacBook lid. On stock macOS, caffeinate -i alone cannot stop hardware sleep the moment the lid closes unless AC power, an external display, and an input device are all attached.

Amphetamine can override closed-display sleep in its session settings, keeping local servers or render jobs running with the lid shut and no external monitor plugged in. Just avoid running heavy CPU or GPU loads inside an enclosed backpack or sleeve, where trapped heat can throttle or damage hardware.

Reach for caffeinate on one-off terminal commands, and pair it with Amphetamine when you need conditional triggers or headless closed-lid operation.

Summary

  • caffeinate wraps terminal commands or PIDs with zero install to block idle sleep during builds and scripts
  • Amphetamine automates awake sessions around Wi-Fi networks, Bluetooth devices, battery levels, and screen-lock prevention
  • Running a MacBook with the lid closed and no external monitor requires Amphetamine’s closed-display override rather than caffeinate alone