skip to content

// macos app

Wakehold

Keeps a Mac awake exactly as long as the work is alive, then lets it sleep.

A session-aware wake controller for macOS: a menu bar app, a CLI and a local control endpoint over a Unix socket. A running process, a listening port, a wrapped command, a coding agent's session, a chosen app or a timer each hold the machine open, and the hold releases itself when the last one ends. When it does, the Mac can notify you, sleep or shut down.

// hourglass12/22
year
2026
type
macos app
group
macos apps
stars
5

//in plain words

Macs go to sleep after a few idle minutes, which kills a long download, a build or an AI agent working overnight. The usual fix is a switch you flip on and forget. Wakehold instead watches the thing you care about and keeps the Mac awake only while it is running, then lets it sleep or shuts it down for you.

for anyone who runs builds, servers or coding agents on a Mac

the problem

//01the problem

Keep-awake tools are a switch you flip on and forget to flip off. They model a timer, not the thing you actually care about: the build, the dev server, the agent that will finish at some point in the night.

how it works

//02how it works

  1. 01

    Sessions, not switches

    Tell it what to watch: a build, a dev server on :3000, a process id, an app, a Claude Code or Codex session, or just twenty minutes. Every session is one type conforming to one protocol, and the Mac is awake exactly while at least one is active. Nothing toggles the power assertion directly; one reconcile step derives it from the sessions.

  2. 02

    Leases, not goodbyes

    Agent hooks open a lease keyed by the session id and renew it on every event. A crash or a kill never sends an end hook, so the lease's expiry is the source of truth, not the goodbye. The hooks are no-ops when the app is not running, so they never block the agent.

  3. 03

    Cleans up after itself

    When the last session ends it can notify, sleep the display, sleep the Mac, shut down or restart. Each action is armed per occasion, shown in the menu and cancelable. Run the agent overnight, shut down when it finishes.

  4. 04

    Guardrails for the battery

    A hold can release itself on battery, below a chosen charge or in Low Power Mode. The display stays on by default, with one switch to let it sleep while the system stays awake. The system-level assertion that fights the lid is never used.

  5. 05

    Legible

    The menu lists every reason the Mac is awake, including other apps' power assertions like a call, audio or a stray caffeinate, named by their owning process. Wakehold's own holds show up in pmset like everyone else's.

  6. 06

    A socket, not a port

    The CLI and hooks talk to the app over HTTP on a Unix domain socket under Application Support, mode 0600 with a peer check. A localhost port would be reachable from a browser and any local process; a socket is scoped by the filesystem, and curl still works.

screens

//03screens

  1. The menu, holding four sessions: A build, a dev server port, a Claude Code session and a timer each hold the Mac awake, every one with its own End; the countdown sits in the menu bar.
    01The menu, holding four sessionsA build, a dev server port, a Claude Code session and a timer each hold the Mac awake, every one with its own End; the countdown sits in the menu bar.
  2. Power: The live power state, the battery rules that pause a hold, and the opt-in hold that keeps a closed laptop awake while a session runs.
    02PowerThe live power state, the battery rules that pause a hold, and the opt-in hold that keeps a closed laptop awake while a session runs.
  3. Integrations: Whether the CLI is installed, whether Claude Code's hooks are connected, and the commands any other agent points its hooks at.
    03IntegrationsWhether the CLI is installed, whether Claude Code's hooks are connected, and the commands any other agent points its hooks at.
  4. Settings in Arabic: Every screen is localised, and the window mirrors right to left from the language the app runs in.
    04Settings in ArabicEvery screen is localised, and the window mirrors right to left from the language the app runs in.
  5. Durations: The default a click on the menu bar eye starts, and the quick picks the menu offers.
    05DurationsThe default a click on the menu bar eye starts, and the quick picks the menu offers.

measured

//04measured

6
kinds of session
timer, process, port, command, agent and app
116
automated tests
swift testing, 95 in the kit and 21 in the app
0
network ports opened
the control endpoint is a unix socket, mode 0600
638 KB
cli binary
release build, arm64, measured on 2 nov 2026

decisions

