8000 GitHub - habibtalib/lidawake: Keep your MacBook awake with the lid closed: menu bar switch, desktop widget, CLI and MCP server for pmset disablesleep, with timer and battery guard · GitHub
[go: up one dir, main page]

Skip to content
habibtalibPublic

About

Keep your MacBook awake with the lid closed: menu bar switch, desktop widget, CLI and MCP server for pmset disablesleep, with timer and battery guard

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

LidAwake

LidAwake

CI macOS 14+ Swift 5.10 MCP server Zero dependencies MIT License

Keep your MacBook awake with the lid closed.
A menu bar switch, a desktop widget, a CLI and an MCP server for sudo pmset -a disablesleep 1,
with an auto-off timer and a battery guard so you never forget it on.

Install · Features · Agent mode · Widget · CLI · MCP · Security


LidAwake menu bar panel, dark   LidAwake menu bar panel, light

💡 Why

Closing a MacBook's lid puts it to sleep, unless an external display, keyboard and power are all connected. That kills SSH sessions, long builds, downloads, agent runs and music over AirPlay.

sudo pmset -a disablesleep 1 stops that, but it needs a password every time, it is easy to forget, and a Mac left awake in a bag gets hot and drains the battery. LidAwake turns it into a one-click switch that turns itself off.

✨ Features

  • Menu bar switch. A big power button with a live countdown ring. The menu bar icon shows the state and the time left.
  • Extend in one click. +30m and +1h while a timer runs, or drag the custom slider (15 minutes to 12 hours).
  • Timer. Keep awake for 30 minutes, 1, 2 or 4 hours, or until you turn it off.
  • Battery guard. Sleep comes back on automatically when you are on battery at 10, 20 or 30% or below.
  • Desktop widget. Small and medium sizes with interactive buttons (macOS 14+).
  • CLI. lidawake on --for 2h, lidawake off, lidawake status --json.
  • MCP server. Lets Claude Code and other agents keep the Mac awake for long tasks, then switch it back.
  • No password prompts. One admin prompt installs a sudoers rule that allows only pmset -a disablesleep 1 and 0.
  • Agent mode. Turns on by itself while Claude Code is working and lets the Mac sleep once it goes quiet.
  • Auto-off. Sleep comes back on after agents are quiet, the Mac is idle, the internet is gone for too long, or the Mac runs hot.
  • Hide the menu bar icon. Settings → Show menu bar icon, or lidawake://menubar?show=0|1. LidAwake keeps running (timer, battery guard, agent mode); open the app again to reach Settings. Clausium uses this to host LidAwake's controls behind one icon. lidawake://set?batteryFloor=20 changes the battery guard from another app (rules go through lidawake rules).
  • Safe quit. Quitting while awake asks whether to turn sleep back on.
  • Zero dependencies. Swift, SwiftUI, WidgetKit and IOKit only.

📦 Install

Requires macOS 14 or later and the Xcode command line tools.

git clone https://github.com/habibtalib/lidawake.git
cd lidawake
Scripts/bundle-app.sh --install     # ~/Applications/LidAwake.app + ~/.local/bin/{lidawake,lidawake-mcp}
lidawake install-permission         # one admin prompt
open ~/Applications/LidAwake.app

Or click Install Permission in the menu bar panel instead of running lidawake install-permission. Turn on Launch at login in Settings so the timer and battery guard keep working after a restart.

Build with the desktop widget

Widgets need a team-signed app with an App Group. A free Personal Team works.

brew install xcodegen
LIDAWAKE_TEAM=<your team ID> Scripts/build-widgets.sh --install

Find your team ID in Xcode > Settings > Accounts. Then right-click the desktop > Edit Widgets > LidAwake.

⚙️ How it works

Piece What it does
pmset -g Read the current SleepDisabled value. No root needed.
/etc/sudoers.d/lidawake Lets your user run exactly /usr/bin/pmset -a disablesleep 1 and 0 without a password. Validated with visudo before install.
~/Library/Application Support/LidAwake/session.json The current session: when it started, the deadline, the battery floor and what started it.
Menu bar app Checks every 30 seconds and on every power-source change. Turns sleep back on when the timer ends or the battery floor is reached, and posts a notification.

