Blog · December 4, 2026
How to leave Claude Code running overnight on a Mac
Keep the Mac from going to sleep, keep it plugged in with the lid open, and give the agent what it needs before you leave. A dark display doesn’t stop Claude Code, Codex or a build. System sleep does, and so does an agent sitting on a permission question nobody answers.
Here is the checklist we use before walking away from a long run, in the order things usually go wrong.
Why does a long agent run stop when I leave?
Two reasons, most of the time. First, macOS puts the whole Mac to sleep after a while without input, and on a MacBook, closing the lid does it right away. Sleep freezes the terminal, drops network connections, and the run just waits for you.
Second, the agent itself may be waiting. Coding agents ask before running some commands or editing files, depending on how you set them up. If a question pops up at 1 a.m., the run sits there until morning.
1. Stop the Mac from sleeping (not the display)
The display can turn off. The Mac can’t sleep. The simplest way is the built-in caffeinate command. Run it in its own Terminal tab and leave it open:
caffeinate -i
It blocks idle sleep until you press Ctrl+C. You can also tie it to one command, so the Mac is allowed to sleep again when that command ends:
caffeinate -i npm run build
A keep-awake menu bar app does the same with a click, if you’d rather not keep a tab open.
2. Keep the lid open and the charger in
A MacBook sleeps when you close the lid, whatever caffeinate says, unless it is on power with an external display, keyboard and mouse attached. So leave it open. Plug it in too: a run that goes all night on battery can drain it, and a dead battery ends the run for good.
3. Answer the questions before you go
Before you leave, look at what the task will need: running tests, installing packages, writing files in the project. Allow those in the agent’s settings for this session, so it doesn’t stop to ask. Keep the allowed list to what the task needs, and run it on a branch you can throw away if the result is bad.
It also helps to ask the agent to write a short summary to a file when it is done. In the morning you read one file instead of scrolling the whole terminal.
4. Cover the screen if other people are around
At home this step is optional. At the office or a shared desk, an open laptop with a terminal full of code is something people read when they walk past, and anyone can tap a key in your session.
That is the gap we built Possum for. It covers every display like a screensaver (black, a dimmed wallpaper or a picture you pick) and keeps the Mac awake while the cover is up, so you don’t need a separate caffeinate tab. Moving the mouse brings up a PIN pad. While it is up, the Dock, the menu bar, notification banners, Cmd+Tab and Cmd+Q are blocked. You can cover now, in 1 to 30 minutes or an hour, or on a weekly schedule.
It is not a real lock, though. Holding the power button or killing the process over SSH removes it. When you need real security, use the macOS lock screen (Ctrl+Cmd+Q) together with a keep-awake setting.
The short checklist
- System sleep off:
caffeinate -i, a keep-awake app, or Possum’s Keep Mac Awake. - Lid open, charger in.
- Permissions the task needs given up front, on a branch you can throw away.
- A summary file to read in the morning.
- The screen covered if you are not alone.
Questions
Will Claude Code keep running if my Mac's display turns off?
Yes. The display turning off does not pause anything. Work pauses when the whole Mac goes to sleep, so block system sleep for as long as the run takes, for example with caffeinate -i.
Can I close the MacBook lid and let it run?
Usually not. A MacBook sleeps when you close the lid unless it is on power with an external display, keyboard and mouse attached. Leave the lid open and cover the screen instead.
Why did my agent stop halfway through the night?
Often it was waiting for you, not asleep. If the agent asks for permission before a command or a file edit, it waits until someone answers. Give it the permissions the task needs before you leave, and check the Mac did not sleep.
Try Possum
7-day free trial with every feature, no account and no card, then $4.99 once. macOS 13 or later. Download the DMG or read more on the Possum home page.
Also on this blog: How to hide your Mac screen and keep it running.