A MacBook sleeps when you close the lid unless it is on power with an external display, keyboard and mouse attached, or something overrides lid sleep. The simplest override is Clamshell for Mac, a menu bar app that keeps the Mac awake with the lid closed on battery or power, with no sudo and no external display. The free route is sudo pmset disablesleep 1, which stays on system-wide until you undo it; caffeinate does not survive a lid close.
An animated MacBook with a coding agent deploying a website from its terminal. The Option key is held and the lid closes: the display goes black, but the Mac stays awake, so a dimmed copy of the terminal keeps working above the closed laptop while its front edge fills with light. When the deploy is done, a pointer shows how to lift the lid. Opening it wakes the Mac to its lock screen, which unlocks to the finished run: deployed, with the live address. The lid can then be opened and closed freely.
Clamshell for Mac keeps the Mac awake with the lid closed while armed. No sudo, no monitor. Free for 7 days, then $9.99 once.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell. On your phone? Send the Mac download link to yourself.
With a monitor, keyboard, and mouse, use Apple's closed-display setup. Without a monitor, your options are an HDMI dummy plug, sudo pmset disablesleep, Amphetamine's Closed-Display Mode, LidRun Pro, or Clamshell for Mac, a menu bar app that keeps an Apple Silicon MacBook running with the lid closed and needs no admin rights. caffeinate on its own does not survive a lid close.
Quick answer
At a desk with a monitor
Connect and allow an external display, keyboard, and mouse, then close the lid. This is Apple's supported route and costs nothing if you own the hardware.
No monitor, Terminal only
sudo pmset -a disablesleep 1 works, but it is system-wide and stays on until you run sudo pmset -a disablesleep 0.
No monitor, free or agent-aware app
Amphetamine's Closed-Display Mode is free; on Apple Silicon laptops its App Store listing describes a separate Power Protect download. LidRun Pro is agent-aware, from $9.90 once; its free tier is lid-open only.
No monitor and no admin
Clamshell is a menu bar app that keeps the Mac awake with the lid closed while it is armed. Arm it from the menu bar, then close the lid. It needs no sudo, admin prompt, or privileged helper, and normal lid sleep returns when you disarm or quit. 7-day free trial, then $9.99 once for one Mac.
Does not work lid-closed: caffeinate, and keep-awake apps that only block idle sleep, such as KeepingYouAwake.
Clamshell for Mac in three steps
- Install it and open it. Download the free trial from clamshell.dev, or run
brew install --cask clamshell, then open Clamshell once. It runs in the menu bar. - Arm it. Right-click the menu bar icon to arm until you turn it off. To arm for the next close only, press both Option keys, or hold ⌥ Option while you close the lid on a MacBook with a lid angle sensor. Check that the menu bar icon shows armed.
- Close the lid. The built-in display stays black and the Mac keeps running, on power or battery, with no external display and no sudo. Disarm from the menu bar or quit Clamshell when you are done, and normal lid sleep is back.
It needs an Apple Silicon MacBook on macOS 14 or later, and costs $9.99 once after a 7-day trial. Clamshell for Mac is a closed-source app, not Apple's clamshell mode, which works only with an external display attached. Clamshell for Mac is available only from clamshell.dev, on Setapp and through Homebrew. It is not on the Mac App Store; App Store apps named Clamshell are from other developers. If you already have a monitor, keyboard and mouse on your desk, Apple's free route below needs no app at all.
Why closing the lid is different from idle sleep
macOS has two separate reasons to sleep. Idle sleep happens when nobody touches the Mac for a while, and a running process can hold it off with a power assertion. That is what caffeinate and most keep-awake apps do. Lid-close sleep is a separate policy triggered by the lid itself. An active download, build, or AI coding agent does not block it. Unless an external display setup or a lid-sleep override is in place, the Mac goes to sleep a moment after the lid shuts and local work stops. The caffeinate guide explains the difference in more detail.
So every working method below does one of two things: it satisfies Apple's external display rule, or it changes what the lid does.
Every method, side by side
| Method | Lid closed | Hardware | Admin or root | How it ends | Price |
|---|---|---|---|---|---|
| Apple external display setup | Yes | Extra gear. External display, keyboard, and mouse | No | Disconnect the display or open the lid | Free if you own the hardware |
| HDMI dummy plug | Yes, by posing as a display | Extra gear. The plug, plus a free port | No | Unplug it | Cost of the adapter |
caffeinate |
No | None | No | When the process or timer ends | Free, built in |
pmset disablesleep |
Yes | None | Needs sudo |
Stays on. Ends only when you run the inverse command | Free, built in |
| Amphetamine | Yes, with Closed-Display Mode | None; Apple Silicon laptops get an optional Power Protect install for power changes | Add-on only. The app needs none. The optional Power Protect install adds a script and a configuration file in /private/etc/sudoers.d/, authorized once with Touch ID or an administrator password |
When the session ends | Free |
| LidRun | Yes, Pro only | None | Admin prompt. A helper you approve once, or your admin password on every toggle | When the job ends, a guardrail trips, or you stop it | Free lid-open tier; Pro from $9.90 once |
| Clamshell | Yes | None | None. No password, no sudo, no privileged helper | Lid open for an Option-close or menu-armed session; disarm otherwise; always ends at restart | Paid, closed source: 7-day trial, then $9.99 once |
Route 1: Apple's external display setup
If you already work at a desk with a monitor, this is the least surprising choice. Apple's support article on accessories says to allow an external display, a mouse, and a keyboard to connect to your Mac laptop; after that you can use it with the lid closed.
- Connect the external display, keyboard, and mouse, and allow them if macOS asks.
- Wait until the desktop appears on the external display.
- Close the lid. The Mac keeps running on the external display.
It does not help on a train, in a bag, or for a Mac you want to leave running headless. An HDMI dummy plug imitates a monitor to cover that case, but it is one more piece of hardware to carry, it takes a port, and macOS treats the phantom screen as real, so windows can open where you cannot see them. The clamshell mode without an external display guide covers the dummy plug route.
Route 2: pmset disablesleep in Terminal
This is the free, no-install override. It sets a system-wide SleepDisabled flag, so the Mac stays awake with the lid closed, on battery and on power.
# keep awake, including lid closed
sudo pmset -a disablesleep 1
# check: look for SleepDisabled 1
pmset -g
# restore normal sleep
sudo pmset -a disablesleep 0
The catch is scope. The flag is not tied to a job, it has no timer, nothing shows it in the menu bar, and it is not in the current pmset(1) manual. The pmset disablesleep guide has the checks and the undo steps.
It has no timer. Forget to undo it and a closed MacBook keeps running in a bag until the battery is empty.
Route 3: Clamshell for Mac
Clamshell does one job: while armed, closing the lid leaves the Mac running with the built-in display black. There is no sudo, admin prompt, kernel extension, driver, or privileged helper.
- Download Clamshell from clamshell.dev and open it. It lives in the menu bar.
- External displays can stay connected: Clamshell arms with or without one.
- Hold ⌥ Option while closing the lid. This gesture needs a lid angle sensor, which the 14-inch and 16-inch MacBook Pro (2021 and later) and some newer MacBook Air models have, but not the M1 MacBook Air or the 13-inch MacBook Pro. Without one, press both Option keys or arm from the menu bar icon instead.
- Open the lid when you are back. The Mac locks, and an Option-close or menu-armed session ends: the menu bar menu arms for the next close only. Right-click and Shortcuts arming stay active across reopenings until you disarm.
Restarting always brings back normal lid sleep. It works on power and on battery and stays armed through every plug or unplug. Thermal safety is always on: if macOS reports serious or critical thermal pressure, Clamshell disarms toward normal lid sleep and blocks arming until the Mac cools. A low-battery switch, on by default, lets the Mac sleep when the battery reaches 20%.
Close the lid without a monitor. Clamshell is free for 7 days, then $9.99 once for one Mac. Apple Silicon MacBooks on macOS 14 or later.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell. Also on Setapp.
Route 4: Amphetamine or LidRun
Amphetamine is a free, long-running keep-awake app on the Mac App Store. Its keep-awake session options include allowing or preventing system sleep when the built-in display is closed. Its listing says Power Protect is only needed on Apple Silicon laptops and is a separate download and installation. The latest version on the listing, checked September 29, 2026, is 5.3.2 from November 10, 2023. If you also want timers and triggers for everyday keep-awake use, it is the strongest free pick. See Amphetamine alternatives for closed-lid use for the details.
LidRun is a menu bar utility focused on AI and developer jobs. Closed-Lid Mode is a Pro feature; its FAQ says it calls pmset disablesleep and uses a helper that you approve once, or macOS asks for an administrator password each time. Its standout is Auto Mode, which detects tools such as Claude Code, Cursor, Docker, and Ollama. The full three-way breakdown is in LidRun vs Amphetamine vs Clamshell.
Which route fits your situation
- You already own a monitor and use it daily: Apple's setup.
- A one-off job, lid open:
caffeinate -i your-command. - A one-off job, lid closed, you are comfortable in Terminal:
pmset disablesleep, and set a reminder to undo it. - You want a free app with many keep-awake triggers: Amphetamine.
- You want the Mac to notice your agent and stop when it finishes: LidRun Pro.
- You want to close the lid anywhere with no admin setup, and have normal sleep come back on lid open: Clamshell.
Running AI coding agents with the lid closed
The most common reason people search for this is a Claude Code or Codex run that should not stop when the MacBook closes. Keeping the Mac awake is only half of it; the agent also needs its permissions and a working network connection. Clamshell's core does not detect agents; its optional Agent Status, Agent Notifications and Finish Work, Then Sleep modules show what Claude Code, Codex, Grok, OpenCode and Kiro agents are doing, notify you, and can let them finish before the Mac sleeps. You can arm it from a script with open "clamshell://arm" and disarm with open "clamshell://disarm", or use its Arm, Disarm, Toggle, and Status actions in Shortcuts. The Claude Code lid-closed guide walks through a full overnight setup.
Keep a closed MacBook safe
- Airflow first. A closed laptop on a hard, open surface is fine for most jobs. A bag or a sofa cushion traps heat no matter which tool you use.
- Know how it ends. Every method above has a different off switch. Know yours before you walk away.
- Watch the battery. Heavy work on battery drains it as fast as it would with the lid open.
Frequently asked questions
Can a MacBook stay awake with the lid closed without an external monitor?
Yes. Without a monitor you need something that overrides lid sleep: sudo pmset -a disablesleep 1, an HDMI dummy plug, Amphetamine's Closed-Display Mode, LidRun Pro, or Clamshell for Mac. Stock macOS settings alone cannot do it.
Does caffeinate keep a Mac awake with the lid closed?
No. caffeinate prevents idle sleep. Closing the lid triggers a different sleep path that it does not block, so the Mac still sleeps.
Is there a setting in System Settings to keep a MacBook on when the lid is closed?
Not for a MacBook with no external display. System Settings controls idle and display sleep, not lid-close sleep. Apple's supported route is an external display, keyboard, and mouse.
Is it safe to keep a MacBook running with the lid closed?
Generally yes, with airflow. A closed MacBook on a hard surface can run normal work. Avoid bags and soft furniture, and prefer a tool with a clear off switch. Clamshell disarms toward normal lid sleep on serious or critical thermal pressure.
Does keeping the lid closed drain the battery?
The Mac draws what the work demands, as it would with the lid open. The built-in display stays dark, and an idle closed Mac draws less than a busy one. Heavy work on battery still drains it, so plug in for long runs or set a low-battery cut-off where your tool offers one.
Which method works on Apple Silicon MacBooks?
All of the working methods here run on Apple Silicon. Amphetamine offers an optional Power Protect install on Apple Silicon laptops for power changes, and Clamshell supports only Apple Silicon MacBooks on macOS 14 or later.
Related guides
- Does Caffeinated work with the lid closed?
- Dummy display plug vs an app
- Claude Code Remote Control with the lid closed
- Use Codex from your phone with the lid closed
- Is it safe to run a MacBook with the lid closed?
- Use a MacBook as a home server with the lid closed
- Does a MacBook keep downloading with the lid closed?
- Is it safe to keep a MacBook running in a bag?
- How keep-awake apps work with the lid closed
- Use clamshell mode without an external display
- Why caffeinate does not work with the lid closed
- What sudo pmset disablesleep 1 does and how to undo it
- Keep Claude Code running with the lid closed
- Clamshell vs Amphetamine vs pmset compared
- Amphetamine alternatives for closed-lid use on Apple Silicon
- LidRun vs Amphetamine vs Clamshell
- Best apps to keep a MacBook awake with the lid closed
- Why KeepingYouAwake sleeps anyway when the lid closes
- Amphetamine not working with the lid closed: fixes
- How to undo sudo pmset disablesleep 1
- Play music with the MacBook lid closed
Sources checked September 29, 2026: Apple's accessory and closed-lid guidance, the Amphetamine App Store listing, LidRun pricing and LidRun FAQ, the KeepingYouAwake README, and the macOS caffeinate(8) and pmset(1) manuals. Clamshell details come from its own documentation. Clamshell is the publisher of this guide. Product names belong to their respective owners. Rechecked October 15, 2026: the Amphetamine Power Protect page and App Store listing.