← Back to feed
Project Mac App

Midnight Oil

A menu-bar app that keeps a MacBook awake with the lid closed so a Claude Code Remote Control session stays reachable — with guards so a laptop in a bag can't drain itself flat.

Midnight Oil

Close the MacBook lid and every Claude Code Remote Control session goes dead — the machine sleeps, the process freezes mid-execution, and the phone shows a session that can't answer. Midnight Oil keeps the Mac awake with the lid shut so those sessions stay reachable, and watches battery, heat and network so a laptop in a bag can't quietly drain itself flat.

It lives in the menu bar. One switch turns it on; everything else is a guard that turns it off again when staying awake stops being a good idea.

The Midnight Oil menu, showing the hold active, battery, thermal and network state, and each guard as a toggle.
The whole app. Header shows how long the hold has run; every guard is one line.
Awake with the lid closedHolds the kernel sleep flag so shutting the lid doesn't end the session. Works on the built-in display alone — no external monitor, no dock, no dummy plug.
Battery floorReleases the hold and sleeps the Mac at 25% by default. macOS's own floor is 1%, which is far too late to protect a laptop that's been sitting in a bag.
Thermal cutoutBacks off after 60 seconds of sustained thermal pressure. The dwell matters — a spike during a compile shouldn't drop the hold mid-task.
Network awareA session offline for ten minutes exits anyway, so an unreachable Mac has nothing to stay awake for. The hold is released after five minutes offline and the machine sleeps after thirty.
Knows when you're doneCounts live Claude sessions by checking the process table, not stale files on disk. No sessions left, nothing worth burning battery for.
Status on your phonePosts battery, power source and network to a private feed each hour, so you can check on the machine from anywhere without opening a session.

Guards that trip on a condition re-arm themselves once it clears — plug back in and the hold returns on its own. An explicit switch-off stays off.

How the guards work

STATE MACHINE Lid-close: Sleeps normal macOS behaviour Holding awake shut the lid, session survives switch on ANY GUARD TRIPS · battery below your floor (25%) · sustained heat for 60s · adapter unplugged, if required · no live Claude sessions · offline for 5 minutes · auto-off timer elapsed Release the hold Lid closed → sleep the Mac clearing the flag alone would not Lid open → leave it you're sitting there Parked — waiting for the condition condition clears — re-arms itself

Two things that had to be measured

caffeinate cannot do this. Power assertions don't defeat clamshell sleep. Proven on the machine rather than taken from documentation: an unrelated app held a sleep-prevention assertion for 12 hours 23 minutes, and the Mac still slept three times inside that window. Only the kernel flag works, which is why the app needs a narrow privilege grant — three literal pmset commands, no wildcards.

Releasing the hold doesn't sleep a closed Mac. Clamshell sleep is evaluated at the moment the lid closes, so clearing the flag afterwards only re-arms it for the next close. Measured: flag cleared, and the Mac was still awake eight minutes later with the lid shut. That single fact made every guard decorative — hit the battery floor in a bag, "release", and keep draining to zero. The guards now actively sleep the machine, but only when the lid is closed, so one tripping at your desk never sleeps a Mac you're using.

Built in a day, mostly as an exercise in not trusting inference. The design changed twice because a measurement contradicted something that seemed obviously true.

Swift · macOS