StayAwake macOS 14+ / Apple Silicon / by René Weteling

Agents keep working. Laptop in your bag.

Keeps a closed MacBook awake on battery for Claude Code and Codex, and lets it sleep before it runs hot.

Someone on an evening train following a coding agent on their phone, with a closed laptop in the backpack next to them.

How I use it

I start a long task, close the lid and follow along from my phone on the train. macOS normally sleeps the moment the lid shuts on battery. StayAwake stops that, within limits.

  1. Start the agent on the Mac.

    Claude Code, Codex or whatever you run, in a terminal like always.

  2. Click the moon in the menu bar and flip Stay awake.

    Pull the power cable while it is on and it asks if it should keep going on battery.

  3. Join your phone’s hotspot, then connect from the phone.

    Use your agent’s own remote or mobile option. StayAwake keeps the Mac and its connection up, it is not the link itself.

  4. Close the lid and pack it.

    The Mac keeps working in the bag. When the battery hits 43 °C, the charge drops under 40%, the network is gone for 15 min or it has run 8 hours on battery, it lets the Mac sleep.

When it lets go

The first rule that trips turns sleep back on. Every limit is a setting, these are the defaults. Temperatures have to stay over the limit for a while, so one spike does not end a run.

Heat

Battery temperature
Hottest battery sensor at 43 °C for 60 s. This is the one that matters in a bag.
CPU
60 s average at 100 °C for 2 min. Clears 10 °C lower.
GPU
60 s average at 95 °C for 2 min.
Thermal pressure
macOS reports serious for 5 min, or critical once.
Battery heating up
Up 2 °C in 5 min with the lid closed on battery. Off by default.

Power and network

Battery charge
Below 40% and not charging. Clears at 50% or on the charger.
No network
No usable route for 15 min.
Sensor failure
No valid temperature for 60 s. Unknown heat counts as hot.

Time

Time cap
8 h held on battery. Plugged in, it keeps going.
Lid on battery
Closed and unplugged for 90 min.
Schedule
Outside your hours for that weekday. Up to three windows a day.
Idle
CPU under 10% for 15 min with the lid closed.
Watched process
No claude process for 20 min. Off by default.

If the app dies, the Mac still sleeps

The bad outcome for a tool like this is a Mac stuck awake in a bag after the app crashed. So the switch is not in the app.

Lease
A small root helper only keeps sleep off while the app keeps renewing a lease. Crash, hang or force quit, and sleep is back within 60 s.
Reboot
The helper turns sleep back on at every boot. A lease from an earlier boot is void.
App quits
Quit, update or remove the helper, and sleep comes back first.
Two commands
The helper runs pmset -a disablesleep 1 or 0 and nothing else. No shell, and only the signed StayAwake app can talk to it.

If everything else fails, this turns normal sleep back on:

$ sudo pmset -a disablesleep 0

Also shown in About and by StayAwake --restore.

Compared with caffeinate, Amphetamine and pmset

caffeinate and Amphetamine create power assertions. macOS honors those while the lid is open, but not when you close the lid on battery. Only pmset -a disablesleep 1 does that.

You can run it by hand, and it works. Then nothing watches the temperature, the charge or the network, and it stays on until you undo it with sudo pmset -a disablesleep 0.

StayAwake runs the same command through a small root helper and adds the rules above and a fail-safe that restores sleep if the app dies. If you only need the Mac awake with the lid open, caffeinate or Amphetamine are the simpler tool.

Install

macOS 14 or newer on Apple Silicon. Signed and notarized, free for noncommercial use.

  1. Download StayAwake.dmg from the latest release.
  2. Drag StayAwake into Applications.
  3. Approve the helper once in System Settings, Login Items. It never asks for your password.
  4. Click the moon in the menu bar and flip Stay awake.

Or build it yourself:

$ git clone https://github.com/reneweteling/stayawake.git
$ cd stayawake && ./scripts/build.sh
$ cp -R build/StayAwake.app /Applications/

FAQ

