Show HN: Adrafinil – keep a lid-closed Mac awake only while agents work (github.com)
This is a solution to this problem. Unlike caffeinate, it will prevent your MacBook from sleeping even with the lid closed, with no external power or display, using pmset disablesleep 1. Unlike other sleep-preventing apps, Adrafinil only activates when there’s an agent actively doing something. It detects agent activity through hooks it installs into Claude Code, Codex, and others. To reassure you it’s working, the app shows the active status in the menu bar, and it plays a chime when you close the lid.
Once the agent is done, Adrafinil detects it and lets the laptop go to sleep by setting pmset disablesleep back to 0. It will also let it sleep in case of overheating. And if you want to manually toggle it, you can install an optional MCP and tell your agent to keep the MacBook awake for a specific time.
It has four binaries, one of which is a root helper exposing a single setSleepBlocked call. All the logic and policy live in the unprivileged parts. They’re all notarized, and the app is fully open source (MIT).
I used to do this 15 years ago to keep listening to music from my laptop (one of the white chiclet ones) in my backpack, can't remember the name of the app I used then.
One caveat, your laptop cannot cool inside a backpack, it will overheat and shut down anyway. This happened to me several times.
(personally I have Ruby scripts that check activity on "tmux capture-output" for that)
https://ghloc.vercel.app/kageroumado/adrafinil?branch=main
He's a connoisseur.
https://github.com/narcotic-sh/modafinil
Maybe as a metaphor that you can't close the lid cuz the boner is in the way and keeps it awake
Recently I bought a usb-c empty external monitor card to prevent mac from going to sleep. There are many of these external monitor simulators on Amazon.
I still see the laptop go to sleep many times with the external monitor simulator.
This is the one I bought.
4K 60Hz USB-C Type-C Virtual Display Adapter DDC EDID Dummy Plug Headless Ghost Display Emulator 2K 60hz1080P@120Hz
Adrafinil simply disables the global sleep without spoofing hardware, and re-enables it once the agent is done working, the temperature is too high, or the battery is low.
I will see how this app fits into my specific need.
I have to check this on Mac Sequoia 15.7
It’s not like Amphetamine can’t do the same, it’s that this app is made specifically for AI agents and nothing else.
sudo pmset -a disablesleep 1
Reset back:
sudo pmset -a disablesleep 0
https://github.com/narcotic-sh/modafinil
(yes, I know, another *afinil named Mac sleep prevention app? but hey, I was first :P)
Thanks!
For example:
caffeinate -dimsu
That keeps the Mac awake so I can use Claude remotely from phone.
You can also wrap your command as well, but I rarely use it.
caffeinate -dimsu your-agent-command
caffeinate -dimsum
https://apps.apple.com/us/app/amphetamine/id937984704?mt=12
Why don’t they just ask the agents to code up something to prevent the Mac sleeping.. and that will auto enable/disable depending on if they have the agent running or not
I mean, agents makes human devs redundant, right? This seems like a trivial little problem for an agent to fix