Free & open source · MIT license

Keep your MacBook awake with the lid closed.

Lid closed, in a bag, on battery, no external display: your processes, SSH sessions, dev servers and AI coding agents keep running as if the lid were open. One switch in the menu bar for you, three commands for your agents.

No release yet — the first build ships right after the closed-lid battery test on the target M4. Until then, build it yourself: scripts/build.sh.

macOS 14+ Apple Silicon Swift, zero dependencies No telemetry, no network

How it works

One flag the kernel already trusts

caffeinate and sleep assertions stop idle sleep, but not the sleep macOS triggers the instant the lid clicks shut. Shutlid uses the one setting the kernel checks before every kind of sleep, including that one.

1

Turn on

From the menu bar, or shutlid on from an agent. One admin authorization the first time; never again after that.

2

Close the lid

The system-wide sleep veto is already set. No external display, keyboard or mouse required — on battery or AC.

3

Auto-off has your back

24 hours by default, or off entirely with shutlid off. A restart always returns to normal sleep.

Built to be boring

Small, reviewable, hard to break

Reliability first. One file talks to macOS power management. Everything else is plain, readable Swift with no dependencies to rot.

Isolated privilege

Setup installs a sudo rule scoped to five literal commands: the sleep flag on or off, and the battery Energy Mode. After that, no custom code ever runs as root.

Auto-off safety net

24 hours by default, adjustable from 1 hour to never. And while the lid is closed, the battery switches to Low Power Mode so a bag stays cooler.

Built for AI agents

Three commands, stable exit codes, no GUI automation and no password prompts after setup.

Restarts to normal

A reboot always returns to normal sleep by default, whether or not the app is even opened.

Honest status, always

status reads the kernel fresh every time. If macOS isn't preventing sleep, it says so.

~1,300 lines, zero deps

Swift Package Manager, no Xcode project, no third-party packages. Understandable in fifteen minutes.

For humans and agents alike

Three commands, one honest status line

The CLI is the agent interface: no GUI automation, no interactive prompts after the one-time setup. Results go to stdout, errors to stderr, and exit codes are documented and stable.

zsh — shutlid
# an agent, mid-task
$ shutlid on
Requested:  ON
Effective:  ON
Mode:       always
Auto-off:   in 23h 59m

# hours later, job done
$ shutlid off
Requested:  OFF
Effective:  OFF
Mode:       always
Auto-off:   24h
usage
shutlid on [--for <hours>]
shutlid off
shutlid status
shutlid setup
shutlid log
Command012
on, offdoneerrorsetup required
statuskeeping awakenormal sleep—

Why not just…

How Shutlid compares

Sourced from the full write-up in RESEARCH.md, including every approach that was tried and rejected.

ApproachSurvives lid closeWorks on batteryNeeds a display/peripheralExtra moving parts
ShutlidYesYesNoNone
caffeinate / sleep assertionsNo—NoNone
Apple clamshell modeYesNoDisplay + AC + inputNone
Virtual-display trickYesNoNoMouse jiggle, assertions, virtual display

Security model, stated plainly

What "one-time authorization" actually means

Full disclosure in the README: after setup, any process running under an admin account on the machine can toggle sleep prevention without a password. It cannot gain root or run anything else — see the security model for the complete threat statement.

FAQ

Questions worth asking before you install anything

Does Shutlid keep a MacBook awake with the lid closed, on battery, with no external monitor?

That is the scenario it is built for. It sets the same power-management flag the kernel checks before any sleep, so no display or keyboard needs to be attached. The on/off toggle has been verified against the real kernel flag on an M4 Pro; the physical closed-lid battery test is tracked in MANUAL_TESTING.md and reported there as it is run.

Does Shutlid ask for my password every time?

No. A one-time administrator authorization installs a sudo rule scoped to exactly two commands: turn the flag on, turn it off. After that, the app and the CLI never see a password again.

Is the underlying mechanism safe and reviewable?

Yes. Every privileged call is Apple's own pmset binary, isolated in a single source file. No custom code ever runs as root. The full investigation, including rejected approaches, is public in RESEARCH.md.

Will this drain my battery or overheat my MacBook?

A closed laptop in a bag cannot shed heat as well as an open one, and while keep-awake is on, low-battery emergency sleep is disabled too. By default Shutlid switches the battery Energy Mode to Low Power while the lid is closed and restores it when the lid opens, and it logs the battery temperature every five minutes so you can see what happened. Auto-off is on by default (24 hours) as the safety net, adjustable down to 1 hour or off entirely.

Can an AI coding agent control Shutlid without a GUI?

Yes. The CLI is the agent interface: shutlid on, shutlid off and shutlid status, with stable exit codes and no interactive prompts after setup.

How is this different from caffeinate or a virtual-display trick?

caffeinate and sleep assertions stop idle sleep but not the sleep macOS triggers when the lid closes. A virtual display can fool clamshell mode but still requires AC power and stacks extra machinery. Shutlid uses the one setting that vetoes lid-close sleep directly, with nothing else running.

What does Shutlid cost, and is it open source?

Shutlid is free and open source under the MIT license. The full source, including the research behind it, is on GitHub.

Close the lid. Keep working.

Free, open source, and built to disappear into the background.