News for hackers. Stuff that matters.

Show HN: Adrafinil – keep a lid-closed Mac awake only while agents work

https://github.com/kageroumado/adrafinil

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 defended their choice with “but I only need it sometimes, and forgetting to disable Amphetamine and finding my laptop discharged in my bag is worse.”

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).

( 82 comments | 75 points | on HN )
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by geor9e on Saturday June 27, 2026 @08:14PM (#48703078)
Codex recently built this in - "Prevent sleep while running" toggle
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by chopete3 on Saturday June 27, 2026 @05:17PM (#48701845)
This is great. Will check it.

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

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @05:57PM (#48702151)
The dummy display enables “clamshell mode,” which lets your MacBook stay awake even with the lid closed, provided that it’s also on AC power. If the MacBook is not connected to power, the clamshell mode isn’t activated and it will sleep normally.

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.

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by chopete3 on Saturday June 27, 2026 @06:24PM (#48702353)
My requirement was to keep the laptop on with the lid closed. Sleep normally when idle but wake up when a nomachine request comes in.

I will see how this app fits into my specific need.

I have to check this on Mac Sequoia 15.7

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @06:47PM (#48702506)
The app is built for 26+, as I never tested it on earlier versions. It won’t solve your specific case, though, as it only prevents sleep. It won’t wake it once it’s already sleeping.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by bluedino on Saturday June 27, 2026 @05:35PM (#48701989)
Can't you just use a hot corner configured as "prevent sleep"?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by fragmede on Saturday June 27, 2026 @05:36PM (#48701998)
How does it sleep when the agent is done working with the hot corner?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by doubled112 on Saturday June 27, 2026 @05:42PM (#48702048)
Have the agent write an app that moves the cursor our of the hot corner and trigger it when done.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by hhh on Sunday June 28, 2026 @02:16PM (#48709926)
this feels like https://xkcd.com/1172/ waiting to happen
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by aqme28 on Saturday June 27, 2026 @05:38PM (#48702013)
Thank goodness. I can’t leave my laptop for a second unattended because my cat loves nothing more than to dance on the keyboard. I’ve need something like this.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by EddieLomax on Monday June 29, 2026 @04:21PM (#48724638)
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by processunknown on Saturday June 27, 2026 @04:53PM (#48701661)
Does it also make my Mac irritable?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @05:24PM (#48701909)
Probably less irritable than amphetamine~
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by loeg on Saturday June 27, 2026 @09:50PM (#48703584)
I guess we are getting the entire modafinil, R-modafinil extended universe.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by lellow on Saturday June 27, 2026 @07:25PM (#48702793)
Interesting. Kind of similar in purpose, but I created a simple app to schedule and type the "continue" word in my terminal after X time has passed, since I have to wait for my usage to be restored. =)
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by julianlam on Saturday June 27, 2026 @08:08PM (#48703048)
And the only thing
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by mr_toad on Saturday June 27, 2026 @06:56PM (#48702574)
I’ve often wondered about the thermal performance or running a MacBook with the lid closed. One argument is that the reduced surface area from a closed lid increases temperature. Others argue that not running & rendering the display (and thus GPU) generates less heat. I’m not sure who to believe.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by herrkanin on Saturday June 27, 2026 @07:08PM (#48702678)
Running lid closed with external display has been officially supported since forever so I wouldn't worry about it too much.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by Maxious on Sunday June 28, 2026 @01:19PM (#48709417)
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by rancar2 on Saturday June 27, 2026 @05:38PM (#48702020)
For MacOS, keep awake with:

sudo pmset -a disablesleep 1

Reset back:

sudo pmset -a disablesleep 0

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @05:46PM (#48702070)
This is exactly what the app does, except it ties it to agent activity and re-enables sleep once the turn ends, the laptop is close to overheating, the battery is low, or on a timer.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by xbar on Saturday June 27, 2026 @05:48PM (#48702090)
Nice. I needed this yesterday, and will need it again today.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by hamza_q_ on Saturday June 27, 2026 @08:36PM (#48703191)
This works great. Only downside is display doesn't turn off when you close the lid. Made a little status bar utility to wrap the disablesleep command and address that downside:

https://github.com/narcotic-sh/modafinil

(yes, I know, another *afinil named Mac sleep prevention app? but hey, I was first :P)

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by freakynit on Saturday June 27, 2026 @11:56PM (#48704191)
Just tried. Bare minimal and does exactly what's needed and nothing else. Love it. Thanks..
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by hamza_q_ on Sunday June 28, 2026 @12:14AM (#48704281)
np cheers!
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @09:23PM (#48703423)
Afinils are cool, and your app is cool too~
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by hamza_q_ on Saturday June 27, 2026 @11:34PM (#48704074)
Indeed.

Thanks!

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by dawnerd on Saturday June 27, 2026 @05:20PM (#48701868)
But Amphetamine has an option to end when an app closes. I’m just so confused why everyone using ai is reinventing solutions that already exist.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by geor9e on Saturday June 27, 2026 @08:14PM (#48703079)
That's not at all what this app does.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @05:28PM (#48701942)
Claude Code or Codex (normally) don’t close the terminal window after a turn ends, they wait for the user’s reply.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by neoecos on Saturday June 27, 2026 @05:51PM (#48702107)
I think the same...It happend to me that I just ask Claude to build whatever I need for my personal very specific use case without looking what else it's outhere
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by conception on Saturday June 27, 2026 @05:27PM (#48701937)
Easier to ask Claude than ask google I guess.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by flexagoon on Saturday June 27, 2026 @05:44PM (#48702055)
Everyone dreams about making the next cool AI tool and doesn't bother checking if someone has already made the same thing years ago without the word "AI" in the description
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @07:04PM (#48702632)
In order to get the same behavior with Amphetamine you’ll need to: 1. Install it from the AppStore (no brew, no GitHub) 2. Not forget to enable lock on lid close 3. If you ever connect/disconnect power while the lid is closed without the optional “Power Protect” system, the MacBook will sleep. The system is a script and a configuration file making sudo pmset -a disablesleep passwordless. 4. Add hooks to Claude Code configuration that will use Apple Script to start and stop Amphetamine sessions. For Codex you’ll have to make a script that will watch process activity to know when a turn ends.

It’s not like Amphetamine can’t do the same, it’s that this app is made specifically for AI agents and nothing else.

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by slopinthebag on Saturday June 27, 2026 @08:04PM (#48703024)
15k loc for this? holy cow
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by moralestapia on Saturday June 27, 2026 @04:57PM (#48701682)
What's old is new again, but I welcome this.

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.

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @05:22PM (#48701887)
It has a setting for thermal cutoff that you can set to something like 60º C. Sleeping will stop heavy work (like a build) before it leads to overheating.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by dmd on Saturday June 27, 2026 @05:07PM (#48701770)
that was true of intel but definitely not of arm macbooks.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by NewJazz on Saturday June 27, 2026 @05:14PM (#48701824)
Then why do they have fans?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by loeg on Saturday June 27, 2026 @09:52PM (#48703594)
Many ARM Macbooks do not have fans?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by moralestapia on Saturday June 27, 2026 @10:46PM (#48703872)
Fans !== heat
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by loeg on Sunday June 28, 2026 @12:32AM (#48704387)
My comment is only in response to https://news.ycombinator.com/item?id=48701824 , which is contending that ARM Macbooks have fans.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by NewJazz on Sunday June 28, 2026 @04:04PM (#48711036)
Many do. I would argue most do, although i don't have air vs. Pro sales numbers so I can't speak definitively there.

Even those that don't may rely on passive cooling strategies that are less effective in enclosed spaces.

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by dominotw on Saturday June 27, 2026 @05:07PM (#48701763)
had a coworkers whose laptop keys melted into mush
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by xlii on Saturday June 27, 2026 @05:13PM (#48701815)
Um so it is

    sudo bash -c 'touch KEEP_RUNNING; pmset -b sleep 0; pmset -b disablesleep 1; while [ -e KEEP_RUNNING ]; do sleep 1; done; pmset -b sleep 5; pmset -b disablesleep 0'
and

    Agent, when you're done do `rm KEEP_RUNNING`, kthxbye.
?

(personally I have Ruby scripts that check activity on "tmux capture-output" for that)

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by fragmede on Saturday June 27, 2026 @05:34PM (#48701988)
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by da_grift_shift on Saturday June 27, 2026 @05:46PM (#48702068)
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by operatingthetan on Saturday June 27, 2026 @05:16PM (#48701832)
So now we're naming apps after obscure Modafinil derivatives?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by hamza_q_ on Saturday June 27, 2026 @08:11PM (#48703063)
I'll take credit for starting this trend :P

https://github.com/narcotic-sh/modafinil

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by operatingthetan on Saturday June 27, 2026 @11:23PM (#48704017)
There were mac apps called caffeine and amphetamine years ago.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by hamza_q_ on Saturday June 27, 2026 @11:34PM (#48704071)
Was referring to the *afinil specifically
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by operatingthetan on Saturday June 27, 2026 @11:36PM (#48704085)
Alright, well I guess I thought were were talking about naming apps after stimulant drugs lol.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by oenton on Sunday June 28, 2026 @01:56AM (#48704794)
In that case from what I understand, Adrafinil has a much lower abuse potential than amphetamines, in particular because it doesn't give you a rush. If we're going to name mac apps after pharmaceuticals then this feels a little bit classier. No rush, just steady wakefulness.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by treme on Saturday June 27, 2026 @07:48PM (#48702932)
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by unacorner on Saturday June 27, 2026 @06:09PM (#48702255)
Adrafinil's discovery and use predates Modafinil, I believe.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by operatingthetan on Saturday June 27, 2026 @06:18PM (#48702318)
I admire your pharma knowledge.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by hoppp on Sunday June 28, 2026 @08:37AM (#48706770)
I thought it was related to sildenafil and gives the laptop an erection lol

Maybe as a metaphor that you can't close the lid cuz the boner is in the way and keeps it awake

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by WUMBOWUMBO on Saturday June 27, 2026 @05:26PM (#48701929)
reminds me of ye old caffeinate
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @05:43PM (#48702050)
Caffeinate doesn’t prevent sleep with the lid closed.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by cyanydeez on Saturday June 27, 2026 @05:56PM (#48702146)
you can run opencode inside a docker container and expose it's webui.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by cyclopeanutopia on Saturday June 27, 2026 @05:24PM (#48701912)
Ridiculous bloat.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by 47 on Saturday June 27, 2026 @08:25PM (#48703128)
I have been using the builtin macOS `caffeinate` command for this.

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

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by zxexz on Saturday June 27, 2026 @08:38PM (#48703206)
Caffeinate is burned into my muscle memory at this point. I attribute that to the realization that you could repeat opt flags. There's something catchy about

caffeinate -dimsum

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by port11 on Monday June 29, 2026 @10:40AM (#48719895)
Yum, dim sums with caffeine! I didn’t know you could repeat flags, I’m gonna steal the idea for some of my own scripts.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @09:37PM (#48703502)
Claude Code actually uses caffeinate -i -t 300 during Claude’s turn, restarted automatically until the turn finishes.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by steve-atx-7600 on Saturday June 27, 2026 @09:41PM (#48703530)
The new wave apps named after speed / modifinil must be hard core?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by IncreasePosts on Saturday June 27, 2026 @08:25PM (#48703131)
At some point, if you closed the lid and didn't have an external monitor plugged in, macos would put the GPU in power save mode, which would tank local llm performance. Is that not the case any more? There were even small singles you could get which would trick the ps into thinking an external monitor was plugged in
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by loeg on Saturday June 27, 2026 @09:52PM (#48703600)
I don't think this is for running local llms.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by exabrial on Saturday June 27, 2026 @08:26PM (#48703133)
Amphetamine is what I use. It has a robust set of triggers, like if you ip address changes to a certain subnet (like private IPs on a work network)

https://apps.apple.com/us/app/amphetamine/id937984704?mt=12

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by anonuser123 on Sunday June 28, 2026 @12:53AM (#48704484)
Came to say this. I've used it for years. Simple and works great!
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by 2001zhaozhao on Saturday June 27, 2026 @08:27PM (#48703137)
We need people to rediscover remote development desperately, lol.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by AussieWog93 on Saturday June 27, 2026 @08:52PM (#48703282)
How does this differ from https://github.com/samber/cc-caffeine?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kageroumado on Saturday June 27, 2026 @09:29PM (#48703465)
It’s an Electron app that uses powerSaveBlocker to prevent display sleep. It won’t prevent macOS system sleep on lid close with no power.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by AussieWog93 on Sunday June 28, 2026 @12:29AM (#48704367)
Thanks. This one looks much better!
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by kylehotchkiss on Saturday June 27, 2026 @11:25PM (#48704035)
`sudo pmset -a sleep 0`
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by tam159 on Sunday June 28, 2026 @12:37AM (#48704411)
It would be great if adrafinil can also track the battery and token usage while agents are working
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by NDlurker on Sunday June 28, 2026 @01:09AM (#48704554)
Adrafinil never seemed to work for me. I tried it a few times when I worked an overnight shift.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by dcan on Sunday June 28, 2026 @01:18AM (#48704602)
Does closing the M-series laptop lid no longer throttle the CPU like it did on the Intel ones?
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by strus on Sunday June 28, 2026 @02:15AM (#48704876)
I am always baffled how many people does not know about Amphetamine.
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by Msurrow on Sunday June 28, 2026 @11:28AM (#48708220)
> 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

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

Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by Rutvik_Pansare on Sunday June 28, 2026 @09:44PM (#48713827)
Finally a smart tool to keep laptops awake, i have frained my battery several times with caffeinated. Thanks
Re:Show HN: Adrafinil – keep a lid-closed Mac awake only whi... by felixlu2026 on Monday June 29, 2026 @01:26AM (#48715162)
honestly this is the kind of boring tool that matters once agents run for hours. laptop sleep has killed more useful runs than bad prompts for me.