Back to Guides

caffeinate, pmset and keep-awake apps: what they prevent and what happens when you close the lid

caffeinate, pmset and keep-awake apps: what they prevent and what happens when you close the lid

caffeinate and the macOS power adapter setting prevent idle sleep, but not sleep from closing the lid: a MacBook without an external display goes to sleep when you close it. It only stays awake with a system change such as sudo pmset -a disablesleep 1 or an app that does this for you, an external display (clamshell mode), an HDMI dummy plug, or a lid that does not close fully, for example with a spacer such as WakeClip.

Two kinds of sleep

Apple's older developer document QA1340 separates idle sleep, which starts after a set time without use, from forced sleep, caused by a direct action such as closing the lid. According to Apple, a program can prevent idle sleep but can only delay forced sleep.

The caffeinate options

The Terminal command caffeinate ships with macOS and creates assertions: requests to macOS not to let something sleep for now. Without an option, it prevents idle sleep. With a command after it, this lasts while the command runs, otherwise until caffeinate ends, for example when you press Control-C. The options according to its man page, the built-in manual (man caffeinate):

  • -i prevents idle sleep. caffeinate -i claude starts Claude Code with this protection until the session ends.
  • -d prevents display sleep. According to Apple, the Mac then cannot idle sleep either. Closing the lid can still turn the display off.
  • -m prevents only the disk from idle sleeping, not the Mac.
  • -s prevents system sleep, but according to the man page only on the power adapter. On battery, use -i.
  • -u declares that the user is active. If the display is off, it turns on and does not go into idle sleep. Without -t, this lasts only 5 seconds.
  • -t sets the duration in seconds: caffeinate -i -t 3600 lasts one hour. With a command, -t is not used.
  • -w releases the assertion when the process with the given process ID (PID) exits, for example caffeinate -i -w 4711 for a task that is already running. pgrep -x rsync prints the PID of a running rsync. With a command, -w is ignored.

The man page does not mention the lid for any option. For the assertion behind -i, Apple's developer documentation says that the Mac may still sleep when the lid closes. For -s, neither the man page nor Apple's developer documentation mentions the lid. In practice, caffeinate prevents idle sleep, not sleep from closing the lid.

What is keeping your Mac awake?

According to the man page, pmset -g assertions shows a summary of the assertions that may prevent system or display sleep, and which process holds which. caffeinate -i appears there as PreventUserIdleSystemSleep, -d as PreventUserIdleDisplaySleep and -s as PreventSystemSleep, as Apple's published source code of caffeinate shows.

Many tools keep the Mac awake while they work. If yours is not listed, put caffeinate -i in front of it.

When did your Mac sleep?

According to the man page, pmset -g log displays a history of sleeps, wakes and other power management events. The output is long, with the newest entries at the bottom. Filter it with grep, but not just for "Sleep", because assertion names such as PreventUserIdleSystemSleep contain that word too.

  • pmset -g log | grep -E "Entering Sleep|Wake from" | tail -n 20 shows the last 20 entries about sleep and waking, with time and reason.
  • pmset -g log | grep -E "Clamshell Sleep|Idle Sleep" shows only sleep caused by closing the lid or by inactivity. Apple's published source code lists both as possible sleep reasons. The pmset man page also calls the lid the clamshell.

The man page does not describe these lines, and their wording may change with new macOS versions. Look at a few without a filter first.

The macOS setting

In Apple menu > System Settings > Battery > Options you find "Prevent automatic sleeping on power adapter when the display is off". According to Apple's guide, it stops automatic sleeping while the display is off, and as its name says, only on the power adapter. It does not work on battery or against closing the lid. According to the same guide, you set when an inactive Mac goes to sleep in Lock Screen settings, by choosing when the display turns off.

What disablesleep does

In practice, this system change switches sleep off system-wide, including sleep from closing the lid. According to the man page, -a applies a setting to all power sources, and pmset must run as root, with full system rights, to change settings. So you need sudo and admin rights. disablesleep itself is not listed in the man page on macOS 27.

Reset it yourself with sudo pmset -a disablesleep 0. Otherwise the Mac also stays awake in your bag. A working MacBook does not belong in a bag or sleeve.

Keep-awake apps

Apps such as Amphetamine or KeepingYouAwake keep the Mac awake, some also with the lid closed. According to its README, KeepingYouAwake is built on caffeinate and only prevents sleep with the lid open. According to its Mac App Store description, Amphetamine can keep a MacBook awake with the lid closed and lets you choose per session whether the display may sleep. The lid is then fully closed.

Display, dummy plug or lid spacer

With an external display, keyboard and mouse, you can keep working with the lid closed, as Apple's guides for MacBook Air and MacBook Pro say. An HDMI dummy plug makes the Mac see a display.

A lid spacer works mechanically. WakeClip keeps the lid 12 mm open. Your MacBook does not go to sleep from closing the lid, and whatever is running keeps running. Unlike a fully closed lid, there is air above the keyboard, and heat can escape.

  • Made for carrying in your hand, not for the bag. Remove the clip before you stow the MacBook, and close it normally.
  • Idle sleep is still handled by your Mac's settings or the running program, with caffeinate -i if needed.

Everything at a glance

Tool or method Prevents idle sleep Prevents display sleep Prevents lid-close sleep Needs admin rights Must be reset
caffeinate -i Yes No No No No
caffeinate -d Yes Yes No No No
caffeinate -s Only when plugged in No No No No
Setting under Battery > Options Only when plugged in No No Apple does not say No, but it stays on
sudo pmset -a disablesleep 1 Yes Not documented Yes Yes Yes, with sudo pmset -a disablesleep 0
Keep-awake apps Yes Depends on the app Amphetamine yes, KeepingYouAwake no Depends on the app End the session or feature
External display or HDMI dummy plug No No Yes, on power No No, just unplug it
Lid spacer such as WakeClip No No, but closing the lid does not turn it off Yes, mechanically No No, remove it before stowing

For which way suits which situation, see Keep a MacBook awake with the lid closed: 7 ways compared. For long runs with an AI agent, see Claude Code stops when you close your MacBook. WakeClip is an independent accessory and is not affiliated with Apple, Anthropic or OpenAI.