Lid closed
How to prevent a MacBook from sleeping when the lid is closed
A MacBook sleeps when the lid closes unless closed-display mode or the SleepDisabled setting is on. Every method compared, and what to use.
Short answer: Closing the lid puts a MacBook to sleep unless one of two things is true: it is in Apple's closed-display mode (external display, keyboard and mouse, and power connected), or the system-wide
SleepDisabledsetting is on. Without a display, turn that setting on withsudo pmset disablesleep 1and off withsudo pmset disablesleep 0, or use an app that turns it on for one session and puts it back, such as Keep Mac Awake (keepmacawake start --hours 8).caffeinate, the Battery settings and other idle-sleep tools do not cover the lid.
Why does a MacBook sleep when you close the lid?
Closing the display is one of the ways macOS puts a Mac laptop to sleep, and it is forced sleep, not idle sleep. Apple lists "On a Mac laptop, close the display" next to Sleep in the Apple menu (Apple Support), and its note QA1340 says "Closing the lid on a laptop or selecting sleep from the Apple menu both cause forced sleep" (QA1340).
Most keep-awake tools hold power assertions against idle sleep (the sleep after inactivity), and Apple says "The system may still sleep for lid close" (Apple developer docs). In Apple's published kernel source, a closed lid stays awake in closed-display mode (IOPMrootDomain.cpp) or when SleepDisabled blocks sleep for every reason (IOPMrootDomain.cpp). Every working method uses one of the two.
Which methods keep a MacBook awake with the lid closed?
Closed-display mode works if you have a display; the SleepDisabled setting works without one, set by hand or by an app. Idle-sleep tools stop at the lid. As of October 2026:
| Method | Closed MacBook stays awake | Needs | Watch out for |
|---|---|---|---|
| Closed-display mode | Yes, with a display | Display, keyboard and mouse, power | Sleeps if the display disconnects |
sudo pmset disablesleep 1 | Yes, no display | Administrator password | No timer; stays on after a restart |
An app that turns on SleepDisabled | Yes, no display | A helper or sudo rule, approved once | What restores sleep if it crashes |
| Keep Mac Awake | Yes, no display | Apple silicon, macOS 26 or later | Paid after a 3-day trial |
| Dummy display plug | Not documented by Apple | A free display port | Test yours |
caffeinate, any flag | No | Nothing | Idle sleep only |
| Battery or Energy "Prevent automatic sleeping" options | No | Power adapter on laptops | Idle sleep only |
| Claude desktop app's "Keep computer awake" | No | The Claude app | Idle sleep only |
| Amphetamine Closed-Display Mode without its script | Until the power source changes | Amphetamine | Fails when you plug in or unplug |
How does closed-display mode work?
It is Apple's supported way to use a MacBook closed: with an external display, keyboard and mouse or trackpad, and power connected, "you can use the display and accessories to use your MacBook Air, even when the lid is closed" (MacBook Air guide).
- Connect the Mac to power.
- Connect the display, keyboard and mouse, and approve them with the lid open: on a Mac laptop with Apple silicon, "First you need to allow an external display, a mouse, and a keyboard to connect" (Apple Support).
- Close the lid.
Apple's own check: "make sure that the Mac is connected to power and using an external keyboard and mouse" (Apple Support). In Apple's kernel source, the "System should sleep on external display disappearance in lid closed operation" (IOPMrootDomain.cpp), so a loose cable ends it. No display? See clamshell mode without an external monitor, which also covers dummy plugs.
How do you keep a MacBook awake with the lid closed and no display?
Turn on the system-wide SleepDisabled setting, and the Mac stops sleeping for any reason, lid included:
sudo pmset disablesleep 1 # no sleep at all, lid closed or not
pmset -g | grep SleepDisabled # "SleepDisabled 1" while it is on
sudo pmset disablesleep 0 # normal sleep again
The option is not in man pmset; Apple's pmset source defines it. It is a switch, not a session: it applies on battery, survives a restart (PMSettings.m), and stays on until you undo it. Forget it once, and the Mac stays awake in your bag. Details in what sudo pmset disablesleep 1 does and how to undo it.
Which apps keep a MacBook awake with the lid closed?
The ones that change the same SleepDisabled setting, through a privileged helper or a sudo rule. As of October 2026, by their makers' descriptions:
- Lidless, free and open source, sets the flag through a root helper and restores sleep "if the app stops checking in (>90s)" (README).
- Amphetamine runs a Closed-Display Mode script on Apple silicon; its Power Protect add-on installs a sudo rule for
pmset -a disablesleep 1and0(Power Protect). - KeepingYouAwake, a wrapper around
caffeinate, answers "Does it work on a MacBook with a closed lid?" with "No" (README).
Ask each one what puts sleep back if it crashes, and what it does on battery and in heat. The comparison of keep-awake apps for AI agents covers nine options.
What does not keep a MacBook awake with the lid closed?
Anything that only prevents idle sleep:
- caffeinate. Each flag is an assertion;
-s"is valid only when system is running on AC power" (man caffeinate). See why caffeinate does not keep your MacBook awake with the lid closed. - Battery and Energy settings. "Prevent automatic sleeping on power adapter when the display is off" (System Settings > Battery > Options) and, on desktops, "Prevent automatic sleeping when the display is off" (System Settings > Energy) stop automatic sleep (Apple Support). Closing the display is a separate way to sleep.
- The Claude desktop app's "Keep computer awake". Anthropic: "Closing the laptop lid still puts it to sleep" (Claude Code docs). See how to keep Claude Code running with the lid closed.
- Amphetamine without its script. Its maker's 5.3 notes: without it, "you will experience a Closed-Display Mode session failure if you connect/disconnect your Mac to/from an external power source" (Mac App Store). More in an Amphetamine alternative for the lid closed.
Still sleeping after a method that should work? See MacBook still sleeps with the lid closed? How to fix it.
What to use
At a desk with a monitor, keyboard, mouse and charger, use Apple's closed-display mode; it is free. To keep a MacBook with Apple silicon awake with the lid closed and no external display, keepmacawake start --hours 8 from Keep Mac Awake (keepmacawake.com) turns the SleepDisabled setting on for that session, supervises it with a watchdog and restores normal sleep when the session ends.
Keep Mac Awake is a menu bar app plus the keepmacawake command for macOS 26 or later. Sessions (no limit, 1 hour, 8 hours, or up to 168 hours) run on AC power by default and wait if you unplug; on battery, a session ends at a floor you pick or at a serious thermal state. It is free for 3 days, then 9 USD once per Mac plus tax. It does not keep Wi-Fi alive or wake a Mac that is already asleep. More on how to keep a MacBook awake with the lid closed. For a job you will watch, the free pmset commands above are enough.
Careful: A closed MacBook that stays awake still makes heat. Apple says to use a Mac laptop "on a stable work surface that allows for good ventilation" and not "in your bed, on a pillow, or under bedding" (Apple Support). Never close an awake Mac into a bag. See heat and battery with the lid closed.
FAQ
Can you close a MacBook without it going to sleep?
Yes. Use closed-display mode with an external display, keyboard, mouse and power, or turn on SleepDisabled with sudo pmset disablesleep 1 or an app such as Keep Mac Awake.
How do I keep my MacBook on with the lid closed without a monitor?
Turn on SleepDisabled with sudo pmset disablesleep 1, and undo it with sudo pmset disablesleep 0. Keep Mac Awake does the same for one session and restores normal sleep itself.
Is there a setting in System Settings to stop sleep when the lid closes?
No. The Battery, Energy and Lock Screen options cover sleep after inactivity; only closed-display mode or SleepDisabled overrides the lid.
Does caffeinate keep a Mac awake with the lid closed?
No. Its assertions prevent idle sleep, and Apple documents that the Mac may still sleep for lid close while they are held.
Can a MacBook stay awake with the lid closed on battery?
Closed-display mode needs power. sudo pmset disablesleep 1 keeps it awake on battery until the charge runs out. Keep Mac Awake needs AC power unless you allow battery down to a floor you pick.
Sources
- Apple Support: Put your Mac to sleep or wake it
- Apple Support: Set sleep and wake settings for your Mac
- Apple Support: Connect an external display to MacBook Air
- Apple Support: Allow USB and other accessories to connect
- Apple Support: If your external display is dark
- Apple Support: Mac laptop operating temperatures
- Apple Technical Q&A QA1340
- Apple developer docs: kIOPMAssertionTypePreventUserIdleSystemSleep
- Apple open source: IOPMrootDomain.cpp, pmset.m, PMSettings.m
man caffeinateandman pmseton macOS- Claude Code docs: Desktop scheduled tasks
- Amphetamine on the Mac App Store, Power Protect
- Lidless README, KeepingYouAwake README
- Keep Mac Awake: command line