sleep-when-done

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.

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

  1. 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.

  2. 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.

  3. 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

sleep-when-done statusWhat it's doing, and every live session
sleep-when-done disableTurn it off. Closing the lid sleeps the Mac right away again.
sleep-when-done disable 2hTurn it off for a while
sleep-when-done enableTurn it back on
sleep-when-done hotspotHow macOS can switch to your phone's hotspot, and the setting to turn on
sleep-when-done logWhat it did, and why
sudo sleep-when-done uninstallRemove everything

Safety