Keep Mac awake with lid closed — no external display needed
Close a MacBook lid and macOS sleeps it immediately — by design. This is sensible for battery life but gets in the way when you want to run a long process, leave a server running, or just stow the laptop while SSH sessions stay alive. This guide explains why macOS does this, what clamshell mode is, and how to keep your Mac running with the lid closed whether or not you have an external display.
Why closing the lid sleeps the Mac
macOS detects lid closure via a magnetic sensor and immediately triggers sleep. The rationale is straightforward: a closed MacBook is likely being moved, and sleep protects against disk corruption and unexpected battery drain. Apple treats it as a safety default rather than a preference.
There is no toggle in System Settings to change this. The only exposed option is Low Power Mode, which affects overall performance, not lid behavior. Changing lid-sleep behavior requires either Terminal or a purpose-built tool.
Clamshell mode: the external-display path
macOS has a built-in exception: if you close the lid while connected to an external display, a power source, and an external keyboard or mouse, the Mac switches to "clamshell mode" — it keeps running with the lid closed and uses the external display instead of the built-in screen.
This works out of the box. The requirements are:
- External display connected (via HDMI, DisplayPort, Thunderbolt, or USB-C)
- Power adapter connected
- External keyboard or mouse connected (or Bluetooth peripherals paired)
If all three are met, close the lid and the Mac keeps running. Open the lid again and the built-in display reactivates automatically.
The limitation is obvious: you need all that hardware. If you want the Mac running with the lid closed for a background task — a long compile, a file transfer, a server process — without a monitor and external peripherals plugged in, clamshell mode is not the answer.
Keep the lid closed without an external display: pmset
macOS includes pmset, a power management command-line tool. The disablesleep flag tells the system to ignore sleep triggers — including lid closure.
Open Terminal and run:
# prevent sleep on lid close (and from other sleep triggers)
sudo pmset -a disablesleep 1
You will be prompted for your password. After that, close the lid — the Mac keeps running. Fans, processes, network connections: all stay active.
To confirm the setting took effect:
# check current sleep settings
pmset -g | grep disablesleep
This should return disablesleep 1.
To restore the default behavior — Mac sleeps when the lid closes:
# re-enable sleep on lid close
sudo pmset -a disablesleep 0
The -a flag applies the setting to all power sources (AC adapter and battery). You can use -c for charger-only or -b for battery-only if you want more granularity.
What disablesleep actually disables
The disablesleep flag is broader than just the lid sensor. It disables all sleep — including sleep triggered by the idle timer, System Settings → Lock Screen settings, and power-nap waking. The Mac will not sleep at all until you undo the setting or manually trigger sleep from the Apple menu.
This is what you want for a background task that needs to run uninterrupted. But remember to reset it when you are done — leaving disablesleep 1 permanently on a laptop that's regularly on battery will drain it faster than normal.
A note on Apple Silicon
On M-series Macs, pmset -a disablesleep 1 works the same way. The Mac will keep running with the lid closed. One difference from Intel Macs: Apple Silicon handles background CPU load more gracefully when throttled, so heat and fan noise with the lid closed are generally less of a concern.
Mainspring includes a Keep awake with lid closed toggle that does exactly this — without an external display, without Terminal, and without a sudo password prompt. Enable it before you close the lid, disable it when you are done. Everything is reversible in one click, and Mainspring is signed and notarized by Apple so macOS trusts it from day one.
Signed & notarized by Apple · 1-day free trial · $29 once
Frequently asked questions
Will the screen turn off when I close the lid?
Yes. Closing the lid physically turns off the built-in display regardless of disablesleep. The CPU, RAM, network, and all processes keep running — you just cannot see them on the built-in screen. Connect to the Mac via SSH or screen sharing if you need to interact with it while the lid is closed.
Does this work on battery?
With the -a flag, yes. The Mac will stay awake on battery with the lid closed. Be aware that this can drain the battery significantly faster, especially if you are running CPU-heavy work. If you only want this behavior while plugged in, use sudo pmset -c disablesleep 1 instead (-c = charger/AC only).
Is it safe to close the lid while a long process is running?
With disablesleep 1 set, yes — the process will keep running. Without it, macOS will sleep the Mac shortly after the lid closes, which will pause or terminate most processes. For anything time-sensitive, set disablesleep 1 before closing the lid.
Can I set a timer so it re-enables sleep automatically?
Not through pmset directly, but you can chain a sleep command in Terminal: sleep 3600 && sudo pmset -a disablesleep 0 will wait one hour and then re-enable sleep. Adjust the seconds as needed.