To keep a Mac awake while a script runs, start the script through caffeinate: caffeinate -i ./build.sh holds off idle sleep until the script exits, then lets the Mac sleep as usual. For a command that is already running, caffeinate -i -w <pid> does the same until that process ends. Both are built into macOS. If you'd rather not remember to type them, an app can watch your terminal for you: Toolnotch's Staywake keeps the Mac awake while a terminal command is actually working, lets go two minutes after, and tells you when a long job finished while you were away.
Why the Mac sleeps in the middle of a job
macOS decides to sleep from your input, not from what the processor is doing. After the idle time in your energy settings, the display turns off and the Mac goes to idle sleep. A compile, a download or an AI agent working through a task doesn't count as you being there.
Some apps tell macOS to stay up while they work, with a power assertion. A command in a terminal almost never does, so a 40-minute build, an rsync to a NAS or a Claude Code session stops when the Mac sleeps, and you find it frozen at 60 % when you come back.
You can see who is holding the Mac awake at any moment with:
pmset -g assertions
The built-in fix: caffeinate
caffeinate ships with every Mac. It creates a power assertion for as long as it runs.
Wrap the command. Put caffeinate -i in front of what you run:
caffeinate -i npm run build
caffeinate -i ./backup.sh
caffeinate -i claude
-i prevents idle sleep. When the command exits, successfully or not, the assertion goes with it. Add -d if you also want the display to stay on, for example to watch a progress bar from across the room.
Attach to something already running. If you started the job without it, find the process ID and wait on it:
caffeinate -i -w $(pgrep -n node)
-w releases the assertion when that process exits. pgrep -n picks the newest process with that name.
Where caffeinate stops helping:
- You have to remember it before the job, or look up a PID after.
- It knows a process exists, not whether it works. A Claude Code session waiting for your answer, or a dev server idling, keeps the Mac awake all night.
- Closing the lid of a MacBook still sleeps it, unless it's on power with an external display connected (clamshell mode).
-sonly prevents system sleep on AC power and doesn't change that. - It tells you nothing when the job ends.
Amphetamine and other keep-awake apps
Amphetamine is a free keep-awake app in the Mac App Store with many triggers: while an app runs, while a file downloads, while a display is connected, and more. A trigger on your terminal app is coarse, though: Terminal is open all day, so the Mac never sleeps.
For timers and sessions you start by hand, see how to keep a Mac awake for a set time.
Staywake: awake while the command works, asleep after
Staywake is the keep-awake part of Toolnotch. Its automatic mode watches the commands in your terminal windows and keeps the Mac awake only while one of them is doing something. It's on by default; the switch is « A terminal command is working » in Settings › Staywake.
What counts as working: the command and everything it started, measured together over the last minute, use at least a few percent of one processor core or read and write the disk steadily. Measured on real sessions, Claude Code waiting for input uses about 1 % of a core and 5 to 11 % while it works, so a session waiting for you doesn't hold the Mac awake, and one that's thinking does.
It works in Terminal, iTerm, Ghostty, Warp, kitty, Alacritty, WezTerm, and the terminals of VS Code, Cursor and Zed. make, xcodebuild, ffmpeg, rsync, a Python script and an AI agent are all just commands that work: there's no list of tools to maintain.
When the last command stops working, the Mac stays awake two more minutes, so a test run that pauses between steps isn't cut off. Then your normal sleep settings apply again. A command that stays quiet for a minute, or exits, counts as finished.
You see it in the hub
Click the notch (or press ⌃⌥N) to open the hub. In its footer, left of Settings, Notchi's head is awake in orange and looks at the name of what works: « claude », or « claude +1 » when two commands work at once. Hover it for « Awake while claude works ».
It tells you when a long job is done
If a job worked for at least five minutes, and at some point you were away (no keyboard or mouse for two minutes), the notch tells you when you come back: « claude finished · 42 min », with a Show button that brings the terminal window forward. If you're at your desk when it ends, you're told right away. A short job or one you watched the whole time ends quietly.
Commands you don't want counted
Click Notchi in the hub's footer while a job keeps the Mac awake:
- « Not this time » lets that run go, until it exits.
- « Always ignore npm run dev » (with the command's name) stops it from counting ever again. Ignored commands are listed in Settings › Staywake, where you can remove them.
For apps that work outside a terminal, such as a video export, a 3D render or a backup, add them under « Apps that work alone » in the same settings page. They're measured the same way.
Screen and battery
The automatic mode prevents idle sleep; the display can still turn off, which doesn't stop the job. Turn on « Keep the screen on » in the hub menu if you want it lit. With « Stop when the battery is low » on (the default), the automatic mode pauses when a MacBook on battery reaches 20 % and resumes on power.
Limits worth knowing
- tmux and screen. Commands inside a tmux or screen session aren't seen, because their processes don't belong to a terminal window. Use
caffeinate -iinside the session. - The lid. Like caffeinate, Staywake doesn't keep a closed MacBook awake without an external display and power.
- Jobs that work in bursts. A command that idles for more than a minute between bursts counts as finished during the gap. The two-minute grace covers most test suites and builds; a job that sleeps for ten minutes between steps needs a manual session.
Setting it up
- Download Toolnotch from toolnotch.app and open it. It runs on macOS 15 Sequoia or later.
- Nothing to configure for terminal jobs: the automatic mode is on. Start a long command and open the hub to see Notchi watching it.
Staywake comes with every Toolnotch licence, alongside the clipboard history, window manager and break reminders (pricing).
FAQ
Does Staywake replace caffeinate?
For terminal jobs, mostly. It starts and stops by itself and only counts commands that work. caffeinate is still the right tool inside tmux, in scripts that run on a schedule, or on a Mac without Toolnotch.
Will it keep my Mac awake all night because a dev server is running?
Only while the server does something. An idle dev server uses almost no processor time, so it doesn't count. If yours stays busy, use « Always ignore » on it.
Does the Mac stay awake with the lid closed?
Not with Staywake. Closing the lid sleeps a MacBook unless it's on power with an external display, and Staywake doesn't change that. Some keep-awake apps, such as Amphetamine, offer a closed-lid option; see Toolnotch vs Amphetamine.
Can I see that Staywake is holding the Mac awake?
Yes. Its power assertion is named « Toolnotch Staywake » in pmset -g assertions, and the hub's footer shows Notchi awake with the command's name.
Does it work on a Mac without a notch?
Yes. The hub and messages hang from the middle of the menu bar, and ⌃⌥N opens the hub.