Adrafinil Keeps Mac Awake for AI Agents, Prevents Sleep

kageroumado· June 27, 2026 View original

Summary

Adrafinil is a new open-source macOS tool that prevents a MacBook from sleeping, even with the lid closed, but only when AI agents like Claude Code or Codex are actively running. It automatically allows the laptop to sleep once agent activity ceases, addressing a common issue for engineers using local AI.

Engineers often face a challenge when running AI agents locally on their MacBooks: closing the lid forces the machine to sleep, interrupting ongoing tasks. While existing solutions like `caffeinate` or Amphetamine prevent sleep, they require manual management and can lead to battery drain if forgotten. Adrafinil offers a targeted solution by intelligently keeping a MacBook awake only when specific AI agents, such as Claude Code or Codex, are actively processing. It achieves this by installing hooks to detect agent activity and using `pmset disablesleep 1` to override lid-closed sleep behavior, even without external power or display. The application provides visual feedback in the menu bar and an audio chime upon lid closure to confirm its active status. Crucially, Adrafinil automatically re-enables sleep (`pmset disablesleep 0`) once agent activity stops or if the device begins to overheat, preventing unnecessary power consumption. It's open-source, notarized, and includes a root helper for necessary system-level control while keeping core logic unprivileged.

Why it matters

This tool directly addresses a productivity bottleneck for AI engineers who need to run local agents without constant supervision, ensuring tasks complete efficiently without manual intervention or excessive battery drain.

How to implement this in your domain

  1. 1Download and install Adrafinil on your macOS development machine.
  2. 2Configure the tool to monitor your specific AI agents (e.g., Claude Code, Codex) by ensuring the necessary hooks are installed.
  3. 3Test the functionality by initiating an AI agent task and closing your MacBook lid to verify it remains awake.
  4. 4Monitor the menu bar status and listen for the chime to confirm active sleep prevention.
  5. 5Integrate the optional MCP if you require manual control or time-specific wakefulness for agents.

Who benefits

Software DevelopmentAI/ML ResearchTech StartupsData Science

Key takeaways

  • Adrafinil is an open-source macOS tool preventing sleep only when AI agents are active.
  • It solves the problem of MacBooks sleeping with the lid closed, interrupting AI tasks.
  • The tool intelligently detects agent activity and re-enables sleep when tasks are complete or overheating occurs.
  • It offers a more efficient alternative to general sleep-prevention utilities for AI development.

Original post by kageroumado

"A month ago there was a wave of posts and tweets about engineers walking around cafes and parks with their MacBooks propped half-open, as fully closing the lid forces sleep that stops their AI agents. Some people made snarky comments about using tmux or Amphetamine, and some defe…"

View on X

Originally posted by kageroumado on X · view source

Want to go deeper?

Turn these trends into skills with Learnijoy's hands-on AI & tech courses.

Explore courses