Claude Code stops when you close your MacBook? Here’s why
You start a long run, close the lid, catch your train. Forty minutes later Claude is exactly where you left it. Here is what happens, and how to keep a run going.
Short answer. Claude Code runs on your Mac but thinks in the cloud: it needs the Mac awake and online the whole time. Closing a MacBook puts it to sleep, the connection drops and the run stalls. Keep the Mac awake with the lid closed, keep it online, and don’t let the session wait for a permission nobody can give.
What actually happens when you close the lid
On sleep, macOS freezes running processes and suspends the network. Claude Code is mid-way through a streamed response from the API; the stream breaks. When the Mac wakes up, the session may resume, retry, or fail with a timeout. A Claude Code issue on GitHub, “Subagents killed by stream-idle watchdog when host laptop sleeps”, describes the worst case: subagents killed after about ten minutes with “Stream idle timeout”. A bot comment there says that specific bug was fixed in version 2.1.126, but the basic problem remains: a sleeping Mac doesn’t work.
1. Keep the Mac awake with the lid closed
This is the hard part, because a MacBook on battery sleeps on lid close regardless of caffeinate. Your options, from Apple’s closed-display mode to pmset and menu bar apps, are compared in how to keep a MacBook awake with the lid closed.
If you’re at a desk and the Mac is plugged in, the simplest fix is not to close it at all:
caffeinate -i -w $(pgrep -n claude) # awake until that Claude Code process exits
Run it in a second Terminal tab. It ends by itself when Claude Code does.
2. Keep it online
An awake Mac without internet is as stuck as a sleeping one. When you leave home you lose your Wi-Fi: turn on your phone’s hotspot before you close the lid, and make sure the Mac joined it.
3. Don’t leave it waiting for a permission
If Claude asks to run a command and nobody answers, the session simply waits, lid closed or not. Two ways round it:
- Pre-approve what you trust. Claude Code lets you allow specific tools and commands in its permission settings, so routine steps don’t stop the run. Read Anthropic’s settings documentation before loosening anything, and keep risky commands on “ask”.
- Get told on your phone. If you know Claude is waiting, you can open the Mac at the next stop instead of finding out an hour later.
4. Watch the battery and the heat
Claude Code itself is light on your Mac, because the model runs on Anthropic’s servers: in 20 closed-lid runs on battery logged by Hibernot, a 13-inch MacBook Air drew 0.5 to 8.0 W on average. Builds, tests and video exports are not light. A closed bag holds heat, so set limits: a maximum time, a battery floor, a temperature stop. The measurements are in is it safe to put a running MacBook in a backpack?
5. Let it sleep when Claude is done
Once the run is over, the Mac should go back to normal sleep by itself. Otherwise it keeps burning battery in your bag for nothing. With caffeinate -w that’s automatic; with pmset disablesleep it isn’t (how to undo it).
How Hibernot handles it
Hibernot is made for this. It keeps a MacBook awake with the lid closed without a password, sees Claude Code through its hooks (and the Claude desktop app from its network activity), and puts the Mac back to sleep 5 minutes after Claude stops working. A session waiting for a permission counts as stopped, and your phone gets a notification for it. It also stops at the battery temperature you choose, 42 °C by default. It’s one option among several; the free methods above work too if you remember to undo them.
Still stuck? Check whether the Mac slept
If a run stalled anyway, Terminal can tell you when and why the Mac slept: see did my Mac sleep with the lid closed?