The CLI and MCP server switch pmset directly. The timer and battery guard need the menu bar app running, or lidawake on --for 2h --wait in a terminal.

🤖 Agent mode

Turn on Agent mode in the panel (or lidawake rules --agent-mode on). LidAwake then keeps the Mac awake while an agent is working and lets it sleep again once the agents have been quiet for 10 minutes. No timers to remember.

LidAwake knows an agent is working from three signals:

Signal Setup How
Transcript writes none A Claude Code transcript in ~/.claude/projects (or $CLAUDE_CONFIG_DIR, ~/.claude-profiles/*) was written in the last 3 minutes. Only file times are read, never contents.
Claude Code hooks lidawake hooks install UserPromptSubmit/PreToolUse mark a session busy; Stop/SessionEnd mark it done. Your other hooks are left alone and settings.json is backed up first.
Keepalive none Any MCP agent calls lidawake_keepalive {minutes, reason}, or a script runs lidawake keepalive 45m --reason "nightly build".

Auto-off rules

These apply to every session, including ones you started yourself. Change them in the panel or with lidawake rules:

Rule Default Flag
Claude Code quiet 15 min --agents-quiet 15m|off
No keyboard or mouse (and no agents) 30 min --idle 30m|off
No internet (Wi-Fi with no internet or a captive portal counts as offline) 10 min --network 10m|off
Mac running hot (macOS thermal state) Serious --heat serious|critical|off

A live keepalive always wins over the first three rules. The timer, battery guard and heat guard always win over everything.

The internet check asks https://captive.apple.com about once a minute while LidAwake is on (or agent mode may turn it on), and counts the internet as gone after two failed checks in a row. The heat guard reads ProcessInfo.thermalState: serious means macOS is already throttling to cool down, critical means it is close to shutting down to protect itself.

🧩 Desktop widget

The widget shows the state, a live countdown and the battery level. Turn On / Turn Off and the 30m / 1h / 2h buttons work in place.

Widgets are sandboxed and cannot run sudo. A tap writes a small request to the shared App Group container and sends a Darwin notification. The menu bar app carries it out and refreshes the widget. If the app is not running, the widget shows Open LidAwake.

⌨️ CLI

lidawake on [--for <duration>] [--battery-floor <percent>] [--wait]
lidawake off
lidawake toggle
lidawake status [--json]
lidawake keepalive <duration> [--reason <text>]
lidawake release [--reason <text>]
lidawake rules [--agent-mode on|off] [--agents-quiet <dur>|off] [--idle <dur>|off] [--network <dur>|off] [--heat off|serious|critical]
lidawake hooks install|uninstall|status
lidawake install-permission
lidawake uninstall-permission
lidawake version
lidawake on --for 1h30m --battery-floor 20
lidawake status
# ON: the Mac stays awake with the lid closed (1h 29m left).
# Turns off on battery at 20% or lower.
# Started from: cli.
# Battery: 64% (on battery).

🤖 MCP server

claude mcp add lidawake -s user -- $HOME/.local/bin/lidawake-mcp
Tool Arguments
lidawake_status none
lidawake_on minutes?, battery_floor?, agent_mode?
lidawake_keepalive minutes? (default 30), reason?
lidawake_release reason? (omit to release all)
lidawake_off none

Example: "Hold the Mac awake while you run the migration, then release it." The agent calls lidawake_keepalive, does the work, then lidawake_release.

🔒 Security

  • The only command that runs as root is /usr/bin/pmset -a disablesleep 1 or 0. The sudoers rule names the full path and both exact argument lists, so no other arguments are allowed.
  • The rule is written for your user only, and only after the user name passes a strict character check.
  • The rule is checked with visudo -c before it is installed with mode 0440, owner root:wheel.
  • Remove it at any time: lidawake uninstall-permission, or delete /etc/sudoers.d/lidawake.

Heat warning: a Mac running with the lid closed on battery, inside a bag or sleeve, can overheat. The heat guard turns sleep back on at the serious thermal state by default; still use the battery guard and a timer.

🛠 Development

swift build
swift test
swift run LidAwakeApp

See CONTRIBUTING.md.

📄 License

MIT © 2026 Habib Talib

About

Keep your MacBook awake with the lid closed: menu bar switch, desktop widget, CLI and MCP server for pmset disablesleep, with timer and battery guard

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0