🤖 AI Hot

Adrafinil Keeps Mac Awake Only While AI Agents Work

A
Alex Chen

If you run AI coding agents on a MacBook, you know the drill. You start a multi-hour refactor with Claude Code or Codex, close the lid, and come back to find your Mac went to sleep 15 minutes in. The agent sat there waiting for a CPU that wasn’t running. Half the work is lost.

The standard fix is caffeinate or Amphetamine — tools that keep your Mac wired 24/7. But those are stimulants. They don’t care whether anyone’s home. You forget to turn them off, and your Mac runs all night for no reason, fans spinning in your bag.

Adrafinil takes a different approach. This new macOS menu bar app, built by indie developer @kageroumado, only prevents sleep while an AI agent is actively working. The moment the last agent session goes idle, your Mac goes back to normal sleep behavior. Close the lid, and it sleeps — unless an agent is mid-task.

What Adrafinil actually does

The app sits in your macOS menu bar and tracks AI agent activity through hook systems. When Claude Code starts a new turn, Adrafinil acquires a sleep assertion. When the agent finishes and hits Stop, Adrafinil releases it. Reference-counted assertions mean overlapping sessions stack cleanly — sleep only unlocks when every agent is done.

The tool ships with one-click hook installers for nine AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Aider, Hermes, OpenCode, Cline, and Pi. If your agent isn’t on that list, the optional process-sniffing mode can auto-detect a known agent binary and acquire an assertion even without explicit hooks.

There are three ways to keep the Mac awake:

  1. Automatic (hooks). Adrafinil detects agent turn starts and stops through each agent’s hook system. No manual input needed. This is the primary mode — the one that makes the tool feel invisible.

  2. Agent-driven (MCP / CLI). An agent can deliberately hold sleep past its reply for a long build or deploy. The bundled MCP tool lets agents call adrafinil hold --for 30m --reason "deploy" to keep things running while they work on a background task.

  3. Manual (menu bar). A Keep awake button starts a time-boxed hold even with no agents running. Useful for long downloads or any off-agent task. Let it sleep clears everything.

The architecture is clean on purpose. The privileged helper that actually calls pmset disablesleep is a tiny, auditable component that only exposes one mutating endpoint: setSleepBlocked(Bool). All policy — ref counting, thermal monitoring, idle detection — lives in an unprivileged daemon that runs as your user. The menu bar app is a pure view layer that can quit and relaunch without affecting held assertions.

The clamshell problem: why caffeinate isn’t enough

Most people learn this the hard way: caffeinate does not prevent clamshell sleep. Close the lid on a MacBook, and IOPMAssertionCreateWithName with the public assertion types won’t keep the machine awake. Apple’s power management treats lid-close as a hard sleep trigger that bypasses those assertions.

Adrafinil’s helper uses pmset disablesleep 1 — which is blunt, and the developer is upfront about that. The helper resets to disablesleep 0 on respawn before re-applying state, so a crash or forced shutdown doesn’t leave sleep permanently disabled. The README notes that the cleaner private IOPMrootDomain paths were tested and found insufficient for displayless lid-closed Macs, so the current approach is a pragmatic tradeoff.

This is one of those problems that only becomes visible at scale. One person running an occasional agent session won’t notice. But if you’re running autonomous agents overnight — and plenty of developers are — a Mac that sleeps through an agent session means wasted compute, lost context, and the kind of frustration that makes you question whether local agents are worth the hassle.

Thermal cutout and safety

Keeping a Mac awake with the lid closed in a bag is risky. Adrafinil has a thermal cutout: if skin or CPU temperature crosses a threshold while the lid is closed, all assertions are force-released. The bag-bound Mac won’t cook itself.

There’s also an idle release mechanism. If the owning process for an assertion dies or goes CPU-idle for N minutes, the assertion drops automatically. This handles edge cases where an agent crashes without cleaning up its hooks.

When you reopen the lid after an overnight agent session, Adrafinil shows a summary: what ran while you were away, peak temperature, and whether the thermal cutout fired. There’s also a lid-close chime — a confirmation that an assertion is held when you close the lid, since the screen is off and a notification wouldn’t be visible.

The CLI is surprisingly fast

Agent hooks are in the hot path of every session. If adrafinil acquire took even 200ms, it would add noticeable latency to every agent turn. The CLI connects to the daemon over a Unix domain socket with sub-50ms round-trip times. Static lookups (like AgentKind.allBinaryNames) avoid filesystem scans at invocation time.

The CLI subcommands cover the full workflow:

adrafinil acquire <session-key> --tool claude-code
adrafinil release <session-key>
adrafinil status          # show active assertions
adrafinil hold --for 30m --reason "deploy"
adrafinil install-hooks   # one-click for all supported agents
adrafinil uninstall-hooks # clean removal

The uninstall is clean — it removes every hook entry across all agent configs, which matters because agent hook systems vary widely in where and how they store configuration.

Who should use this

If you run AI coding agents on a MacBook and have ever come back to a sleeping machine mid-task, Adrafinil solves that problem directly. It’s especially useful if you:

  • Run agents overnight or during long stretches away from your desk
  • Use multiple agents (Claude Code for architecture, Codex for implementation, Aider for quick fixes) and don’t want to manage wake settings per tool
  • Care about battery and thermals and don’t want an always-on wake utility draining power when nothing is running

Who should skip it

  • Desktop Mac users who never close a lid. caffeinate -d works fine for you.
  • Developers who only run short agent sessions under 5 minutes. Sleep is unlikely to interrupt those.
  • Anyone on macOS versions before Tahoe 26.4 — Adrafinil requires it, and the developer is explicit that earlier versions are untested.

