Keep your Mac awake while running Claude
A long unattended run — Claude Code working through a task for an hour, a big model download, an agent grinding through a queue overnight — dies the moment your Mac idles into sleep and suspends the process. The fix is one command that ships with macOS: caffeinate. Point it at the job and your Mac stays awake until the work is done, then releases on its own.
Wrap the task so wakefulness ends with it
The cleanest way is to hand your command to caffeinate. It runs the command, holds an assertion against idle sleep the whole time, and lets go the instant the command exits — no timers to guess, no toggle to remember to switch back off.
# Keep the Mac awake for exactly as long as this runs
caffeinate -i claude
The -i flag prevents idle system sleep, which is what would otherwise pause your run. The display is still free to dim and switch off — that's fine, since the CPU and network keep working with the screen dark. When Claude finishes and the process ends, the assertion is released automatically and your Mac goes back to its normal sleep schedule.
Or hold it awake by hand
If the work isn't a single command — say you're driving an interactive session, or several jobs back to back — open a spare Terminal tab and start caffeinate on its own. It stays awake until you stop it with Ctrl-C.
# Stay awake until you press Ctrl-C
caffeinate -i
# Add -d to also keep the screen on, to watch progress
caffeinate -i -d
Add -d when you want the display itself to stay lit — handy if you're glancing over at streaming logs. Leave it off to let the screen sleep while the machine keeps running. Either way, that one tab is now the switch: close it or hit Ctrl-C and sleep is allowed again.
Give it a deadline
When you know roughly how long the run needs, put a timeout on it so you can walk away without a caffeinate process lingering for the rest of the day.
# Stay awake ~1 hour (3600 seconds), then release automatically
caffeinate -t 3600
# Combine flags: no idle sleep for two hours
caffeinate -i -t 7200
The -t value is plain seconds — 3600 for an hour, 28800 for a full overnight window. When the timer expires, the assertion drops and the machine is free to sleep again exactly as before.
Attach to a job that's already running
Started the run before you thought about sleep? You don't have to restart it. Find the process ID and tell caffeinate to hold on until that specific process exits with -w.
# Look up the process id, then keep awake until it exits
caffeinate -i -w 4821
A quick note on the flags you'll actually reach for: -i blocks idle system sleep, -d keeps the display on, -m keeps the disk from idling, and -s forces the system awake but only works on AC power — on battery it's ignored, so stick with -i. There's no defaults setting for any of this; the System Settings route is only the coarse display-off and sleep timers under Lock Screen and Battery, which change your Mac's behaviour permanently rather than for one run.
Rather not keep a Terminal tab open just to babysit a run? Mainspring's Keep Awake power-up runs caffeinate for a duration you pick and auto-expires when it's done — one of 90+ hidden macOS settings it turns into labelled, reversible toggles.
Try Mainspring free →Signed & notarized by Apple · 1-day free trial · $29 once
Go deeper on the tool
caffeinate has a few more flags worth knowing — asserting user activity, waking the display, chaining behaviours. Our full guide to caffeinate on Mac walks through each one with examples.