Don't let your Mac fall asleep, like a sir
Warning
A closed laptop has reduced airflow — do not put it in a bag or on soft surfaces while this
mode is engaged. If Chai crashes (rather than quitting normally), the override stays on until
you reboot or run sudo pmset disablesleep 0 yourself. Check the current state at any time
with pmset -g | grep SleepDisabled.
brew install ar4l/tap/chaiThe cask removes the quarantine attribute on install, so Gatekeeper won't complain about the app not being notarized.
Caution
Always use the fully-qualified name ar4l/tap/chai — including for upgrades
(brew upgrade --cask ar4l/tap/chai). The bare name chai resolves to the deprecated
official cask (upstream, 3.3.0, no lid-closed mode) and will silently replace this fork
with a downgrade.
Or build from source (requires the Xcode command line tools):
./script/build
cp -r .build/release/Chai.app /Applications/This is a fork of lvillani/chai that adds two preferences: keeping the Mac awake with the lid closed, and pausing on battery power.
Note
Upstream Chai runs in the App Sandbox. This fork does not — sandboxed processes cannot run
pmset with administrator privileges, which lid-closed mode requires.
Closing the lid normally forces sleep regardless of power assertions; the only supported
override is pmset disablesleep, which requires administrator privileges. With this preference
enabled, Chai runs pmset disablesleep 1 while a keep-awake session is active and
pmset disablesleep 0 when it ends (deactivation, timer expiry, or quitting Chai). To gain
privileges, Chai first tries a passwordless sudo -n, then falls back to a macOS password
prompt.
Important
If you use timed sessions with the lid closed, set up the passwordless sudoers rule. Without it, re-enabling sleep when the timer fires pops a password dialog — which nobody can answer while the lid is shut, so the Mac stays awake until you open it and dismiss the prompt.
Chai sets this up for you: when you start a timed session with lid-closed mode enabled and no
rule is installed, it offers to create /etc/sudoers.d/chai (validated with visudo before
install) after a single administrator prompt. The rule is scoped to exactly
pmset disablesleep 0 and pmset disablesleep 1 for your user. When you turn the preference
off, Chai offers to remove the rule again.
Prefer to do it manually? Run:
echo "$USER ALL=(root) NOPASSWD: /usr/bin/pmset disablesleep 0, /usr/bin/pmset disablesleep 1" \
| sudo tee /etc/sudoers.d/chaiTo remove it later: sudo rm /etc/sudoers.d/chai. Note the file holds a single user's rule —
on a multi-user Mac, the last user to install wins.
Enabled by default, matching upstream behavior. Turn it off and Chai pauses its keep-awake session while on battery power and resumes it on AC — so a "Forever" session can't silently drain the battery. While paused, the menu bar icon shows the empty mug and the menu reads "Paused While on Battery".
| Preference | Effect |
|---|---|
| Disable After Suspend | (Upstream) If the Mac does sleep and wakes back up, Chai deactivates itself instead of resuming the session. |
| Keep Awake When Lid Is Closed | Keeps the Mac running in clamshell mode via pmset disablesleep while a session is active. |
| Keep Awake on Battery | On by default. Turn off to pause sessions on battery power and resume on AC. |
Chai is better than Caffeine in a number of ways:
- It is open source, so we have nothing to hide.
- It uses power assertions to keep your Mac awake.
- Upstream Chai runs in the sandbox to keep your Mac secure (this fork trades that for lid-closed support — see above).
Icons are licensed from Glyphish and cannot be used outside this project.
