MacBook laptops are designed to enter system sleep automatically as soon as the display lid is closed. This behaviour preserves battery life and protects the machine from thermal build-up inside laptop bags. Apple officially supports “clamshell mode,” but only when the MacBook is connected simultaneously to an external display, a power adapter, and an external mouse or keyboard.
If you need your MacBook to remain awake while closed—such as when running long terminal scripts, hosting local network servers, rendering media files, or downloading large software packages without an attached external monitor—macOS provides deep power management controls through the native pmset terminal utility. Using pmset, you can override clamshell sleep triggers directly at the Darwin kernel level without relying on third-party background apps.
Understanding Clamshell Sleep Controls in macOS
The pmset (Power Management Settings) command manipulates macOS power configurations stored in the com.apple.PowerManagement system preference domain. The specific setting that governs lid behaviour is disablesleep.
disablesleep 1: Disables system sleep entirely at the hardware level, allowing the MacBook to continue processing tasks with the lid closed even on battery power or without an external monitor.disablesleep 0: Restores default macOS power management, ensuring the laptop sleeps normally when closed.- Thermal precaution: Because modern MacBooks exhaust heat through the keyboard deck and hinge vents, avoid running CPU-intensive operations inside enclosed carrying bags while sleep is disabled.
Configuring pmset to Prevent Sleep on Lid Close
Open the Terminal utility to modify the power management configuration.
- Launch Terminal on your Mac (press Cmd+Space, type
Terminal, and press Enter). - First, check your current power settings to review existing timeouts:
Note down the value displayed next topmset -gsleepanddisablesleep. - To prevent the MacBook from going to sleep when the lid is closed, execute:
Thesudo pmset -a disablesleep 1-aflag applies the setting across all power sources (both AC wall power and battery). - Enter your macOS administrator password when prompted and press Enter.
- Verify that the override is active by running
pmset -gand ensuring thatdisablesleepreflects1. - You can now close your MacBook lid. Audio playback, network downloads, SSH sessions, and background renders will continue uninterrupted.
Restoring Default macOS Lid Sleep Behaviour
Once your background tasks have concluded, revert the setting to ensure your battery does not drain unexpectedly when traveling:
- Open Terminal.
- Run the command to re-enable sleep:
sudo pmset -a disablesleep 0 - Enter your admin password. The MacBook will immediately resume standard clamshell sleep behaviour upon lid closure.
Alternative: Using the caffeinate Command for Temporary Sessions
If you only need to prevent sleep for a specific command or fixed time interval without permanently modifying system preferences, use the built-in caffeinate command:
- Prevent sleep for a duration: Run
caffeinate -u -t 7200to keep the system awake for 2 hours (7200 seconds). - Tie to a specific process: Run
caffeinate -s command_nameto keep the system awake only until that designated command finishes executing. - Press Ctrl+C at any time to cancel caffeinate and restore normal sleep.