# Running coding agents on a closed MacBook: what I learned about macOS sleep — retained record

> Retained reddit record from reddit:AI_Agents.

Canonical: https://highsignal.app/data/records/e9d08eaed0b1be84

[← sources](https://highsignal.app/data)


source: [reddit](https://highsignal.app/data/reddit) (reddit:AI_Agents)  published 2026-11-18 15:48 ingested 2026-11-19 02:35

[original source ↗](https://www.reddit.com/r/AI_Agents/comments/1xzij5d/running_coding_agents_on_a_closed_macbook_what_i/)

## retained text



```
Every morning a few of my agents run on a schedule: they go through the services and accounts I follow and send me a short report with news and social posts worth reading. The catch is that they run on my MacBook Air, and at night it's closed and asleep. Same story during the day with long coding runs: close the lid and the agent stops. A few things I learned while fixing this for myself:



1. Closing the lid sleeps the Mac unless it's in clamshell mode (power plus an external display). \`caffeinate\` doesn't help here: it prevents idle sleep, not lid sleep.

2. The built-in switch is \`sudo pmset -a disablesleep 1\`. It works, but it stays on until you run \`sudo pmset -a disablesleep 0\`. Forget it once and the Mac never sleeps, including in a bag.

3. "Is the agent done?" is harder than it looks. An agent in an editor thinks on a server and barely uses the CPU, so CPU load alone says the Mac is idle while it's waiting for the model. What worked better for me: count the CPU time of programs the editor or terminal started (the agent, its shells, builds, tests) and treat a minute as work if they used more than about half a second.

4. Waking up for a scheduled run works, but only on power. With the lid closed on battery, macOS wakes the Mac only briefly.



I wrapped this into a small open-source menu bar app, LidAwake (disclosure: I'm the author). It keeps an Apple silicon Mac running with the lid closed and turns that off by itself when the agent's work has been quiet for a chosen time (10 to 60 min), when a timer ends, on low battery or when macOS reports overheating. It can also wake the Mac at a set time every day and, if it's on power, keep it running until the work is done and then let it sleep. It doesn't start your agent, that's still up to your scheduler. Link in the comments, per the sub rules.



How do you handle this? Do you keep agent runs on a desktop or server, or let them run on a laptop? And how do you decide an agent is actually done?
```



document fetched 2026-11-19 00:19 · canonical https://reddit.com/r/AI_Agents/comments/1xzij5d/running_coding_agents_on_a_closed_macbook_what_i
