macOS can be configured to avoid idle sleep, but closing a MacBook lid still stops long-running coding agents, SSH sessions, and background jobs. I wanted my MacBook to keep working as an agent machine without leaving the display glowing inside the closed lid.
I built a small, reversible shell setup for that.
What it changes
- Disables idle sleep with
pmset - Prevents lid-close system sleep
- Watches
AppleClamshellStateevery two seconds - Turns off only the display when the lid closes
- Runs the watcher through a macOS LaunchAgent
- Includes an uninstall script that restores normal sleep behaviour
Install
git clone https://github.com/apoorvdarshan/macbook-24x7-agents.git
cd macbook-24x7-agents
./install.sh
After installation, closing the lid leaves Claude Code, Codex, SSH sessions, and other background processes running while the display switches off.
Revert everything
./uninstall.sh
Important caveats
Keep the MacBook plugged in, give it proper airflow, and remember that manual Sleep will not work while disablesleep is enabled. This is intended for a stationary machine running long-lived jobs, not for carrying a running laptop inside a bag.
Repository and full explanation:
https://github.com/apoorvdarshan/macbook-24x7-agents
Top comments (0)