Troubleshooting
MacBook still sleeps with the lid closed? How to fix it
Find the sleep reason with pmset -g log, then fix it: caffeinate alone, a lost display or charger, pmset without sudo, a reset setting, battery or heat.
Short answer: A MacBook sleeps when the lid closes unless closed-display mode (display, keyboard, mouse and power) or the system-wide
SleepDisabledsetting overrides it, so a Mac that still sleeps had neither 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:caffeinatealone, a display or charger that disconnected,pmsetwithoutsudo, or another tool that switched the setting off.
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 why
pmset -g | grep SleepDisabled # 1 means sleep is off system-wide
pmset -g assertions # what each app holds
pmset -g batt # AC power or battery, and the charge
-g log "displays a history of sleeps, wakes, and other power management events" (man pmset). Each sleep reads Entering Sleep state due to '...' (PrivateLib.m), then the power source and charge, such as Using Batt (Charge:32%) (pmset.m). The reasons come from Apple's kernel headers (IOPMPrivate.h):
| 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.
Why does my Mac sleep even though caffeinate is running?
caffeinate holds power assertions, 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), so pmset -g assertions shows PreventUserIdleSystemSleep 1 while the log shows 'Clamshell Sleep'.
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). The methods that work: how to prevent a MacBook from sleeping when the lid is closed. Why no flag helps: why caffeinate does not keep your 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).
- Power.
pmset -g battshould printNow drawing from 'AC Power', not'Battery Power'(pmset.m, IOPSKeys.h). - Accessories. 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). Approve them with the lid open.
- The display. In Apple's kernel source, the "System should sleep on external display disappearance in lid closed operation" (IOPMrootDomain.cpp), so a loose cable or a dock that drops it sleeps 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).
No display at all? See 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).
- 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, Mac App Store). A tool that ends its own session sets the value back.
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?
Closed-display mode needs power, and caffeinate -s "is valid only when system is running on AC power" (man caffeinate). pmset disablesleep ignores the power source.
Keep Mac Awake runs on AC power by default. Unplug, and the session waits 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 run on battery, allow it for the next session: keepmacawake config set --battery allowed --min-battery 30.
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). The log shows 'Low Power Sleep' or 'Thermal Emergency Sleep'; pmset -g therm and pmset -g thermlog show thermal conditions where available (man pmset).
That applies to closed-display mode and assertions. With SleepDisabled on, Apple's published kernel source refuses those sleep requests (IOPMrootDomain.cpp), 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). 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.
| 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
If the lid has to stay closed with no display, keepmacawake start --hours 8 from Keep Mac Awake (keepmacawake.com) turns SleepDisabled on for one session on a MacBook with Apple silicon and macOS 26 or later, with a watchdog that restores normal sleep, 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 plus tax; it does not keep Wi-Fi alive. The free fixes: a complete closed-display setup, or sudo pmset disablesleep 1 and its undo. 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?
caffeinate prevents idle sleep, and closing the lid is a separate, forced sleep. Use closed-display mode or turn on SleepDisabled.
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, 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.
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
man pmsetandman caffeinateon macOS- Apple open source: PrivateLib.m, pmset.m, IOPSKeys.h
- Apple open source: IOPMPrivate.h, IOPMrootDomain.cpp
- Apple developer docs: kIOPMAssertionTypePreventUserIdleSystemSleep
- Apple Technical Q&A QA1340
- Apple Support: If your external display is dark
- Apple Support: Allow USB and other accessories to connect
- Apple Support: Mac laptop operating temperatures
- Claude Code docs: Desktop scheduled tasks
- Amphetamine on the Mac App Store, Power Protect
- Keep Mac Awake: command line and failure modes