pmset disablesleep: what it does, the risks, and how to undo it
It’s the one free command that keeps a MacBook awake with the lid closed on battery. It’s also the one people forget to turn off. Here is how to use it, check it and undo it.
Short answer. sudo pmset -a disablesleep 1 switches system sleep off, lid included. sudo pmset -a disablesleep 0 switches it back on. Check with pmset -g | grep SleepDisabled. It stays on until you undo it, so tie it to a timer or use something that undoes it for you.
What it does
disablesleep sets a system-wide flag, shown as SleepDisabled, that stops the Mac from sleeping for any reason: idle, lid, the Apple menu. It needs administrator rights, and it isn’t listed in the pmset manual, so Apple doesn’t promise it will keep working. On current Macs it still does.
sudo pmset -a disablesleep 1 # sleep off, lid included
pmset -g | grep SleepDisabled # 1 = off, 0 = normal
sudo pmset -a disablesleep 0 # back to normal
The risks
- It never ends by itself. Your Mac won’t sleep tonight, tomorrow, or in your bag next week, until you run the command with
0. - It’s saved with your power settings, so it can still be there after a restart. People who forgot it find “Sleep” greyed out in the Apple menu weeks later (MacRumors).
- It knows nothing about heat or battery. A closed Mac running hard in a bag keeps running until the battery is flat.
- It needs your password every time, or a
sudoersrule that lets it run without one.
Make it end by itself
If you use it, give it an end. Start your job first, find its process ID (for Claude Code: pgrep -n claude), then run this in a second Terminal tab, with your PID instead of 4242:
sudo sh -c 'trap "pmset -a disablesleep 0; exit" INT TERM HUP
pmset -a disablesleep 1
end=$(( $(date +%s) + 5400 ))
while kill -0 4242 2>/dev/null && [ $(date +%s) -lt $end ]; do sleep 30; done
pmset -a disablesleep 0'
It restores normal sleep at whichever comes first: the job ends, or 90 minutes pass (5400 seconds). Press Ctrl-C or close the tab and it restores sleep too. The one thing it can’t survive is a restart in the middle, so after a crash or a restart run sudo pmset -a disablesleep 0 by hand.
If sleep stays off after you undo it
- Run
sudo pmset -a disablesleep 0, thenpmset -g | grep SleepDisabled: it should say0. - Restart and check again.
- If it comes back as
1, something is setting it again: an app, a script or a launch agent. Look at your login items and at any keep-awake tool you installed, including the ones that added asudoersrule. - Use
pmset -g assertionsto see which apps are holding the Mac awake right now.
Is there a way without a password?
Yes. macOS lets a normal user ask the kernel not to sleep when the lid closes; that request is separate from disablesleep and disappears at every restart. Clamshell says its core needs no password, and Hibernot uses this kernel request: it sets it only for the run you start, clears it when the run ends or after a crash, and adds a time limit, a battery floor and a temperature stop on top. The other options, free and paid, are in how to keep a MacBook awake with the lid closed.