caffeinate with the lid closed: why it stops, and what works

caffeinate is free, safe and already on your Mac. It also stops at exactly one place: the lid.

Updated · by Sasha Yakovlev, maker of Lidwork

Quick answer

If your lid stays open, use caffeinate -i: it's built in, needs no password and reverts automatically. If you close a MacBook's lid without an external display, caffeinate can't keep it awake; Lidwork can, and it restores normal sleep if it crashes or your battery hits 10/20/30%.

At a glance (as of Oct 2026)

Lidworkcaffeinate
Idle sleepPreventedPrevented (-i)
Lid closed, no monitorYesNo — the Mac sleeps on lid close
PasswordNoneNone
If it crashesBackground part turns lid sleep back on: at once after a crash, within 30 s after a hangNothing to restore — the assertion ends with the process
Battery cutoff10 / 20 / 30%, on in every sessionNo (use -t for a time limit)
InterfaceMenu-bar starTerminal
Price$9.99 once, Mac App StoreFree, built into macOS

Why caffeinate stops at the lid

Try it: run caffeinate -dimsu on battery, start a download, close the lid. Within seconds the Mac is asleep and the download stops. caffeinate creates power assertions that block idle sleep. Closing a MacBook's lid without an external display is a separate, explicit sleep path, and macOS sleeps anyway. The only built-in override is the global pmset disablesleep switch, which caffeinate doesn't touch — and which, unlike caffeinate, doesn't turn itself off. Full details: caffeinate on Mac, every flag explained.

On battery it is even stricter

caffeinate -s only works on AC power, and Apple's own closed-display mode needs a charger plus an external display and keyboard. Unplugged, with nothing attached, no caffeinate flag and no Energy setting keeps a closed MacBook running. That is the case Lidwork exists for: it keeps a closed MacBook awake on battery, stops at the battery level you choose (10, 20 or 30%) or when the Mac gets too hot, and if Lidwork quits or crashes, its background part turns its lid hold off so normal sleep comes back.

Use caffeinate when…

  • The lid stays open, or it's a desktop Mac.
  • You want “awake while this command runs”: caffeinate -i ./job.sh is perfect.
  • You live in Terminal anyway. Our command builder writes the flags for you.

Use Lidwork when…

  • You close the lid and leave — commute, meeting, bag.
  • You'd otherwise use sudo pmset -a disablesleep 1 and might forget the undo.
  • You want a battery floor and a background part that turns sleep back on if the app crashes.

Using both

They don't conflict. A good pattern for agents and builds: caffeinate -i for the job while you're at the desk, Lidwork switched on only for the part where the lid is closed.

FAQ

Does caffeinate work with the lid closed?

Not on a MacBook without an external display. caffeinate blocks idle sleep; closing the lid is a separate sleep request that macOS honours anyway, on battery and on power.

Does caffeinate -s keep a closed MacBook awake on the charger?

No. -s blocks system idle sleep while on AC power, but lid-close sleep still happens unless the Mac is in Apple's closed-display mode (charger, external display and keyboard).

Which caffeinate flag keeps the Mac awake with the lid closed on battery?

None of them. -d, -i, -m, -s and -u all act on idle sleep. Only the global sudo pmset -a disablesleep 1 switch, or an app that manages lid sleep, keeps a closed MacBook awake on battery.

Is there a free alternative?

Yes: sudo pmset -a disablesleep 1, then sudo pmset -a disablesleep 0 when you are done. It does not turn itself off, so a forgotten undo leaves the Mac awake until the battery is empty.