Sleep and power
Keep a Mac awake from Terminal with caffeinate
The caffeinate command stops a Mac from sleeping while a task runs. It is part of macOS and changes no settings.
Symptoms
- A download, build or script stops when the Mac goes to sleep.
- A remote session or SSH connection drops after some minutes with no input.
- You want the Mac to stay awake for one task, but you do not want to change the sleep settings.
Likely causes
- Idle sleep. macOS puts the Mac to sleep after a time with no keyboard or mouse input. Network activity alone does not always stop this.
- Display sleep. The display turns off on its own timer. On some Macs, the system then sleeps too.
- The lid. Closing the lid of a Mac laptop puts it to sleep.
caffeinatedoes not change this. See Keep a Mac laptop working with the lid closed.
How to check
Open Terminal. See which processes now prevent sleep.
pmset -g assertionsOutput A list of assertions such as
PreventUserIdleSystemSleep, with the process that holds each one.See the sleep settings that are in use now.
pmset -g
How to fix it
To keep the Mac awake while one command runs, put
caffeinate -ibefore the command. The assertion stops when the command stops.caffeinate -i makeTo keep the Mac awake for a fixed time, give the time in seconds with
-t. This example is two hours.caffeinate -i -t 7200To keep the Mac awake until a process stops, give its process ID with
-w.caffeinate -i -w 12345To keep the display on too, add
-d.caffeinate -d -iTo stop
caffeinatethat you started with no command, press Control-C.To stop automatic sleep while the display is off, change the setting. On a Mac laptop, choose Apple menu > System Settings > Battery > Options. Turn on “Prevent automatic sleeping on power adapter when the display is off”.
On a Mac desktop, choose Apple menu > System Settings > Energy. Turn on “Prevent automatic sleeping when the display is off”.
With Kilobat
Kilobat can keep the Mac awake until a download goes quiet, then let it sleep. Open Kilobat from the menu bar. Click the teacup and choose Until Downloads Finish.
The CLI does the same. It stops after 3 minutes below 16 KB/s.
kilobat awake --until-quietTo keep the Mac awake while one command runs, and to see the data it moved, use
awake --.kilobat awake -- make releaseThese features are free. See the recipe for the app, CLI and MCP steps.
Questions
Does caffeinate keep the Mac awake with the lid closed?
No. caffeinate stops idle sleep. Closing the lid still puts a Mac laptop to sleep, unless the Mac uses an external display, keyboard and power. See Keep a Mac laptop working with the lid closed.
What does the -s option do?
-s stops system sleep. The man page says that it works only when the Mac is on AC power.
Does caffeinate change my settings?
No. It creates power assertions. They stop when caffeinate stops.
Sources
- caffeinate(8), man page installed with macOS 27.2
- pmset(1), man page installed with macOS 27.2
- Apple Support: Set sleep and wake settings for your Mac
Sources checked on 29 October 2026. Man pages are the ones installed with macOS; open one with man <name> in Terminal.