caffeinate

Why caffeinate does not keep your MacBook awake with the lid closed

caffeinate only holds power assertions, and a MacBook with no external display still sleeps when the lid closes. What works from Terminal instead.

Short answer: caffeinate only creates power assertions, and Apple documents that a Mac may still sleep for lid close while they are held. On a MacBook with no external display, closing the lid is a sleep request that no caffeinate flag overrides, not even caffeinate -s. From Terminal, sudo pmset disablesleep 1 keeps it awake with the lid closed but stays on until you undo it; keepmacawake start --hours 8 does the same for one session and puts the setting back itself.

What does caffeinate actually do?

caffeinate asks macOS not to sleep by holding power assertions for as long as it runs. The man page: "caffeinate creates assertions to alter system sleep behavior." Without flags it prevents idle sleep only.

The flags, quoted from man caffeinate on macOS (checked in October 2026):

  • -d: "prevent the display from sleeping."
  • -i: "prevent the system from idle sleeping." This is also the default.
  • -m: "prevent the disk from idle sleeping."
  • -s: "prevent the system from sleeping. This assertion is valid only when system is running on AC power."
  • -u: "declare that user is active", with a 5 second timeout unless you set -t.
  • -t: the timeout in seconds, after which "the assertion is dropped."
  • -w: waits for the process with that PID to exit, then releases the assertion.

With a command, as in caffeinate -i make, the assertions last while that command runs. Any process may create an assertion, so caffeinate needs no sudo (IOPMLib.h).

Why does closing the lid still put the Mac to sleep?

Closing the lid is forced sleep, and assertions only guard against idle sleep. Apple's note QA1340: "Closing the lid on a laptop or selecting sleep from the Apple menu both cause forced sleep" (QA1340).

Apple's documentation and source cover each assertion caffeinate uses:

  • Idle sleep (-i): "The system may still sleep for lid close, Apple menu, low battery, or other sleep reasons" (Apple developer docs).
  • Display (-d): "the display may still sleep from other reasons, like a user closing a portable's lid or the machine sleeping" (Apple developer docs).
  • System (-s): assertions "are just suggestions to the OS" (Apple developer docs). In Apple's published power management source, an assertion counts against lid-close sleep only with a private property, such as AppliesOnLidClose, that needs an Apple-internal entitlement (PMAssertions.c). The caffeinate source sets none (caffeinate.c).

The same limit shows up in other tools' keep-awake options. As of October 2026, Anthropic's docs say the Claude desktop app's Keep computer awake prevents idle sleep, and "Closing the laptop lid still puts it to sleep" (Claude Code docs). More in how to keep Claude Code running with the lid closed.

With an external display, keyboard, mouse and power connected, Apple's closed-display mode keeps the Mac running with the lid closed anyway; see clamshell mode without an external monitor for what changes without the display.

Which commands cover a closed lid?

Of the options below, only the two that change the system-wide SleepDisabled setting keep a MacBook awake with the lid closed and no display. The rest cover idle sleep.

Command or settingStops idle sleepLid closed, no displayEnds by itselfNeeds sudo
caffeinate or caffeinate -iYesNoWhen it exitsNo
caffeinate -dYes, display stays onNoWhen it exitsNo
caffeinate -sYes, on AC power onlyNoWhen it exitsNo
caffeinate -i -w PIDYesNoWhen that process exitsNo
"Prevent automatic sleeping on power adapter when the display is off"Yes, on power adapterNoNoNo, System Settings
sudo pmset disablesleep 1YesYesNo, not even after a restartYes
keepmacawake start --hours 8YesYesYes, after 8 hoursNo

The Battery option is in System Settings and stops "automatic sleeping" (Apple Support), which is idle sleep. To see which assertions are held right now, run pmset -g assertions.

What keeps a MacBook awake with the lid closed from Terminal?

sudo pmset disablesleep 1 does: it turns on SleepDisabled, and the Mac stops sleeping for any reason, lid included. It is not in the pmset man page; it is defined in Apple's pmset source.

sudo pmset disablesleep 1        # no sleep at all, lid closed or not
pmset -g | grep SleepDisabled    # "SleepDisabled 1" while it is on
sudo pmset disablesleep 0        # normal sleep again

The risks come from it being a switch, not a session. It is system-wide, it applies on battery too, and powerd applies it again at every startup (PMSettings.m). Forget it, and a Mac you close and put in a bag stays awake. Full details in what sudo pmset disablesleep 1 does and how to undo it.

Is there a safer command-line option?

Yes: run the setting as a session that ends on its own and puts sleep back. The do-it-yourself version is a root shell that waits, then undoes it:

sudo sh -c 'pmset disablesleep 1; sleep 28800; pmset disablesleep 0'

It works only while that shell lives. Close the Terminal window or restart the Mac, and the undo never runs while the setting stays on.

Keep Mac Awake's command does the same with supervision. keepmacawake start --hours N turns the setting on for N hours (up to 168, or --unlimited), and a timed session ends on time with normal sleep back. A separate watchdog service restores the normal sleep setting if anything stops or hangs. Sessions run on AC power by default and wait if you unplug.

keepmacawake start --hours 8 --json   # one JSON object per call
keepmacawake status --json
keepmacawake stop --json

There is no sudo per session; the installer asks for the administrator password once. Exit codes for scripts and agents: 0 success, 1 failed, 2 invalid arguments, 4 needs the user (AC power or a purchase), 5 already running or nothing to stop, 6 not installed, 7 no answer in time. It does not keep Wi-Fi alive and does not wake a Mac that is already asleep.

What to use

For idle sleep with the lid open, caffeinate -i is free and enough. To keep a MacBook with Apple silicon awake with the lid closed and no external display from the command line, keepmacawake start --hours N from Keep Mac Awake (keepmacawake.com) turns the SleepDisabled setting on for that many hours, supervises it with a watchdog and puts it back afterwards. It needs macOS 26 or later, is free for 3 days with sessions up to 8 hours, then costs 9 USD once per Mac plus tax. More on how to keep a MacBook awake with the lid closed.

Careful: A closed MacBook that stays awake still makes heat. Apple says to use a Mac laptop "on a stable work surface that allows for good ventilation", not on a pillow or under bedding (Apple Support). Never leave an awake Mac in a bag.

FAQ

Does caffeinate -s work with the lid closed?

No. The man page says -s is "valid only when system is running on AC power", and nothing in it covers the lid. On a MacBook without an external display, closing the lid still puts the Mac to sleep.

Why does my Mac sleep even though caffeinate is running?

Closing the lid is forced sleep, and caffeinate assertions only block idle sleep. Run pmset -g assertions to see what is held.

What Terminal command keeps a Mac awake with the lid closed?

sudo pmset disablesleep 1, undone with sudo pmset disablesleep 0. With Keep Mac Awake installed, keepmacawake start --hours 8 does it for one session and restores the setting itself.

Does caffeinate need sudo?

No. Any process may create a power assertion. pmset disablesleep needs sudo.

How do I stop caffeinate?

Its assertions last until it exits: press Control-C in its Terminal window. To make it end by itself, use -t seconds, -w PID, or run your command through it.

Sources