Blog · October 3, 2026 · 8 min read
Running Claude Code Overnight on a MacBook: The Sleep, Lid, caffeinate and Lock Checklist
Leaving Claude Code running while you fetch coffee is a ten-minute problem. Leaving it running overnight is a different one: eight hours in which the Mac will try to sleep, the display will try to turn off, the lid might get closed, a notification will interrupt something, and whoever walks past your desk, or your kitchen table, has an unlocked machine with a live shell on it. Most overnight runs that fail do not fail because of the agent. They fail because the laptop went to sleep at 1:14 am.
This is the checklist we use. It is in order: power, sleep, the session, the lock, and what you look at in the morning. It assumes a MacBook on a current macOS, Claude Code in a terminal, and a task long enough to be worth babysitting by machine rather than by you.
1. Power: plug it in, and know what that unlocks
Everything below is easier on mains power, and some of it only works there. macOS treats battery and power adapter as two separate sets of sleep rules, and the one that stops the Mac from sleeping when the display is off (System Settings → Battery → Options → "Prevent automatic sleeping on power adapter when the display is off") is, as the name says, adapter-only. On battery, idle sleep will win eventually no matter what you set.
2. Sleep: use caffeinate, and understand its flags
caffeinate is built into macOS and is the simplest way to hold the machine awake for exactly as long as a process runs. The flags matter:
-iprevents idle system sleep while letting the display dim and turn off. This is the one you want for an agent run.-dkeeps the display on. Useful if you want to glance at the screen; wasteful if you do not.-sprevents system sleep but only on AC power; it is silently ignored on battery.-w <pid>holds the assertion until that process exits;-t <seconds>gives it a deadline.
The cleanest form wraps the agent itself, so the assertion disappears the moment the run ends:
caffeinate -i claudeTwo gotchas. Closing the terminal window drops the assertion instantly, which is why the overnight version is usually tmux new-session -d -s agent 'caffeinate -i claude' so the session outlives any window. And you can check that the assertion is actually held with pmset -g assertions; look for a PreventUserIdleSystemSleep line while the run is going, and note that it vanishes when the wrapped command exits.
3. The lid: do not close it
This is the one that catches people. caffeinate does not override lid-close sleep, and neither does VibeLock; its security model page says so plainly. A MacBook with the lid shut stays awake only in clamshell mode, which needs an external display and the power adapter, or a third-party tool that overrides the lid behaviour. If you have neither, leave the lid open, let the display turn off on its own, and accept that the laptop is going to sit there glowing faintly all night.
4. The session: make it survivable and make it tell you
- Run under tmux or screen so an accidental window close, or a terminal app update, does not end the run.
- Decide permissions up front. A run that stops at 2 am to ask "allow this command?" has wasted six hours. Either scope the task so it needs nothing outside its allow rules, or accept the risk of a broader mode consciously; do not discover the prompt in the morning.
- Get told when it finishes or stalls. A done notification to your phone means you are not setting an alarm to check. Tools like AI Done Now or NotchFit do this from Claude Code's hooks; a bare
Stophook that pings you works too. - Silence everything else. Turn on a Focus mode. Notification banners are drawn by macOS, not by hidden apps, so they will still appear on screen even with VibeLock engaged; a Focus keeps them off the display where a passer-by could read them.
5. The lock: screen on, inputs off
The ordinary macOS lock (⌃⌘Q) protects the machine but blanks the display, so you cannot see at a glance whether the run finished or hung; and more importantly for an overnight run, the lock screen does nothing to stop the Mac sleeping. That is what VibeLock is for. On lock it blocks every keystroke, click, scroll and system shortcut with a session-wide event tap, hides every app that is not on your Visible While Locked list behind an opaque backdrop, blocks Spotlight, Force Quit and ⌘Q so nobody can kill your agent, and holds a "no display sleep" power assertion for as long as it is locked. Your terminal stays readable; nothing else is reachable.
For an overnight run specifically, three settings are worth a thought:
- Keep the visible list short. Anyone can read what your visible apps show, including secrets an agent prints in the terminal. If the task involves credentials, let it log to a file rather than the screen, or do not mark the terminal visible at all and rely on the phone notification instead.
- Leave the accessible list empty. "Accessible While Locked" exists for pair sessions where a colleague approves a prompt at your desk. Overnight, there is no colleague, and an accessible terminal gives anyone a shell.
- Know the escape hatch. If something goes wrong and you are not there,
ssh you@your-mac killall VibeLockfrom another device releases the input block instantly. Keep SSH on if that matters to you; it is also the documented reason VibeLock is not a defence against someone with remote access.
VibeLock keeps the display awake but, to say it again, does not override lid-close sleep and does not replace caffeinate for idle sleep once the display has turned off. The three work together: caffeinate -i for the system, VibeLock for the display and the inputs, the adapter for both.
6. Where the machine is
An overnight run at home is one risk profile; at a shared office, a hotel desk or a café that stays open late is another. VibeLock is a strong deterrent against the casual case, the curious kid or the colleague who wants to see what you are up to. It is not a defence against someone who takes the laptop, boots it into recovery, or long-presses the power button into a forced shutdown (which ends up at the real login screen but also ends your run). The security model page lists every one of those limits. For a shared space, FileVault and a locked drawer are the controls that matter; for your own flat, the checklist above is plenty.
7. The morning
Unlock with Touch ID or your login password typed into VibeLock's shield. Before you read the agent's summary, check two things: pmset -g log | grep -i sleep tells you whether the Mac slept at any point in the night, and the tmux session's scrollback tells you whether the run paused for a permission you did not expect. If both are clean, the overnight setup is working and you can stop thinking about it. If the Mac slept, it was almost always battery, the lid, or a terminal window that got closed; fix that one thing rather than adding more tools.
Related
For the shorter version of the same problem, stepping away for twenty minutes rather than eight hours, see leaving Claude Code running while you are away. For why an unlocked Mac with a live agent is a bigger exposure than it looks, the vibe coding security post walks through the threat model.