Will Claude Code keep running overnight if I close my MacBook?
Not by default: the closed lid puts the Mac to sleep and the claude process stops with it. How to keep it working until morning.
A short answer from the Keep Mac Awake team, written with the help of an AI writing program and checked against the sources linked below.
Short answer: Not by default. Closing the lid puts a MacBook to sleep, and Claude Code runs only while the Mac is awake. To leave it working overnight with the lid closed, the first choice is Keep Mac Awake: start a session from the menu bar or with
keepmacawake start --hours 8before you close the lid. It works on a MacBook with Apple silicon on macOS 26 or later, needs no external display and runs on AC power or on battery down to a floor (20% by default).
Download Keep Mac Awake for Mac (free trial; Apple silicon, macOS 26 or later).
What happens to Claude Code when the lid closes?
Claude Code is a process on your Mac: it reads your files, runs your commands and talks to Anthropic's API from there. Apple lists closing the display as one of the ways to put a Mac laptop to sleep (Apple Support), and Claude Code does not run while the Mac sleeps. When you open the lid in the morning, Claude Code notices the dropped connection (its error reference lists Your computer went to sleep mid-response) and retries where it can (Claude Code errors), but the night is lost.
Why doesn't the usual keep-awake trick cover it?
Most keep-awake settings stop idle sleep, the timer that runs while nobody touches the Mac. The lid is a different sleep reason. Apple's documentation for the common idle-sleep power assertion says "The system may still sleep for lid close" (Apple developer docs). caffeinate keeps a closed Mac from sleeping only with -s on AC power, and then in dark wake. Closed-display mode works too, but it needs an external display, keyboard, mouse and power.
A setup for one night
- Plug the MacBook into power and put it on a desk with air around it, never in a bag.
- Start the session:
keepmacawake start --hours 8(or pick 8 hours in the menu bar). - Give Claude Code its task in the terminal, then close the lid.
- In the morning,
keepmacawake statusshows whether the session is still running or has ended; when it ends, normal sleep returns.
A separate watchdog restores the normal sleep setting if Keep Mac Awake's background service or the system service stops or hangs. Keep Mac Awake keeps the Mac awake, not the network: it does not keep Wi-Fi alive or wake a Mac that is already asleep, and Claude Code still needs its connection to Anthropic. It also does not answer Claude Code's permission prompts, so allow the commands the task needs before you leave.
The full guide, with a hook that lets Claude Code start and stop the session itself, is on keepmacawake.com: how to keep Claude Code running with the MacBook lid closed.
About the author
- Keep Mac Awake is a Mac menu bar app and command line tool that keeps a MacBook awake with the lid closed for a session you start. These guides explain Mac sleep, pmset and long jobs with the lid closed, and first appear on keepmacawake.com.
Comments
Join the discussionNo comments yet. Be the first to comment.
