• How to Keep Your Mac Awake for Long-Running Agent Tasks

    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:

    This keeps it awake for 1 hour (3600 seconds).

    For a quick test:

    And if you want to prevent pretty much all kinds of idle sleep while the command is running:

    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.