I usually run coding agents somewhere in a VM or on a remote host, so I don’t have to think about what my laptop is doing.
But sometimes, especially for bigger tasks, I need to run an agent locally on my Mac.
And then there is one annoying problem: macOS may go to sleep while the agent is still working.
Apparently, caffeinate is a very simple way to prevent that.
Keep the Mac awake for a specific amount of time:
|
1 2 |
caffeinate –t 3600 |
This keeps it awake for 1 hour (3600 seconds).
For a quick test:
|
1 2 |
time caffeinate –t 10 |
And if you want to prevent pretty much all kinds of idle sleep while the command is running:
|
1 2 |
caffeinate –dimsu |
Simple, built into macOS, and surprisingly useful when running long AI agent tasks, builds, migrations, or anything else you don’t want interrupted by sleep.
