Guide · October 2026

How to keep a MacBook awake with the lid closed

No external display, even on battery. The free way is sudo pmset -a disablesleep 1 (and 0 afterwards). Why the built-in options don't work, and how to do it safely without forgetting to undo it.

Lidnight keeps your Mac awake only while Claude Code or Codex is working, even with the lid closed, and lets it sleep when they finish.

Download freePro trial included · no card · Apple Silicon, macOS 13+

Why closing the lid puts the Mac to sleep

macOS sleeps the Mac when you close the lid. The only exception is clamshell mode, which needs a power adapter, an external display and an external keyboard or mouse all connected. That rules out cafés and commutes.

caffeinate, keep-awake apps and the “Prevent automatic sleeping when the display is off” setting stop idle sleep. Lid-close sleep is a separate mechanism, so in most setups the Mac still sleeps when you close it.

The free way: do it in Terminal

The command that also disables lid-close sleep is sudo pmset -a disablesleep 1. Turn sleep back on with sudo pmset -a disablesleep 0. The option isn't listed in man pmset, so check the current value with pmset -g | grep SleepDisabled (1 means it's on).

The catch: it's easy to forget to undo. If the Mac stays awake in your bag after the work is done, the battery drains and it heats up. The setting even survives a restart.

Check that it worked: pmset -g log | grep -E "Clamshell|DarkWake" shows when the lid closed and the wakes after it. If you use Claude Code, the free read-only script lid-check shows whether requests were recorded inside each sleep period: curl -fsSL https://raw.githubusercontent.com/whereisdw/lid-check/main/lid_check.py | python3 -

Automatically with Lidnight

Lidnight uses the same mechanism but remembers to turn it on and off for you. While AI work is running (Claude Code, Codex, Gemini CLI, Ollama and 41 more), the Mac stays awake with the lid closed, then sleeps normally when the work is done. A timer mode is there too (up to an hour, no limit in Pro).

Safety nets: it sleeps right away if the battery drops below your floor or it gets hot, like in a bag. If the app quits or the Mac restarts, sleep settings go back to normal.

You can also choose whether closing the lid locks and turns off the screen, and whether opening it shows your work right away.

Questions

Is it safe on battery with the lid closed? Yes, as long as heat can escape. A MacBook vents from the bottom and back even when closed. In a closed space like a bag, Lidnight watches the temperature and puts it to sleep.

Does it work on Intel Macs? Lidnight is for Apple Silicon Macs (M1 and later).

Try Lidnight free

Apple Silicon Macs · macOS 13 or later. Every download includes a free trial of everything in Pro (5 lid-closed runs or 14 days), no payment details needed. Pro is a one-time payment (1 Mac $9.99 · 3 Macs $14.99, 50% off through Dec 1) with a 14-day refund.

Download freeBuy Pro ›More about Lidnight ›

Homebrew: brew install whereisdw/tap/lidnight