The annoying difference between idle sleep and lid-close sleep on macOS
by•
I kept seeing `caffeinate` suggested under long-running agent threads, so the short version is: it prevents idle sleep. Closing the lid uses a different macOS sleep path, which is why a build or agent can still stop the second you shut the MacBook.
If you only need to lock the screen or walk away with the lid open, `caffeinate -i` is enough. For closed-lid work, you need something that changes the lid behavior and, just as importantly, restores it afterwards. That distinction is what pushed me to build Clamshell.
Curious how other people handle long local agent jobs: leave the lid cracked, use cloud agents, or change the Mac’s sleep behavior?
46 views


Replies
Dial
my previous answer to this was `sudo pmset -a disablesleep 1` before closing the lid, then remembering to flip it back after, which is exactly the kind of manual step that gets skipped the one time you're in a rush and end up with a laptop that won't sleep on the train either. the "restores it afterwards" part is the actual product to me, not the not-sleeping part - the raw pmset flag has been sitting in terminal history for years, the annoying bit was always cleanup. does Clamshell hook into wake/lid-open to flip the setting back automatically, or is it watching for something else like AC power getting unplugged?
Clamshell
Yep, that cleanup is the whole point for me. In the default mode, opening the lid returns the Mac to normal lid behavior. Power and wake changes are handled in the background so it doesn’t quietly end up looking armed when it isn’t.
Dial
@matyasrathonyi good to know it's not a timer-based thing, since a timer would be exactly the kind of "quietly re-arms itself" bug I'd worry about. one edge case - what happens if the lid opens for a second (grabbing something out of a bag) and closes again before the wake event fully registers? does that count as a real wake, or is there a debounce so a half-second flash-open doesn't toggle the setting twice in a row
Clamshell
It doesn’t wait for a full wake or use a timer. If macOS reports a real closed-to-open transition, even a quick one, a one-close (momentary) session disarms immediately; closing it again by itself won’t re-arm it. If the lid moves so briefly that macOS never reports the open state, Clamshell can’t safely invent that edge, so it stays armed. I’m deliberately conservative there to avoid false disarms from replayed lid notifications.