To keep your Mac awake while AI agents work, you need something that stops it from sleeping when you step away. A coding agent can run for an hour without a single click or key press, and to macOS that can look like an idle computer.
This guide covers two ways to keep the work going: a one-line Terminal command for a single run, and a free menu bar app for everyday use.
Why agents stop when your Mac sleeps
When your Mac sleeps, running programs pause and network connections drop. An agent in the middle of a task cannot reach its model, run your tests or finish its edits until the Mac wakes, and the run may fail when its connection is lost.
How soon this happens depends on your sleep settings. You could turn automatic sleep off for good, but then your Mac also stays on when nothing is running.
Option 1: Start the agent with caffeinate
Every Mac includes a tool called caffeinate. Put it in front of the command that starts your agent:
caffeinate -i your-agent-command
For example, this starts Claude Code and keeps the Mac awake until you exit it:
caffeinate -i claude
The -i option prevents idle sleep. When the command ends, your Mac goes back to its usual settings.
If the agent is already running, find its process ID and wait on that instead:
caffeinate -i -w 1234
This costs nothing and installs nothing. You do have to remember it each time, and it only covers agents you start from a terminal.
Option 2: Use Easy Caffeinate
Easy Caffeinate is a free menu bar app that runs the same built-in tool, with a coffee cup you can click. It also works for agents inside a code editor or desktop app.
Stay awake whenever your tools are open
If you use agents most days, set this up once:
- Right-click the cup and choose Settings….
- Open the Automation tab.
- Under Stay awake while these apps are running, click Add App….
- Choose your terminal, such as Terminal or TerminalSpace, or your code editor, and click Add.
Your Mac now stays awake whenever one of those apps is open, and sleeps normally once they have all quit.
Stay awake for one long job
Right-click the cup when you want something more specific:
- A timer runs from 15 minutes to 8 hours, or any length you choose.
- Until a Time… suits an overnight run: set it to 7:00 AM and your Mac can sleep after that.
- While an App Is Running keeps it awake until the app you pick quits.
Which one should you use?
| Your situation | Best option |
|---|---|
| One agent run from a terminal | caffeinate -i |
| You use agents most days | Easy Caffeinate with Automation |
| An agent inside an editor or desktop app | Easy Caffeinate with Automation |
| A job you are leaving overnight | Easy Caffeinate with Until a Time… |
Settings for long runs
Let the screen sleep
Most agents do not need the display. In Easy Caffeinate, turn off Keep the display on in Settings > While Awake to save power while the work continues. Leave it on for an agent that needs to see or control your screen.
Stay plugged in
A long run uses real power, so keep the charger connected. If you do work on battery, Turn off when the battery gets low in the Battery tab protects your charge. When that rule ends the session, your Mac can go to sleep and the agent stops with it.
Leave the lid open
Closing a MacBook's lid normally puts it to sleep, so the simplest setup for a long run is to leave it open. Apple's supported way to work with the lid closed uses power, an external display, and an external keyboard and mouse.
Common questions
Does this work with any AI agent?
Yes. Easy Caffeinate keeps the whole Mac awake and does not connect to your agent, so it makes no difference which tool you use.
Does Easy Caffeinate know when my agent has finished?
No. It follows apps and timers, and it does not read what an agent is doing. If the agent finishes and its app stays open, your Mac stays awake until you quit the app or click the cup. To stop exactly when a command ends, use caffeinate -i with that command.
Does keeping my Mac awake use more power?
Yes, an awake Mac uses more power than a sleeping one. Letting the display sleep and setting an end time both keep the extra use down. For more ways to control this, see how to keep your Mac awake.