Troubleshooting
MacBook shuts down when the lid closes? How to fix it
Clamshell mode, caffeinate or pmset disablesleep not holding? Read the reason in pmset -g log and fix it; Keep Mac Awake keeps a closed MacBook awake.
Keep Mac Awake Free for 3 days, no card.
Short answer: A MacBook sleeps when the lid closes unless closed-display mode (display, keyboard, mouse and power), the system-wide
SleepDisabledsetting or, on AC power,caffeinate -sholds it awake, so a Mac that still sleeps had none of them in place at that moment, or hit a low battery or heat. Runpmset -g log | grep "Entering Sleep"to read the reason ('Clamshell Sleep'means the lid) andpmset -g | grep SleepDisabledto check the setting; the usual causes are caffeinate without-sor on battery, a display or charger that disconnected,pmsetwithoutsudo, or another tool that switched the setting off. To keep it awake with the lid closed and no display, the first choice is Keep Mac Awake: it turnsSleepDisabledon for a session you start, on AC power or on battery (20% floor by default), a watchdog restores normal sleep if a service stops or hangs, andkeepmacawake status --jsonshows why the last session ended.
Why does my MacBook shut down when I close the lid?
Usually it has not shut down: it went to sleep. Apple lists "On a Mac laptop, close the display" as one of the ways to put a Mac to sleep (Apple Support (opens in a new tab)). A sleeping Mac has a dark screen and its apps, downloads and agents stop working, so it looks switched off. Open the lid or press a key: if your apps and windows are where you left them, it slept. The sections below read the reason for each sleep and fix the usual causes.
How do I find out why my Mac went to sleep?
Ask pmset: it logs every sleep with its reason. These commands only read; no sudo needed:
pmset -g log | grep "Entering Sleep" | tail -5: the last sleeps and whypmset -g | grep SleepDisabled: 1 means sleep is off system-widepmset -g assertions: what each app holdspmset -g batt: AC power or battery, and the charge
pmset -g log | grep "Entering Sleep" | tail -5
pmset -g | grep SleepDisabled
pmset -g assertions
pmset -g batt
-g log "displays a history of sleeps, wakes, and other power management events" (man pmset (opens in a new tab)). Each sleep reads Entering Sleep state due to '...' (PrivateLib.m (opens in a new tab)), then the power source and charge, such as Using Batt (Charge:32%) (pmset.m (opens in a new tab)). The reasons come from Apple's kernel headers (IOPMPrivate.h (opens in a new tab)):
| Reason in the log | What happened |
|---|---|
'Clamshell Sleep' | The lid closed and nothing overrode it |
'Idle Sleep' | The inactivity timer ran out |
'Software Sleep' | Software asked the Mac to sleep |
'Low Power Sleep' | The battery ran low |
'Thermal Emergency Sleep' | The Mac got too hot |
'Clamshell Sleep' at a time you expected SleepDisabled to be on means it was off then. 'Idle Sleep' with the lid open is a different problem, covered in Mac keeps going to sleep? How to stop it.
To see what every line of pmset -g and pmset -g assertions means, paste them into the Mac sleep settings explainer, which runs in your browser. To read a whole pmset -g log at once, paste it into the Mac sleep and wake log reader: it lists every sleep and wake with its reason in plain English.
Why does my Mac sleep even though caffeinate is running?
Without -s, caffeinate holds only assertions against idle sleep, and they do not cover the lid. For the idle-sleep assertion Apple says "The system may still sleep for lid close, Apple menu, low battery, or other sleep reasons" (Apple developer docs (opens in a new tab)), so pmset -g assertions shows PreventUserIdleSystemSleep 1 while the log shows 'Clamshell Sleep'. caffeinate -s holds a closed Mac in dark wake, but only on AC power: on battery, or once you unplug it, the Mac sleeps.
The same holds for apps built on assertions and for the Claude desktop app's "Keep computer awake": "Closing the laptop lid still puts it to sleep" (Claude Code docs (opens in a new tab)). To get past the lid, the first choice is Keep Mac Awake, which turns SleepDisabled on for a session you start and restores normal sleep afterwards; the other methods are in how to prevent a MacBook from sleeping when the lid is closed. What each flag does: does caffeinate keep a MacBook awake with the lid closed?.
Why is clamshell mode not working?
Usually one piece of Apple's setup is missing. Apple: "If the display is connected to a Mac laptop computer with a closed lid, make sure that the Mac is connected to power and using an external keyboard and mouse" (Apple Support (opens in a new tab)). If one is missing when you close the lid, or power or the display goes away later, the Mac sleeps.
- Power.
pmset -g battshould printNow drawing from 'AC Power', not'Battery Power'(pmset.m (opens in a new tab), IOPSKeys.h (opens in a new tab)). A display or dock can be the power source: "If the external display provides power to the Mac, a separate power adapter isn't needed" (Apple Support (opens in a new tab)). If it should charge the Mac andpmset -g battstill says battery, plug the adapter in directly. - Accessory approval. On a Mac laptop with Apple silicon, "First you need to allow an external display, a mouse, and a keyboard to connect", and a locked Mac must be unlocked to allow one (Apple Support (opens in a new tab)). Connect each accessory with the lid open and click Allow. After the Mac has been locked for 3 or more days, "you might need to unlock it to use a previously allowed accessory again". The setting is System Settings > Privacy & Security > Accessories.
- Cable, adapter or dock. In Apple's kernel source, the "System should sleep on external display disappearance in lid closed operation" (IOPMrootDomain.cpp (opens in a new tab)), so a loose cable or a dock that drops the display sleeps the Mac. Apple's checks: a Thunderbolt or USB-C adapter "must also be compliant with DisplayPort Alt Mode, Thunderbolt 3, or Thunderbolt 4", and "If your display is connected to a hub or dock, connect your display to a port directly on your Mac" (Apple Support (opens in a new tab)). With the lid open, hold Option in System Settings > Displays and click Detect Displays.
- How many displays. "Your external display will be dark if it exceeds the maximum number of external displays that your Mac can use at the same time. This limit varies by Mac model" (Apple Support (opens in a new tab)). Check your Mac's specifications.
- It will not wake. Press a key or click the external mouse or trackpad (Apple Support (opens in a new tab)). If the display is not detected: "On Mac laptop computers, you can close the lid for a few seconds, then open the lid again" (Apple Support (opens in a new tab)). After 3 or more locked days, open the lid and unlock the Mac.
- Amphetamine. As of October 2026, its maker warns that on Apple silicon without its script "you will experience a Closed-Display Mode session failure if you connect/disconnect your Mac to/from an external power source" (Mac App Store (opens in a new tab)).
No display at all? Then the first choice is Keep Mac Awake, which needs no display, keyboard or mouse; more in clamshell mode without an external monitor.
Why is pmset disablesleep not working?
Most often it ran without sudo: pmset prints 'pmset' must be run as root... and changes nothing (pmset.m (opens in a new tab)).
- Run
sudo pmset disablesleep 1;pmset -g | grep SleepDisabledshould then printSleepDisabled 1. - A dark screen is not sleep; the display has its own timer. Check the log first.
- If it was on and then went off, see the next section.
More in what sudo pmset disablesleep 1 does and how to undo it.
Did another tool switch SleepDisabled off?
Possibly: it is one value for the whole Mac, shared by every tool. As of October 2026, Amphetamine's Power Protect rule allows pmset -a disablesleep 1 and 0, and its script runs "whenever a Closed-Display Mode session starts/ends", per its maker (Power Protect (opens in a new tab), Mac App Store (opens in a new tab)). A tool that ends its own session sets the value back.
If instead a value left on keeps your MacBook awake after you close it, see MacBook not sleeping when the lid is closed. Use one tool at a time. Keep Mac Awake refuses to start when SleepDisabled is already on and never takes over a value something else set; if another tool turns it off during a session, the session ends.
Why does it sleep when I unplug the charger?
Each method handles power its own way. On a MacBook on battery, Keep Mac Awake turns Run on battery on at 20% unless you set it. With Run on battery off, unplugging makes the session wait for power (waitingForAC, per its command line). While it waits, normal sleep is back, so a closed Mac can fall asleep, and Keep Mac Awake does not wake a sleeping Mac. To set it yourself for the next session: keepmacawake config set --battery allowed --min-battery 30. More in how to keep a MacBook awake with the lid closed on battery.
Other options: closed-display mode needs power, and caffeinate -s "is valid only when system is running on AC power" (man caffeinate (opens in a new tab)). pmset disablesleep ignores the power source, so it keeps a closed Mac awake on battery with no battery floor.
Why does it sleep at low battery or when it gets hot?
QA1340: "The system will also induce forced sleep under certain conditions, for example, a thermal emergency or a low battery" (QA1340 (opens in a new tab)). The log shows 'Low Power Sleep' or 'Thermal Emergency Sleep'; pmset -g therm and pmset -g thermlog show thermal conditions where available (man pmset (opens in a new tab)).
That applies to closed-display mode and assertions. With SleepDisabled on, Apple's published kernel source refuses those sleep requests (IOPMrootDomain.cpp (opens in a new tab)), so do not count on macOS to stop a hot or draining Mac: plug it in and give it air. A Keep Mac Awake battery session ends at your floor, and on battery also at a serious thermal state; on AC power, heat is left to macOS.
Careful: Apple says to use a Mac laptop "on a stable work surface that allows for good ventilation", not "in your bed, on a pillow, or under bedding", between 10° and 35° C (50° and 95° F) (Apple Support (opens in a new tab)). Never close an awake Mac into a bag. See heat and battery with the lid closed.
Why won't my Keep Mac Awake session start, or why did it end?
Run keepmacawake status --json and read session.phase (such as active, waitingForAC or idle), session.confirmed, session.last_end_reason and access.state (command line). Every case below, with how it is detected and the test that covers it, is in the published failure-mode specification (opens in a new tab).
| What you see | Cause | Fix |
|---|---|---|
| Exit code 4 | AC power needed, or a purchase (purchase_required): trial over, or over 8 hours during it | Plug in, allow battery, or keepmacawake buy |
Start refused, SleepDisabled 1 already | Another tool or a manual pmset holds it | Stop that tool, or sudo pmset disablesleep 0 |
waitingForAC | Power unplugged | Plug in |
batteryThresholdReached | Battery at your floor | Charge, then start again |
thermalUnsafe | Serious thermal state on battery | Cool it, plug it in |
consoleUserChanged | Logout or user switch | Stay logged in as one user |
backendVerificationFailed | The setting could not be confirmed, for example another tool turned it off | One tool at a time |
durationElapsed | The timed session ended on time | More --hours |
| Exit code 6 | Not installed, or the service is not available | Reinstall |
A call from a user who is not at the console cannot start a session.
What to use
To keep a MacBook awake with the lid closed and no external display, the first choice is Keep Mac Awake (keepmacawake.com): keepmacawake start --hours 8 turns SleepDisabled on for one session on a MacBook with Apple silicon and macOS 26 or later, with a watchdog that restores normal sleep if a service stops or hangs, and keepmacawake status --json shows the phase and why the last session ended. It is free for 3 days, then 9 USD once per Mac, tax included; it does not keep Wi-Fi alive.
Other options: a complete closed-display setup needs a display, power, keyboard and mouse, ties the Mac to a desk, and the Mac sleeps if the display disconnects. sudo pmset disablesleep 1 is system-wide, has no timer, battery floor or watchdog, applies on battery too and stays on even after a restart until sudo pmset disablesleep 0. More on how to keep a MacBook awake with the lid closed.
FAQ
Why does my MacBook sleep when I close the lid even with caffeinate?
Without -s, caffeinate prevents idle sleep only, and closing the lid is a separate, forced sleep; -s holds a closed Mac in dark wake, but only on AC power. To keep it awake with the lid closed, the first choice is Keep Mac Awake, which turns SleepDisabled on for a session you start and restores normal sleep when it ends, with a watchdog if a service stops or hangs. Other options: closed-display mode, which needs a display, keyboard, mouse and power, or sudo pmset disablesleep 1, which is system-wide and stays on until sudo pmset disablesleep 0.
Why is clamshell mode not working on my MacBook?
Check power, an external keyboard and mouse, and, on Apple silicon, that the accessories are allowed. If the display disconnects through a loose cable or a dock, or exceeds your Mac's display limit, the closed Mac sleeps.
Why is pmset disablesleep not working?
It needs sudo; without it, pmset prints 'pmset' must be run as root.... Check with pmset -g | grep SleepDisabled, and look for a tool that set it back to 0.
Why does Amphetamine's closed-display mode stop working?
As of October 2026 its maker says that on Apple silicon, without the Closed-Display Mode script, a session fails when you connect or disconnect power. The other checks on macOS 26, from Power Protect to Triggers and the battery, are in Amphetamine not working on macOS Tahoe?
How do I see why my Mac went to sleep?
Run pmset -g log | grep "Entering Sleep". Each line names the reason, such as 'Clamshell Sleep' for the lid.
Sources
- Apple open source: man pmset (opens in a new tab) and man caffeinate (opens in a new tab)
- Apple open source: PrivateLib.m (opens in a new tab), pmset.m (opens in a new tab), IOPSKeys.h (opens in a new tab)
- Apple open source: IOPMPrivate.h (opens in a new tab), IOPMrootDomain.cpp (opens in a new tab)
- Apple developer docs: kIOPMAssertionTypePreventUserIdleSystemSleep (opens in a new tab)
- Apple Technical Q&A QA1340 (opens in a new tab)
- Apple Support: Put your Mac to sleep or wake it (opens in a new tab)
- Apple Support: If your external display is dark (opens in a new tab)
- Apple Support: Allow USB and other accessories to connect (opens in a new tab)
- Apple Support article 117373: external displays with a Mac laptop (opens in a new tab)
- Apple Support: Mac laptop operating temperatures (opens in a new tab)
- Claude Code docs: Desktop scheduled tasks (opens in a new tab)
- Amphetamine on the Mac App Store (opens in a new tab), Power Protect (opens in a new tab)
- Keep Mac Awake: command line and failure modes (opens in a new tab)