Close the lid.
Claude keeps working.
Normally, closing your MacBook puts it to sleep, even mid-task. With sleep-when-done, the Mac stays awake until your Claude Code sessions finish, then goes to sleep.
$ sleep-when-done status Lid closed, staying awake for 14m so far. working: Fix flaky tests, Landing page Sessions working Fix flaky tests working Landing page waiting Refactor auth (needs your input; does not keep the Mac awake) 9 idle With the lid closed it gives up and sleeps after 3h, at 10% battery, or if the Mac gets dangerously hot.
Set it up
Ask your agent easiest
Paste this into Claude Code. It installs the tool, checks that it works, and walks you through the hotspot setting. You'll type your Mac password once.
Set up sleep-when-done on my Mac by following https://tonyxin.com/sites/sleep-when-done/agent.md
Or run it yourself
Downloads one bash script and installs it as a small background service.
cd "$(mktemp -d)" && curl -fsSLO https://tonyxin.com/sites/sleep-when-done/sleep-when-done && sudo bash sleep-when-done install
Needs macOS 15 or later and Claude Code. Read the script before running it.
When you close the lid
-
Claude keeps working
If any session is busy, the Mac stays awake with the screen off. Nothing new starts after the lid is closed. It only finishes what was already running.
-
Wi-Fi gone? macOS can switch
macOS can move the Mac onto your iPhone's hotspot on its own, but never while the Mac sleeps, so staying awake gives it the chance. Turn on Wi-Fi → Ask to join hotspots → Automatic. The tool can't make the switch itself. It logs when the internet drops and comes back.
-
Done, then sleep
When the last session finishes, it waits 90 seconds in case Claude starts another turn, then puts the Mac to sleep.
Commands
Safety
- Gives up and sleeps after 3 hours with the lid closed, at 10% battery, or if macOS reports dangerous heat. Ordinary throttling under load doesn’t count.
- Questions don't count. A session waiting for your answer won't keep the Mac awake, since nobody is there to answer it.
- External display? In clamshell mode it never sleeps the Mac for you.
- Fails safe. If the service ever stops, normal lid sleep comes back. As a manual reset,
sudo pmset -a disablesleep 0always works. - It never touches your Wi-Fi. Switching to your iPhone's hotspot is up to macOS, which does it only once you've left every saved network. If the Wi-Fi stays connected but loses its internet, macOS asks first, and nobody is there to answer.