caffeinate is a built-in macOS Terminal command that keeps your Mac from sleeping for as long as it runs, with no sudo and no saved settings to change, but Apple's own documentation says your Mac can still sleep when you close the lid (and its -s flag only applies on AC power). If a job needs to keep running after you close your MacBook lid on battery or power, Clamshell for Mac keeps a closed Apple Silicon MacBook awake from the menu bar with no admin password and nothing to undo, for $9.99 once after a 7-day free trial.
Written by Matyas Rathonyi, the maker of Clamshell for Mac.
caffeinate prints nothing while it runs. pmset -g assertions shows the assertion it holds and how long it lasts. (Lines condensed from our run.)What caffeinate does
/usr/bin/caffeinate ships with macOS, needs no install, and runs without sudo. Apple's caffeinate(8) manual describes it as "prevent the system from sleeping on behalf of a utility."
While running, caffeinate holds one or more power assertions in memory and prints nothing to Terminal. Per Apple's manual, those assertions end automatically when caffeinate exits, when its -t timer expires, or when the command you pass to it finishes.
Every caffeinate flag explained
Here is what each flag in man caffeinate does and the power assertion pmset -g assertions shows for it:
| Flag | What it stops | Assertion | Limit |
|---|---|---|---|
| (none) | Idle system sleep (same as -i) | PreventUserIdleSystemSleep | Lid close can still sleep Mac |
-d | Display sleep and idle system sleep | PreventUserIdleDisplaySleep | Lid close can still sleep display |
-i | Idle system sleep (display may dim) | PreventUserIdleSystemSleep | Lid close can still sleep Mac |
-m | Disk idle sleep | PreventDiskIdle | System can still sleep |
-s | System sleep on AC power | PreventSystemSleep | AC power only, not battery |
-u | Wakes display, marks user active | UserIsActive | 5-second timeout without -t |
-t seconds | Drops assertion after N seconds | Same, asserting for N secs | Ignored when wrapping a command |
-w PID | Holds until process ID exits | Same, asserting on behalf of Process ID N | Ignored when wrapping a command |
Four details are easy to miss:
- Combine flags freely. Use
-dito keep both the screen and system awake, or-dimsto hold all four sleep assertions at once. -dalso blocks idle system sleep. Apple'sIOPMLib.hheader says: "While the display is prevented from dimming, the system cannot go into idle sleep."-udrops after 5 seconds without-t. Apple's manual says-uturns the display on if it is off and takes a default 5-second timeout when-tis omitted; the assertion expires even while thecaffeinateprocess stays running.-mworks despite the synopsis.man caffeinateomits-mfrom its synopsis line (caffeinate [-disu]), though-mis listed under Available options and holdsPreventDiskIdle. Passing a nonexistent PID to-wmakescaffeinateexit right away with status 0.
To assemble a command with a picker, use the pmset and caffeinate command builder.
Ready-to-use caffeinate commands
Every command below runs without sudo:
Keep your Mac out of idle sleep until you stop it (bare, or with -i explicit):
caffeinate
caffeinate -i
Keep your Mac awake for 1 hour (3600 seconds) or 2 hours (7200 seconds):
caffeinate -i -t 3600
caffeinate -i -t 7200
Keep the screen lit as well (caffeinate -d alone also works):
caffeinate -di
Block system sleep on AC power:
caffeinate -s
Hold all four assertions at once (display, idle, disk, and AC system sleep):
caffeinate -dims
Wake the display and mark the user active for 5 seconds:
caffeinate -u
Keep your Mac awake only while one command runs (Apple's manual example; replace make with your command; caffeinate passes the command's exit code through):
caffeinate -i make
Wrap a chain of commands using sh -c '...' so caffeinate tracks the whole sequence:
caffeinate -i sh -c 'sleep 1 && echo step1 && sleep 1 && echo step2'
Wait until an already-running process ends (replace <PID> with the process ID):
caffeinate -i -w <PID>
How to check and stop caffeinate
Because caffeinate prints nothing while active, check it from another Terminal tab with:
pmset -g assertions | grep caffeinate
Each line prints the PID, assertion type, and whether caffeinate is asserting forever, counting down a timeout, or holding on behalf of a command or PID. See pmset -g explained to read the rest of the output.
To stop caffeinate and release its assertions immediately:
- In the same Terminal tab: press Control-C (
SIGINT, exit status 130). - Automatically: let the
-ttimer finish (exit 0), wait for the wrapped command to exit, or wait for the-wprocess to end. - From another Terminal tab: find its PID with
pmset -g assertions | grep caffeinateand stop that specific process withkilland its PID (SIGTERM, exit 143). Avoidkillall caffeinatebecause it stops every runningcaffeinateprocess, including ones started by other tools. - Closing the Terminal window: sends
SIGHUPto its shell and child processes, endingcaffeinate(exit 129) and releasing its assertion.
Where caffeinate stops: closing the lid
caffeinate is built to prevent idle sleep while your lid stays open. Apple's IOPMLib.h SDK header states for PreventUserIdleSystemSleep (bare caffeinate and -i): "The system may still sleep for lid close, Apple menu, low battery, or other sleep reasons." For PreventUserIdleDisplaySleep (-d), it notes: "the display may still sleep for other reasons, like a user closing a portable's lid or the machine sleeping."
What about caffeinate -s? Apple's manual limits -s to AC power: "This assertion is valid only when system is running on AC power." On battery, -s does not apply at all, and the manual says nothing about a closed lid.
The built-in closed-lid alternatives ask for extra hardware or admin access. Apple's closed-display mode requires a charger plus an external monitor, keyboard, and mouse. Running sudo pmset -a disablesleep 1 asks for an admin password and turns sleep off until you undo it by hand.
Why pay $9.99 once for Clamshell when caffeinate is free? caffeinate is built for an open lid and stops protecting you once you close the lid on battery, while Clamshell handles a closed lid on battery or power with no sudo, nothing to undo, and built-in heat and battery cut-offs.
- Works with the lid closed, on battery or power. Close your Apple Silicon MacBook with no external monitor attached; the built-in display stays off while builds, scripts, downloads, or SSH sessions keep running.
- No
sudo, no admin password, and nothing to undo. Arm Clamshell from the menu bar, by pressing both Option keys, or from a script using its URL scheme (open "clamshell://arm"andopen "clamshell://disarm"). Normal lid sleep returns when you disarm or quit. - Always-on heat cut-off and 20% battery floor. Thermal safety stays on at all times and disarms Clamshell toward normal sleep if your Mac gets too hot. Low-battery stop at 20% is on by default.
- Notarized and installable with Homebrew. Install by direct download, via Setapp, or with
brew install --cask clamshellon Apple Silicon Macs running macOS 14 or later.
Test it on your Mac before paying anything: Download free trial (free for 7 days, no card required; $9.99 once for 1 Mac or $19.99 for up to 3 Macs, with a 14-day money-back guarantee). For more on closing the lid, see does caffeinate work with a MacBook lid closed and how to keep a Mac running with the lid closed.
When caffeinate is the better pick
- Your lid stays open, or you use a desktop Mac.
caffeinateis free, built into/usr/bin/caffeinate, and wraps a single command cleanly with zero setup. - You use an Intel Mac or macOS 13 or earlier. Clamshell requires an Apple Silicon MacBook on macOS 14 or later, while
caffeinateships on every Mac.
Frequently asked questions
What does caffeinate -i do?
caffeinate -i holds a PreventUserIdleSystemSleep assertion that blocks idle sleep while still letting the display dim and sleep. It lasts until you press Control-C, a -t timer expires, or the command or -w process finishes, so use it for lid-open terminal jobs.
What is caffeinate -dims?
caffeinate -dims combines -d (display sleep), -i (idle system sleep), -m (disk idle sleep), and -s (system sleep on AC power only) in one command. Use it on a plugged-in Mac with the lid open when you want the screen, disk, and system to stay awake together.
How do I caffeinate my Mac for 1 hour or 2 hours?
Run caffeinate -i -t 3600 for 1 hour or caffeinate -i -t 7200 for 2 hours, since -t takes seconds. Swap -i for -di if you also want the screen to stay lit.
How do I stop caffeinate on a Mac?
Press Control-C in the Terminal tab where caffeinate is running. If it is running in another tab or in the background, find its PID with pmset -g assertions | grep caffeinate and stop it with kill followed by that PID.
Does caffeinate work with the lid closed?
Not reliably for general use: Apple's SDK header says the Mac may still sleep for lid close under bare caffeinate and -i, and that the display still sleeps on lid close under -d, and Apple's manual limits -s to AC power. If you want a closed Apple Silicon MacBook to stay awake on battery or power without sudo, start Clamshell's 7-day free trial instead.
What is the difference between caffeinate and pmset?
caffeinate needs no sudo and releases its hold automatically when it exits, while modifying power settings with pmset requires root and saves changes until you revert them. Use caffeinate for temporary lid-open jobs, pmset -g explained to inspect power settings, and Clamshell if you want closed-lid awake control with no admin rights.
Related guides
- How to prevent your Mac from sleeping
- pmset -g explained: what each line of the output means
- Does caffeinate work with a MacBook lid closed?
- How to keep a Mac running with the lid closed
Try Clamshell free for 7 days
Keep your Apple Silicon MacBook running with the lid closed, on battery or power, with no admin password, an always-on heat cut-off, and a 20% battery floor. Normal lid sleep returns when you disarm or quit.
$9.99 for 1 Mac, $19.99 for up to 3 Macs. 7-day free trial with no card required and a 14-day money-back guarantee. Apple Silicon, macOS 14 or later, notarized by Apple. Also available via Homebrew or Setapp.
Sources checked November 23, 2026: macOS 27.2.1 caffeinate(8) manual (footer dated November 9, 2012), Apple's IOPMLib.h header from the macOS 27.0 SDK, and command checks run without sudo on macOS 27.2.1. Clamshell details come from version 2.0.5. Clamshell is an independent app, not affiliated with or endorsed by Apple. Product names belong to their respective owners.