Skip to content

emmanuel39hanks/mac-lid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mac Lid

Mac Lid

Close the lid. Walk away. Let claude keep cooking in your bag.

A macOS menu bar utility that keeps your Mac awake — even with the lid closed — while Claude Code or Codex CLI is mid-turn, and lets it sleep the moment they finish.

Download: grab the latest MacLid.zip from the Releases page, unzip, and drag MacLid.app to ~/Applications (or anywhere you like). Open it, click the menu bar ☕, and toggle Awake.

Features

  • Awake — master keep-awake toggle, holding PreventUserIdleSystemSleep.
  • Wait for AI agent turn — when on, the system-sleep assertion is only held while at least one tracked agent is in turn or waiting on input. Live status for each agent is shown inline.
  • Timer — auto-disarm after 15 m / 30 m / 1 h / 2 h / 4 h.
  • Stay awake with lid closed — runs pmset -a disablesleep 1. By default each toggle prompts for an admin password (osascript). Use More → "Install silent lid helper" to install a tightly-scoped /etc/sudoers.d/maclid rule (one prompt, silent forever after).
  • Keep display awake — holds PreventUserIdleDisplaySleep.
  • More — install/remove silent helper, reinstall agent hooks, reset agent state, open the data dir.

Building

Requires the Xcode 15+ Command Line Tools (Swift 5.9, macOS 13 SDK).

make app          # produces ./MacLid.app
make run          # builds and launches
make install-user # copies to ~/Applications/MacLid.app

How agent tracking works

On first launch, MacLid drops two tiny shell scripts into ~/.mac-lid/hooks/ and registers them as hooks in Claude Code's ~/.claude/settings.json and Codex CLI's ~/.codex/config.toml.

  • Claude Code: UserPromptSubmitin_turn, Stopidle, Notificationwaiting, SessionStart/SessionEndidle.
  • Codex CLI: UserPromptSubmitin_turn, Stopidle, SessionStartidle, plus the notify command as a backup for agent-turn-complete.

Each hook writes a JSON state file at ~/.mac-lid/state/<agent>.json via atomic rename. MacLid watches that directory with DispatchSource.

If you don't want MacLid touching your agent configs, choose Remove agent hooks from the More menu.

Lid-closed caveat

IOPMAssertion types do not override clamshell sleep on macOS — only pmset -a disablesleep 1 does, and that requires root. There are three ways MacLid drives that:

  1. sudo rule (recommended) — Menu → More → "Install silent lid helper". Asks for your password once, writes a 1-line file to /etc/sudoers.d/maclid whitelisting only pmset -a disablesleep 0|1. Subsequent toggles are silent.
  2. XPC helper via SMAppService — for users who install MacLid into /Applications (Apple gates daemon registration to that path). The bundle ships Contents/Library/LaunchDaemons/com.schemalabs.maclid.helper.plist ready to register.
  3. osascript prompt (default fallback) — every toggle asks for an admin password.

If MacLid is force-killed while the toggle is on, your Mac will keep SleepDisabled 1 until you re-launch MacLid (which resyncs) or run sudo pmset -a disablesleep 0 manually.

Layout

Sources/MacLid/
├── MacLidApp.swift         # @main, MenuBarExtra
├── AppModel.swift          # cross-cutting state
├── TimerController.swift
├── Power/
│   ├── AssertionManager.swift   # IOKit IOPMAssertion wrapper
│   └── ClamshellManager.swift   # pmset disablesleep via osascript
├── Agents/
│   ├── AgentState.swift
│   └── AgentStateStore.swift    # FS watcher
├── Integration/
│   └── HookInstaller.swift      # writes settings.json / config.toml
└── Views/
    ├── MenuPanel.swift
    ├── ToggleRow.swift
    └── AgentStatusRow.swift
Resources/
├── Info.plist
└── Hooks/
    ├── claude-state.sh
    └── codex-state.sh

License

MIT — © 2026 Emmanuel Haankwenda.

Credits

Inspired by a tweet from @amideau showing a similar menu mockup. Built with Claude Code.

About

macOS menu bar app that keeps your Mac awake while Claude Code or Codex CLI is in turn — then lets it sleep again.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors