Back to Blog

Keeping Your Mac Always-On for AI Agent Automation - Caffeinate and Beyond

Fazm Team··2 min read
always-oncaffeinatemacosautomationmenu-bar

Keeping Your Mac Always-On for AI Agent Automation

A pair of Reddit threads about Mac wake/sleep automation and sudo caffeinate brought up a practical issue that anyone running an AI desktop agent hits: your Mac goes to sleep and your agent stops working.

The simplest fix is caffeinate -s in the terminal. This tells macOS to stay awake indefinitely. Add sudo and it overrides even low-battery sleep. But this is a blunt instrument - your Mac stays awake even when there is nothing for the agent to do, burning power and generating heat for no reason.

Smarter Approaches

A better pattern is conditional wakefulness. The agent itself manages sleep state - it keeps the Mac awake while tasks are queued or in progress, and allows sleep when idle. On macOS, this is done through IOKit power assertions. A native Swift menu bar app can create and release power assertions programmatically, so the Mac sleeps normally when the agent has nothing to do and stays awake when it does.

You can also use macOS energy settings to prevent sleep while connected to power but allow it on battery. For a Mac Mini running as an always-on agent, this is the default setup - plugged in permanently, display off, agent running headlessly.

The Menu Bar Agent Pattern

The most practical setup for an always-on AI agent is a menu bar app that launches at login and runs in the background. It monitors your desktop passively, builds context about your workflow, and responds to voice commands or keyboard shortcuts. When you close your laptop lid, it can optionally keep running on external power or gracefully pause and resume when you open it again.

The key detail from the Reddit threads is that caffeinate alone is not enough. You also need to prevent the screensaver from activating (it can interfere with screenshot-based agents), handle network reconnection after sleep (your MCP connections will drop), and manage state persistence so the agent picks up where it left off.

For anyone running background automations - scheduled file organization, periodic email processing, or continuous monitoring tasks - the always-on setup transforms an AI agent from a tool you use occasionally into infrastructure that works for you around the clock.

Fazm is an open source macOS AI agent. Open source on GitHub.

Related Posts