caffeinate command builder

macOS can keep itself awake from the Terminal. Nobody remembers the flags. Pick what you're doing and copy the command.

What are you keeping awake for?

For how long?

The screen?

caffeinate -dimsu

What this command can't do

caffeinate is a blunt instrument. It holds a power assertion and nothing else. It has no idea what your Mac is doing, and it will not stop on its own.

A warning about the other command people use. If you search this problem you will find sudo pmset -a disablesleep 1. Do not use it casually. Unlike caffeinate, that changes a permanent system setting. It stays on after you close the terminal, after you log out, and after you reboot, until you explicitly turn it off. That is how people end up with a laptop running hot in a bag.

The safe version

One click, and it knows when to stop

Awake does everything the command does, from a menu bar switch, plus the things it structurally cannot: it keeps running with the lid closed, and it looks after your machine while you are away.

 caffeinateAwake
Keeps the Mac awakeYesYes
Setup each timeType the commandOne click
Survives closing the terminalNoYes
Works with the lid closedNoYes
Stops before your battery diesNoYes, at 20%
Stops if the Mac gets hotNoYes
Shows you it's runningNoMenu bar icon
Timed sessionsFlag only30m / 1h / 5h
Download Awake for Mac

Free 3-day trial, no card. Notarized by Apple. $14.99 once, not a subscription.

Questions

How do I stop it?

Press Control-C in that terminal, or close the tab. If you backgrounded it, run pkill caffeinate. Sleep goes back to normal immediately.

How do I check it's working?

Run pmset -g assertions. You'll see the active assertions and which process owns them.

Does it work with the lid closed?

No. Closing the lid triggers a clamshell sleep that a normal assertion can't override. That needs a privileged helper, which is what Awake ships.

Will it drain my battery?

It can. caffeinate has no low-battery cutoff, so use a time limit above if you're unplugged.

Why does my Mac sleep during a Claude Code or Codex run?

macOS measures user input, not CPU load. An agent thinking with no keystrokes looks idle. More on that here.

More detail: the complete caffeinate guide · keeping your Mac awake for AI agents