How do I keep a MacBook awake with the lid closed on battery?

Run sudo pmset -a disablesleep 1, or let StayAwake do it with one click in the menu bar. Normal tools like caffeinate only hold power assertions, and macOS ignores those when you close the lid on battery. disablesleep is the setting that does keep a closed MacBook running. StayAwake adds the safety rules and the fail-safe that make this fine to use in a bag.

Is it safe to run Claude Code in a closed MacBook in a backpack?

It is safe with limits, and StayAwake sets them for you. By default the Mac may sleep at 43 °C battery temperature, a 100 °C CPU or 95 °C GPU average over 60 seconds, serious thermal pressure for 5 minutes, below 40% battery, 15 minutes without network, 90 minutes lid closed on battery and 8 hours on battery in total. Unreadable sensors count as hot. Still, do not pack the Mac tight. Leave some air around it.

How do I undo pmset disablesleep?

Run sudo pmset -a disablesleep 0 in Terminal. StayAwake does this itself when a rule trips, when the app stops renewing its lease, and at every boot, so you only need the command if you want to be sure. You can check the current state with pmset -g | grep SleepDisabled.

How is StayAwake different from caffeinate, Amphetamine or pmset by hand?

caffeinate and Amphetamine use power assertions. Those keep a Mac awake with the lid open, or on power with a display attached, but macOS does not honor them for a closed lid on battery. pmset -a disablesleep 1 does, and you can run it by hand, but then nothing watches the temperature, the battery or the network, and you must remember to undo it. StayAwake runs that same command through a root helper and adds heat, battery, network, schedule and lid-time rules plus a fail-safe that restores sleep if the app dies.

Does the Mac stay on my hotspot with the lid closed?

Yes, as long as it was already connected. StayAwake keeps the Mac awake, so the connection it has stays up. Join the hotspot before you close the lid and keep Personal Hotspot on. If the network is gone for 15 minutes, the no network rule lets the Mac sleep.

Can I control Claude Code from my phone with this?

Not by itself. Use the remote or mobile option of your agent tool, for Claude Code or Codex. StayAwake does not provide that link. It keeps the Mac awake and online, so the session is still there when you connect from your phone.

Is it safe in a bag?

That is what most of the work went into. By default it stops at 43 °C battery temperature, a 100 °C CPU average, serious thermal pressure, 40% battery, 15 minutes without network, 90 minutes lid closed on battery and 8 hours on battery in total. Unreadable sensors count as hot. Still, do not pack it tight. Leave some air around the Mac.

What does it actually do?

It runs pmset -a disablesleep 1 for you through a small root helper, so a closed MacBook on battery keeps running. It runs pmset -a disablesleep 0 when a rule trips, when the app stops renewing its lease, and on every boot.

What if the app crashes while it holds?

The helper holds a lease that the app keeps renewing. When that stops, the lease runs out within 60 seconds and the helper turns sleep back on. After a reboot it does that before anything else. If you ever doubt it, run sudo pmset -a disablesleep 0.

Why not the App Store?

It needs a root helper, so it ships as a signed and notarized app on GitHub releases.

What does it send?

Crash reports through Sentry with the app version and rule names, nothing else. No sensor data leaves the Mac. You can switch crash reports off in Settings.

What does it cost?

Nothing for noncommercial use, under PolyForm Noncommercial 1.0.0. The source is on GitHub.

René Weteling

Made by René Weteling

I build products with a fleet of AI agents and bring the engineering judgement that keeps them honest. I wrote StayAwake because I wanted those agents to keep going while I was on the train.

Want that speed on your own product? Idea to production, CTO as a service, or a second pair of senior eyes.

Other apps

  • TidyDriveYour disk is full. Take it back.
  • LoftDrag a file to your menu bar, get a link back.
  • fckrMake your colleagues’ Macs talk. From your terminal.
  • HeadsUpYour group chats, turned into one morning to-do list.
  • FooterManagerEmail signatures that manage themselves.
  • All appsThe rest are on weteling.com.