Keep your Mac awake with the lid closed (no password) — for Claude Code, Cursor, Ollama, and music
Close the lid on a MacBook and your running task — or your music — stops. The reason is that macOS has a separate lid-closed sleep path, distinct from idle sleep. This post explains it and a way to keep going that needs no password.
Why the built-in settings can't do it
The "never sleep" option in Energy Saver only affects idle sleep: the screen can turn off while the system stays awake. Lid-closed sleep is a different kernel path, and ordinary power assertions (the equivalent of the built-in caffeinate) can't block it. So you get:
- Lid closed → the Mac sleeps → downloads, builds, and AI agents all stop;
- Remote connections drop, because the Mac isn't online;
- Music stops the moment you close the lid.
The classic workaround is sudo pmset -a disablesleep 1, which needs an admin password, writes a persistent system setting, and is easy to forget — leaving the Mac running hot in a bag.
The no-password way: session-level lid-closed control
macOS's power manager (IOPMrootDomain) exposes an interface that can temporarily "skip lid-closed sleep" with no root and no permission prompt. Two properties matter:
- Session-level: valid only while the app runs, and released on quit / crash / restart — no persistent change is left behind;
- No authorization: no admin password, and no system setting is modified.
HeyWakeup's Awake When Closed is built on exactly this. First use requires zero authorization, and your task keeps running with the lid shut.
Start and stop by scenario, not always-on
Staying awake forever works, but doing it on demand is much friendlier. HeyWakeup splits automation into two layers:
- Conditions decide when to start: program running / device busy / audio playing / remote control (or a specific app). Choose any or all to match; it lets go when the conditions clear.
- Scope constraints decide when it must not start: AC power only / battery only / a time window. All constraints must pass; otherwise the scene won't start, and an active session ends immediately.
What it can watch:
- Program running:
claude,codex,cargo,rustc,xcodebuild,ffmpeg… stays awake for long tasks and AI agents, and lets go when they finish; - Audio playing: detects whether the system is outputting audio (browser playback included), enabling music with the lid closed via Music mode;
- Remote control: stays awake while TeamViewer / AnyDesk / RustDesk / ToDesk / screen sharing runs, and releases when it quits;
- Device busy: sustained high CPU load or network throughput.
You can also switch instantly with the Scene presets: Meeting / Demo · Closed-Lid Server · Auto Tasks · Music · Remote.
Safety nets: safe to leave in a bag
Keeping a Mac awake with the lid closed draws more power and runs hotter. HeyWakeup turns on several guards by default:
- Stop on low battery (adjustable threshold), and triggers are blocked while the battery is low;
- Thermal protection: stops and latches when the device overheats, and resumes after it cools;
- Lid-closed display off: hands the screen to the system so the internal display doesn't stay lit in a bag;
- Normal sleep restored on quit / crash / restart: it never leaves the Mac in a "don't sleep" state.
Pick the right keep-awake mode
| Mode | What it does | Best for |
|---|---|---|
| Prevent Sleep | Screen may turn off; the system stays awake | Downloads, builds, backups — the most power-efficient default |
| Awake When Closed | Stays awake even with the lid closed | Running in a bag, as a server or a player |
In most cases Prevent Sleep is enough: with the screen off the CPU keeps running, your tasks continue, and you save power. “Off” is not a third mode — it just stops keeping awake. Manual and scenes are exclusive: starting manually closes the current scene, and stopping does not restore it.
Quick start
- Launch HeyWakeup — a laptop icon appears in the menu bar;
- Click it and choose Prevent Sleep or Awake When Closed, or open More › for every scene;
- For automation: Preferences → Scene → Automation, and select a scene or add a condition.
Supports macOS 12 and later, universal (Intel + Apple Silicon), with no Accessibility permission and no kernel extension.
Download HeyWakeup, or see pricing and the FAQ.
Related reading
- Use Your MacBook as a Music Player with the Lid Closed
- Keep AI Agent Runs Alive with the Lid Closed (Claude Code, Codex)
- MacBook Clamshell Mode with an External Monitor: When Do You Need an App?