The bigger picture: agent infrastructure is maturing

Adrafinil is part of a wave of tools that treat AI agents as first-class workloads, not just CLI curiosities. Six months ago, running an agent overnight meant cobbling together shell scripts and praying. Now there’s a dedicated tool for keeping the machine awake — with thermal monitoring, hook integration, and a proper uninstall path.

This matters because autonomous agents are moving from experimental to operational. Developers aren’t just playing with agents anymore; they’re depending on them for real work. When an agent is halfway through a large refactor at 3 AM, you need the machine to stay awake. Not forever. Just until the work is done.

How it compares to the alternatives

The macOS ecosystem already has several wake-prevention tools, but none of them are agent-aware. Here’s how Adrafinil stacks up:

caffeinate (built-in). The caffeinate command is available on every Mac and works fine for keeping the display on. But caffeinate -d doesn’t prevent clamshell sleep — close the lid and the machine sleeps regardless. You can combine flags (caffeinate -dims) to block idle sleep, display sleep, and disk sleep, but it’s an all-or-nothing approach. There’s no concept of “stay awake only while this process is running” beyond wrapping it in a shell script that kills caffeinate on exit. And if your agent spawns subprocesses or runs in the background, that wrapper breaks.

Amphetamine. The most popular third-party wake utility on the App Store, with a 4.8-star rating. It supports triggers based on specific apps, which is close to what Adrafinil does — but it triggers on the app being open, not on the agent actively working. Claude Code could sit idle at a prompt for hours while Amphetamine keeps the machine awake the entire time. It also requires manual configuration per app rather than auto-detecting agent hooks.

Owly. A newer menu bar tool that prevents sleep with a single toggle. Simple and effective, but no agent awareness at all. You toggle it on, you toggle it off. If you forget, your Mac runs all night.

Adrafinil’s key differentiator isn’t that it prevents sleep — it’s that it knows when to prevent sleep. The hook integration means it tracks agent activity at the turn level: Claude Code’s UserPromptSubmit and Stop hooks, Codex’s session lifecycle events, Cursor’s chat turn boundaries. An open-but-idle agent session doesn’t hold a sleep assertion. Only active work does.

Setup takes under a minute

Installation is a signed, notarized disk image from GitHub Releases. Download, drag to Applications, launch. The first launch asks for admin rights once to register the privileged helper via SMAppService. After that, the app runs as a normal menu bar item.

Hook installation is one click. Open the menu bar dropdown, click “Install Hooks,” and Adrafinil wires itself into every supported agent it finds on your system. It reads each agent’s config file, appends the hook entries, and verifies the result. If you later add a new agent, run “Install Hooks” again — it’s idempotent, so existing hooks won’t be duplicated.

The uninstall is just as clean. “Uninstall Hooks” removes every entry Adrafinil added across all agent configs. Drag the app to Trash and you’re done. No leftover LaunchDaemons, no orphaned config entries, no system preference panes to hunt down.

For agents not on the supported list, the process-sniffing fallback watches for known agent binaries (claude, codex, gemini-cli, aider, etc.) and auto-acquires when it spots one. It’s less precise than hooks — it can’t distinguish between an idle agent and an active one — but it works without any configuration.

What to watch out for

Adrafinil is on version 1.0, and some quirks are worth knowing before you depend on it for overnight agent runs.

First, the pmset disablesleep approach means the helper needs to clean up on exit. If the helper process crashes or the system force-kills it (rare but possible during an OS update), disablesleep could remain set to 1. The developer addresses this by resetting to disablesleep 0 on every helper respawn before re-applying current state. In practice, this means a reboot always starts clean.

Second, the daemon runs XPC and socket callbacks on arbitrary dispatch queues. The assertion registry is synchronized, but the concurrency model is something to be aware of if you’re modifying the source.

Third, the tool requires macOS Tahoe 26.4 or later. If you’re on an earlier 26.x release, the developer says it “likely runs” but hasn’t tested it. If you’re on Sequoia (macOS 15) or earlier, it won’t work at all — the Swift 6 strict concurrency features and updated SMAppService APIs don’t exist in those versions.

The tooling gap for autonomous agents

Adrafinil exposes something I’ve been thinking about: we’re building autonomous agents, but the operating system doesn’t know they exist. macOS has no concept of “an AI agent is performing work that shouldn’t be interrupted.” There’s no IOPMAssertion for agent activity. No power management awareness of long-running inference or tool-use loops.

This is a tooling gap that will only grow as more developers run agents in the background. Right now, the workaround is a third-party menu bar app with hook integration — which works, but it’s fragile. Hook formats change. Agent config schemas evolve. The app has to chase nine different agent ecosystems just to know when work is happening.

What would be better: a system-level API that lets any process declare “I’m doing background work that shouldn’t be interrupted by sleep.” Android has WakeLock. Linux has systemd-inhibit. macOS has nothing general-purpose — just IOPMAssertion for idle sleep and pmset for everything else. Until Apple fills that gap, tools like Adrafinil are doing the OS’s job.

The tool is open source under MIT, built in Swift with strict concurrency enabled. The repo has 341 stars as of early July 2026, which is modest but reflects how niche this problem is — and how specific the solution. It’s not trying to be a general-purpose system utility. It does one thing: keep your Mac awake when agents are working, and only then.

Sources

Disclosure: CarCare Guide is reader-supported. When you buy through links on our site, we may earn an affiliate commission at no extra cost to you. Learn more.
A
Alex Chen