---
title: How to prevent a MacBook from sleeping when the lid is closed
description: A MacBook sleeps when the lid closes unless closed-display mode or the SleepDisabled setting is on. Every method compared, and what to use.
date: 2026-10-20
kicker: Lid closed
section: The closed lid, explained
related: clamshell-mode-without-external-monitor, pmset-disablesleep, caffeinate-lid-closed
order: 1
home: 1
---

> **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 `SleepDisabled` setting is on. Without a display, turn that setting on with `sudo pmset disablesleep 1` and off with `sudo 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](https://support.apple.com/guide/mac-help/put-your-mac-to-sleep-or-wake-it-mh10330/mac)), and its note QA1340 says "Closing the lid on a laptop or selecting sleep from the Apple menu both cause forced sleep" ([QA1340](https://developer.apple.com/library/archive/qa/qa1340/_index.html)).

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](https://developer.apple.com/documentation/iokit/kiopmassertiontypepreventuseridlesystemsleep)). In Apple's published kernel source, a closed lid stays awake in closed-display mode ([IOPMrootDomain.cpp](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/iokit/Kernel/IOPMrootDomain.cpp#L4461)) or when `SleepDisabled` blocks sleep for every reason ([IOPMrootDomain.cpp](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/iokit/Kernel/IOPMrootDomain.cpp#L7671)). 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](https://support.apple.com/guide/macbook-air/connect-an-external-display-apd8cdd74f57/mac)).

1. Connect the Mac to power.
2. 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](https://support.apple.com/en-us/102282)).
3. 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](https://support.apple.com/en-us/102501)). In Apple's kernel source, the "System should sleep on external display disappearance in lid closed operation" ([IOPMrootDomain.cpp](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/iokit/Kernel/IOPMrootDomain.cpp#L8840)), so a loose cable ends it. No display? See [clamshell mode without an external monitor](/blog/clamshell-mode-without-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:

```sh
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](https://github.com/apple-oss-distributions/PowerManagement/blob/d415e45501842834a280930c3eed9186544a67f0/pmset/pmset.m#L5813) defines it. It is a switch, not a session: it applies on battery, survives a restart ([PMSettings.m](https://github.com/apple-oss-distributions/PowerManagement/blob/d415e45501842834a280930c3eed9186544a67f0/pmconfigd/PMSettings.m#L1160)), 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](/blog/pmset-disablesleep).

## 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](https://github.com/nghialuong/Lidless)).
- **Amphetamine** runs a Closed-Display Mode script on Apple silicon; its Power Protect add-on installs a sudo rule for `pmset -a disablesleep 1` and `0` ([Power Protect](https://x74353.github.io/Amphetamine-Power-Protect/)).
- **KeepingYouAwake**, a wrapper around `caffeinate`, answers "Does it work on a MacBook with a closed lid?" with "No" ([README](https://github.com/newmarcel/KeepingYouAwake)).

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](/blog/best-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](/blog/caffeinate-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](https://support.apple.com/guide/mac-help/set-sleep-and-wake-settings-mchle41a6ccd/mac)). 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](https://code.claude.com/docs/en/desktop-scheduled-tasks)). See [how to keep Claude Code running with the lid closed](/blog/keep-claude-code-running-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](https://apps.apple.com/us/app/amphetamine/id937984704?mt=12)). More in [an Amphetamine alternative for the lid closed](/blog/amphetamine-alternative-lid-closed).

Still sleeping after a method that should work? See [MacBook still sleeps with the lid closed? How to fix it](/blog/mac-sleeps-with-lid-closed-not-working).

## 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](https://support.apple.com/en-us/102336)). Never close an awake Mac into a bag. See [heat and battery with the lid closed](/blog/macbook-lid-closed-heat-and-battery).

## 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](https://support.apple.com/guide/mac-help/put-your-mac-to-sleep-or-wake-it-mh10330/mac)
- [Apple Support: Set sleep and wake settings for your Mac](https://support.apple.com/guide/mac-help/set-sleep-and-wake-settings-mchle41a6ccd/mac)
- [Apple Support: Connect an external display to MacBook Air](https://support.apple.com/guide/macbook-air/connect-an-external-display-apd8cdd74f57/mac)
- [Apple Support: Allow USB and other accessories to connect](https://support.apple.com/en-us/102282)
- [Apple Support: If your external display is dark](https://support.apple.com/en-us/102501)
- [Apple Support: Mac laptop operating temperatures](https://support.apple.com/en-us/102336)
- [Apple Technical Q&A QA1340](https://developer.apple.com/library/archive/qa/qa1340/_index.html)
- [Apple developer docs: kIOPMAssertionTypePreventUserIdleSystemSleep](https://developer.apple.com/documentation/iokit/kiopmassertiontypepreventuseridlesystemsleep)
- [Apple open source: IOPMrootDomain.cpp](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/iokit/Kernel/IOPMrootDomain.cpp), [pmset.m](https://github.com/apple-oss-distributions/PowerManagement/blob/d415e45501842834a280930c3eed9186544a67f0/pmset/pmset.m), [PMSettings.m](https://github.com/apple-oss-distributions/PowerManagement/blob/d415e45501842834a280930c3eed9186544a67f0/pmconfigd/PMSettings.m)
- `man caffeinate` and `man pmset` on macOS
- [Claude Code docs: Desktop scheduled tasks](https://code.claude.com/docs/en/desktop-scheduled-tasks)
- [Amphetamine on the Mac App Store](https://apps.apple.com/us/app/amphetamine/id937984704?mt=12), [Power Protect](https://x74353.github.io/Amphetamine-Power-Protect/)
- [Lidless README](https://github.com/nghialuong/Lidless), [KeepingYouAwake README](https://github.com/newmarcel/KeepingYouAwake)
- [Keep Mac Awake: command line](https://keepmacawake.com/command-line.md)
