DEV Community

Eli
Eli

Posted on • Originally published at aiglimpse.ai

New Mac Tool Lets AI Agents Keep Laptops Awake Without Draining Batteries

Adrafinil intelligently prevents sleep only during agent execution, solving a workflow problem that has developers awkwardly propping open their MacBooks.

A developer has created an open-source macOS utility that addresses an increasingly common frustration in AI-assisted development: keeping a laptop awake while running autonomous agents without sacrificing battery life during downtime.

According to Hacker News, the tool, called Adrafinil, tackles a problem that emerged as engineers began relying more heavily on AI coding assistants. The issue arose because closing a MacBook lid typically triggers sleep mode, which halts background processes including AI agents performing autonomous tasks. This prompted some developers to resort to inelegant workarounds, such as manually propping their laptops partially open while working in cafes or parks.

Selective Sleep Prevention

Adrafinil differs from existing sleep-prevention solutions by activating selectively. Rather than keeping a machine perpetually awake (as traditional tools like caffeinate do), it monitors activity from AI agents integrated into Claude Code, Codex, and similar platforms. The utility only prevents sleep when an agent is actively executing tasks, then allows the system to resume normal sleep behavior once the work completes.

The mechanics rely on modifying macOS power settings through the pmset command. When an agent begins working, Adrafinil sets disablesleep to 1. Upon completion, it reverses this setting, returning disablesleep to 0 to permit sleep mode. The application also includes thermal safety features, allowing sleep to resume if the system overheats.

Technical Implementation and Trust

The architecture separates privileged and unprivileged components. Four binary files handle different functions, with one operating as a root helper that exposes a single setSleepBlocked call. By concentrating elevated permissions narrowly, the designers kept policy logic in the unprivileged portions where auditing becomes simpler.

Security considerations shaped the distribution approach. All binaries carry Apple notarization, and the entire codebase is publicly available under an MIT license. This transparency allows security-conscious users to verify the tool's behavior before installation.

User Control and Customization

The interface provides visual feedback through menu bar indicators showing when the tool is actively preventing sleep. An audible chime confirms when the lid closes, giving users reassurance that the mechanism functions as intended. For users needing manual override capabilities, an optional Model Context Protocol integration allows agents to maintain wakefulness for specified durations through direct commands.

The project emerged from developer feedback about existing solutions proving inadequate. Some cited frustration with alternative sleep-prevention apps that proved difficult to disable, resulting in dead batteries when forgotten in bags. Others simply needed occasional sleep prevention rather than constant availability, making a blanket solution impractical for their workflows.

Adrafinil represents a growing class of productivity tools tailored specifically to the operational patterns created by agentic AI systems. As these autonomous workflows become more prevalent in development environments, utilities designed around their specific requirements may become standard fixtures in developer toolkits.


This article was originally published on AI Glimpse.

Top comments (0)