Skip to content
Tips & Tricks
TerminalVerified

caffeinate — Keep Your Mac Awake Indefinitely

Prevent macOS sleep with one terminal command. Perfect for long-running AI sessions, deployments, and overnight tasks.

macosterminalsleepcaffeinatechannelsimessage

What is it

caffeinate is a command built into every Mac. It tells macOS "don't go to sleep" — that's it. No install, no config, no app. Just run it in Terminal and your Mac stays awake until you stop it with Ctrl+C.

Apple developer docs on caffeinate

What problems it solves

You set up Claude Code with iMessage channels and leave your desk. Ten minutes later your Mac falls asleep, the channel dies, and messages pile up on your phone while Claude sits there doing nothing. You come back to a queue of unanswered messages.

Or you kick off a long deployment, walk away to grab coffee, and come back to find the process froze because the Mac went to sleep mid-way through.

Or you're running overnight test suites and the Mac decides 2 AM is a great time for a nap.

How to use it

The simplest version — just keep the system awake:

|terminal
# Keep the system awake (display can still turn off)
caffeinate -i

Combine it with Claude so it stops when Claude stops:

|terminal
caffeinate -di claude --channels plugin:imessage@claude-plugins-official

The flags:

  • -d = prevent display sleep
  • -i = prevent idle sleep (display turns off, system stays on)
  • -s = prevent sleep on AC power

Pro tips

The -i flag is the sweet spot for overnight use. Your screen turns off to save power, but the Mac stays awake and processes keep running.

When you combine caffeinate with another command (like caffeinate -di claude ...), it automatically stops keeping the Mac awake when that command finishes. No cleanup needed.

References