//05decisions

  1. 01

    chose a Unix domain socket for the control endpoint

    over an HTTP server on a localhost port

    A port is reachable from any local process and, through DNS rebinding or a form POST, from a web page. A socket file with mode 0600 and a peer-uid check is scoped by the filesystem. It cost a hand-written HTTP/1.1 parser, since NWListener cannot bind a socket, but curl --unix-socket still works.

  2. 02

    chose expiring leases for agent sessions

    over trusting start and end hooks

    End hooks never fire when an agent crashes or is killed, which would leave the Mac awake all night. A lease renewed on every event releases on its own when the agent goes quiet.

  3. 03

    chose preventing idle display sleep

    over the system-wide PreventSystemSleep assertion

    The system assertion only applies on AC power and still does not stop the sleep that closing the lid forces. Idle sleep is the case every session needs, and it needs no privileges.

  4. 04

    chose a one-line sudoers rule for the lid-closed hold

    over a privileged helper daemon

    Closing the lid sleeps the Mac whatever any app asserts; only the root-only pmset disablesleep setting overrides it. One admin prompt installs a rule, checked by visudo first, that lets one user run exactly that command on and off. That avoids a signed helper and XPC, but the setting outlives the app, so Wakehold clears it on quit and again on the next launch.

  5. 05

    chose no App Sandbox

    over a sandboxed, store-ready build

    Watching arbitrary processes and ports and wrapping commands needs access the sandbox forbids. The app is built from source instead of distributed through the App Store.

try it

//06try it

  1. //build the menu bar app

    git clone https://github.com/KhaledSaeed18/wakehold && cd wakehold && open Wakehold.xcodeproj

    xcode 16 or later, macos 14 or later

  2. //build the cli

    swift build --package-path WakeholdKit -c release --product wakehold
  3. //hold while a command runs

    wakehold -- pnpm build

    the app must be running

highlights

//07highlights

  • Menu bar app, CLI and a control endpoint over a Unix socket
  • Watches processes, ports, commands, agents, apps and timers
  • Hooks for Claude Code, Codex, Gemini CLI and Cursor with crash-safe leases
  • Post-session sleep, shutdown, restart or notify; battery guardrails
  • Opt-in hold that keeps a closed laptop awake while a session runs
  • Localised in English and Arabic, with mirrored layout
  • Native Swift with IOKit power assertions, no Electron

built with

  • Swift
  • SwiftUI
  • IOKit
  • Swift Testing

on githubwakehold

stars
5
license
MIT
language
Swift
last push
nov 2, 2026

printings

//08printings

  1. First commit

    The kit, the IOKit assertion, the socket endpoint, the CLI, agent leases, post-session actions and guardrails, most of it in one day.

  2. Arabic localisation

    Menu, settings and duration plurals in a second language, with a mirrored layout.

  3. Other holds in the menu

    Every process's sleep assertion read from IOKit and listed with its reason.

  4. Lid closed, and a real app around it

    An opt-in hold that keeps a closed laptop awake while a session runs, a click to toggle with the menu on a right click, sessions listed and ended from the menu, and settings rebuilt as a sidebar of panes. Tested end to end by driving the app, which found and fixed a menu crash and an agent lease that could never come back.

questions

//09questions

Does Wakehold need Accessibility or Screen Recording permission?
No. The only system prompt is Automation for System Events, and only if you arm shut down or restart as a post-session action. The notify action asks for notification permission, and turning on the lid-closed hold asks for an admin password once.
Does the CLI work without the app running?
No. The CLI and the agent hooks talk to the running app over its socket. The hooks do nothing when the app is absent, so an agent is never blocked by them.
Does it keep the Mac awake with the lid closed?
Yes, if you turn it on. A one-time admin prompt installs a rule that lets Wakehold switch system sleep off, and it does so only while a session holds: a two hour timer keeps a closed Mac awake for those two hours, a build until it exits. When the last session ends, the Mac sleeps.
Is there a download or a Homebrew formula?
Not yet. Build the app from the Xcode project and the CLI with Swift Package Manager; both are a single command. It runs on Apple Silicon and Intel Macs on macOS 14 or later.

related sheets

//10related sheets

//11contact

Say hello.I read everything.

Email is the fastest way to reach me. For anything that needs a conversation, book a call.

to

name
Khaled Saeed
country
Lebanon