How to keep your Mac awake
caffeinate -i in Terminal keeps your Mac awake until you press Ctrl+C. Add -d to keep the screen on too, -t 3600 for an hour, or -w <pid> to stay up exactly as long as a process runs. Here’s the full set, plus the settings and apps that do it without Terminal.
Updated
caffeinate: built into macOS
caffeinate holds a power assertion for as long as it runs. No install, no settings to undo afterwards.
caffeinate -i # keep the Mac awake until Ctrl+C (screen can sleep)
caffeinate -d # keep the screen on too
caffeinate -i -t 7200 # for 2 hours (time in seconds)
caffeinate -i -w 48211 # until process 48211 exits
caffeinate -i npm run build # for as long as this command runs
| Flag | What it prevents |
|---|---|
-i | Idle system sleep. The usual choice |
-d | Display sleep (which also keeps the Mac awake) |
-s | System sleep, but only while on the power adapter |
-m | Disk idle sleep |
-u | Declares user activity: wakes the display, stays for 5 seconds unless you add -t |
-t <sec> | Timeout for the assertion |
-w <pid> | Wait for that process to exit, then release |
With no flags, caffeinate behaves like -i.
The two most useful forms
Wrap the command. If you run a long job from Terminal, put caffeinate -i in front. The Mac stays awake for exactly that job and is free to sleep the moment it ends, even if it fails:
caffeinate -i ./scripts/migrate.sh
caffeinate -i rsync -a ~/Projects /Volumes/Backup/
Attach to something already running. If a download, render or agent session is already going, find its PID and wait on it:
pgrep -l Xcode
caffeinate -i -w 23104 & disown
& disown runs it in the background and detaches it from the shell, so it keeps going after you close the tab.
The System Settings way
For a permanent change rather than a one-off:
- System Settings › Lock Screen: set “Turn display off on power adapter when inactive” to a longer time or Never.
- System Settings › Battery › Options (laptops): turn on “Prevent automatic sleeping on power adapter when the display is off”. On a desktop Mac this is under Energy.
This works, but it’s easy to forget you changed it, and then you’re back on our why won’t my Mac sleep page wondering why the battery drained overnight. A timed assertion is usually better.
Menu bar apps
If you’d rather click than type:
- Amphetamine (free, Mac App Store): sessions by time, until an app quits, while a file downloads, plus triggers. Very configurable. See our Amphetamine comparison.
- KeepingYouAwake (free, open source): a one-click cup icon that runs
caffeinatefor a duration. Simple and small. Compared in KeepingYouAwake alternative. - Stat Space: keep-awake timers alongside a system monitor (below).
What doesn’t work
- Moving the mouse with a jiggler app. It resets the idle timer but also keeps the screen on and unlocked. An assertion is cleaner and safer.
- Setting sleep to Never with
sudo pmset -a sleep 0. It works, permanently, until you remember to undo it. - Closing the lid. Covered separately in keeping a Mac awake with the lid closed, because the rules are different.
Check it’s working
pmset -g assertions | grep -i caffeinate
If you see your caffeinate with PreventUserIdleSystemSleep (or ...DisplaySleep with -d), the Mac won’t idle-sleep.
Doing this with Stat Space
Stat Space’s Awake tab and menu bar cup icon start a timer in one click: 15 minutes, 1 hour, until a time, or indefinitely, for the system only or system and display. Condition timers cover the cases people use -w for: until a download finishes, while on the charger, or until a terminal task exits. The tab always says why the Mac is awake, for example “Awake 1h 23m · because Vite on :5173”, and lists any other app blocking sleep. Timers are free; rules that switch on automatically (while an app or port runs, on a schedule, with an external display) are Pro.
From the terminal: statspace awake 2h, statspace awake forever --display, statspace awake off. Agents can call the same thing over MCP. See Keep awake.
Questions
Does caffeinate work with the lid closed?
Not reliably. Closing a MacBook’s lid puts it to sleep whatever caffeinate is doing, unless it’s in clamshell mode with power and an external display. See our guide to keeping a Mac awake with the lid closed.
Does keeping my Mac awake hurt the battery?
It drains it faster, because the Mac never enters low-power sleep. Use -i instead of -d so the screen can turn off, and set a time limit with -t on battery.
How do I stop caffeinate running in the background?
Press Ctrl+C in its terminal, or find it with pgrep -l caffeinate and run kill <pid>. pmset -g assertions also lists it by PID.
Will my Mac still lock while it’s kept awake?
With -i, yes: the display sleeps and the screen locks on its normal schedule. With -d, the display stays on, so it usually won’t lock on idle. Press Control-Command-Q to lock it yourself.
Know what your Mac is doing, without adding to it.
Free, no account. Pro is $9.99 once for the first 100 buyers.