Skip to content
JoJoAtkinsonPublic

About

lichbook (lich book): keep your MacBook awake with the lid closed, but only while it's plugged in. Built for Claude Code sessions, AI agents, and remote work on a docked Mac. CLI, menu bar skull, Control Center toggle, and a Claude Code skill.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

56 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

lichbook πŸ’€

Release License: MIT macOS 26+ Install

Close your lid. Your prompts, agents, and remote sessions keep running. Only while it's plugged in and you're logged in β€” unplug it, log out, or lay it to rest, and it sleeps like any mortal machine. (Need it awake off the cord for a while? That's roaming, and it has a battery floor.)

Install

Paste the whole block into Terminal. It's one command chained with &&, so it's safe to copy exactly as it is, and it stops at the first step that fails:

brew tap jojoatkinson/lichbook https://github.com/JoJoAtkinson/lichbook &&
brew trust jojoatkinson/lichbook &&
brew install lichbook &&
lich install &&
lich on
Step What it does
brew tap … adds this repo as a Homebrew tap
brew trust … third-party taps need explicit trust before brew will load them
brew install lichbook installs the CLI and builds the menu bar app on your machine
lich install one-time privileged setup. Asks for your password once
lich on πŸ’€ risen

That's it. Close the lid on a docked Mac and Claude Code sessions, claude remote-control, ssh sessions, and long jobs keep going.

Don't see the πŸ’€ in your menu bar? lich install checks and tells you which of the usual suspects is hiding it: macOS 26's System Settings β†’ Menu Bar β†’ "Allow in the Menu Bar", a full menu bar behind the notch, or a menu bar manager like Bartender or Ice. lich works fine without the icon.

Using Claude Code? There's an official skill. Install it with /plugin marketplace add JoJoAtkinson/lichbook and then /plugin install lichbook@lichbook, or just tell Claude: "install the skill at https://github.com/JoJoAtkinson/lichbook/blob/main/skills/lichbook/SKILL.md". After that, Claude can install lichbook for you, keep the Mac awake for long jobs, and hand it back when it's done. See For AI agents.

Use

Command What it does
lich status: risen or at rest, power source, sleep setting, watcher health, roam mode, battery vs. floor
lich on πŸ’€ risen: lid-close keeps the Mac awake while on AC
lich off ⚰️ at rest: normal sleep

Both states persist across logins. Updating is one word β€” it detects whether you installed via brew or a clone, updates accordingly, refreshes the menu bar app, and reloads the watcher:

lich upgrade

What happens when… (the everyday cases)

No sleep/wake theory required β€” while the lich is risen πŸ’€:

You… Your Mac…
leave it plugged in, lid closed stays awake indefinitely β€” Claude sessions, ssh, automations all keep running, screen locked behind the closed lid
finish up, close the lid, walk it over to the charger wakes within seconds of the cord going in and stays awake β€” hours later, ask it something from your phone and it answers. The plug is the on-switch; the lid never needs to open
use it plugged in, lid open never dozes off mid-task β€” idle sleep is off while risen
lock the screen (Ctrl+Cmd+Q, or just close the lid) keeps working behind the password screen β€” locked and asleep are different things; your session and its work continue
unplug it goes back to being a normal laptop: sleeps shortly after you stop using it (unless you asked it to roam)
log out, or run lich off fully mortal β€” sleeps like lich was never installed

All of these are field-tested. Every state beyond them β€” crashes, battery floors, multiple users, the works β€” lives in the full state table.

Roaming: staying awake on battery

Sometimes the work has to leave the desk β€” an agent mid-run you carry to the couch, a build you'd rather not babysit next to an outlet. Roaming is the lich risen without its phylactery: awake on battery, deliberately, with a floor that ends it before your battery pays for it.

Roaming has two layers, so a one-off never costs you your default:

  • Standing settings persist until you change them: always (unplugged never means sleep) or timer (unplugged, it stays awake until nobody has touched it for roam_mins, 30 min out of the box, then sleeps. The countdown starts when you stop using it, not when you unplug, and any keypress or trackpad touch starts it over).
  • Trips are temporary overlays: roam (until you next plug in) or roam 45 (a bounded window). When a trip is spent or expires, it evaporates β€” and your standing setting is simply back, untouched.
Command Kind What it does
lich roam trip stay awake unplugged until you plug back in
lich roam 45 trip for 45 minutes (45m works too)
lich roam always standing every unplug, from now on
lich roam timer standing unplugged, stay awake until roam_mins without use, forever
lich roam off clear the standing setting (and any trip)
lich roam status machine-readable <standing> <trip>, e.g. timer -, off once, timer until:<epoch>

Every arming form also raises the lich, so one command is enough from a cold start.

You run Lasts Your standing setting
roam / roam 45 this trip / this window kept β€” returns when the trip ends
roam always until roam off is the setting
roam timer until 30 min idle, every time you're unplugged is the setting

lich roam status is what the menu bar app parses β€” one bare line, no decoration. lich status says the same thing in English, plus the battery line described below.

The battery floor

Below the floor β€” 20% by default β€” roaming stops. No exceptions, no override flag. Not even always outranks it; that's the whole point of having it, and a machine that will run itself flat in a bag is a worse tool than one that sleeps.

  • A once or timed roam (a trip) that hits the floor is canceled: the trip is cleared, your standing setting is kept, and the log says why. Plug in, and re-arm it if you still want it.
  • always is suspended, not cleared: your standing preference survives the low battery and takes effect again once you've charged 5 points past the floor (25% by default). A few minutes on the charger, or a reading that wobbles back up a point, won't re-arm it at 21% just to end again.

The floor is checked every tick, alongside everything else, so a roam ends within ~5 seconds of crossing it β€” lid open or closed.

Config

Command What it does
lich config print the effective config, defaults included
lich config floor 15 battery floor, percent (5–95)
lich config roam_mins 45 what lich roam timer means, minutes (1–1440)

Values live in ~/.lich/config as plain key=value lines. No file, or a missing key, means the default (floor=20, roam_mins=30); anything else in there is ignored.

For AI agents

If you're an agent β€” or you're writing the prompt for one β€” and you were told to keep this Mac awake, hand the machine back when you're done:

lich done

That clears a trip (a once or bounded roam) so an unplugged Mac is free to sleep again. It deliberately does not touch the standing setting (always or timer β€” the owner's preference, not yours to spend) and does not lay the lich to rest β€” lich off stays a human decision.

The lichbook skill teaches Claude Code all of this, including how to install lichbook itself (Claude runs everything except the one lich install password prompt, which it hands to you).


The rules it enforces

Plugged in Logged in Risen Lid closed β†’
βœ… βœ… βœ… stays awake
❌ β€” β€” sleeps β€” unless roaming ⁺
β€” ❌ β€” sleeps
β€” β€” ❌ sleeps

⁺ Roaming is the one exception to the battery row, and only when you asked for it: risen and a roam armed and the battery above the floor. See Roaming. Logged out and at rest have no exceptions at all.

The power cord is the phylactery: while it feeds the machine, the lich stays risen. Sever it and the body returns to rest β€” within ~5 seconds, even with the lid already closed. That's not flavor text, it's the actual power contract, which is why you'll never cook the battery in a bag; roaming borrows against it on purpose, for a bounded time, and the floor calls the loan.

How it works

One bash script (lich, a few hundred lines, half of them comments β€” read it before you grant it sudo) plus one per-user LaunchAgent, com.lichbook.watcher:

  • The watcher runs lich watch, which every 5 seconds reads the risen flag and the power source and flips the hidden pmset disablesleep setting: 1 when risen and (on AC power or roaming), 0 otherwise. The same tick reads the battery percentage, so an expired timer, a spent one-shot, or a floor breach ends a roam within ~5 seconds. disablesleep is the only mechanism that blocks clamshell (lid-close) sleep β€” caffeinate cannot. Plain polling is deliberate: pmset -g pslog doesn't stream reliably under launchd (it exits after its header), and an event stream that can die takes disablesleep down with it.
  • The logged-in condition is free. Per-user LaunchAgents only run while you're logged in; at logout launchd sends SIGTERM and the cleanup trap restores disablesleep 0 before the process dies.
  • KeepAlive restarts the watcher if it ever dies, and the cleanup trap restores normal sleep on any exit.
  • Lid close locks the screen. Normally the lock rides along with sleep; since lich prevents the sleep, macOS never locks. The watcher detects the lid closing while risen, locks the console itself, and then verifies the lock took (IOConsoleLocked), warning in the log if it didn't. The lock rides on your Lock Screen setting β€” keep "Require password after screen saver begins or display is turned off" at Immediately (System Settings β†’ Lock Screen) or an opened lid can land on your desktop.

The risen state is just a flag file, ~/.lich/desired-state, containing on or off. The CLI, the menu bar app, and the Control Center toggle all flip the same flag; the watcher applies it within ~5 seconds. Anything else that can write a file β€” Shortcuts, ssh, cron β€” controls it the same way. Roaming is the same idea: ~/.lich/roam holds the standing setting (off, always, or timer), optionally followed by a trip (once or until <epoch>), and ~/.lich/config holds the floor and roam_mins settings. The watcher owns those files too β€” it's what clears a spent one-shot, an expired timer, or a roam that hit the floor.

What install does

  1. Writes /etc/sudoers.d/lichbook-<you> β€” passwordless sudo scoped to exactly two commands: pmset -a disablesleep 0 and pmset -a disablesleep 1 (validated with visudo -cf before going live). Per-user filename, so multiple users' installs never clobber each other's rule. (This must live in root-owned /etc/sudoers.d/, not in ~/.lich β€” a root grant in a user-writable folder would be a privilege escalation. Everything else lich remembers lives per-user in ~/.lich/.)
  2. Puts lich on your PATH by symlinking /usr/local/bin/lich β€” skipped when lich is already on PATH, as it is after brew install.
  3. Creates ~/.lich/desired-state (starts at rest).
  4. Writes and loads ~/Library/LaunchAgents/com.lichbook.watcher.plist. On a Homebrew install the watcher points at brew's stable opt path, not the versioned Cellar path, so upgrades don't break it.

lich uninstall removes all of it and restores normal sleep (only the log at ~/Library/Logs/lich.log is left behind, as the audit trail).

Running from a clone works the same: ./lich install, then lich on.

Menu bar app

Installed for you: the brew formula builds Lich.app on your machine during brew install (ad-hoc signing only trusts locally-built code β€” this is why there's no prebuilt download), and lich install copies it to /Applications and launches it. From a clone, make -C menubar first, then lich install picks it up the same way. If the build isn't there, install just says so and everything else works β€” the app is optional.

Prefer CLI only? lich install --no-app removes the menu bar app if it's there (login item included) and skips it from then on. The choice is persisted, so lich upgrade never resurrects an interface you declined. lich config no_app 1 does the same. Change your mind later with lich config no_app 0 and re-run lich install.

The icon is a status light β€” πŸ’€ risen, ⚰️ at rest β€” and any click opens the menu: live status lines, then checkboxes for Awake (the tool itself), the three roaming modes, and Start at Login, plus Quit. Numbers like the battery floor and timer minutes stay in lich config; the menu just reflects them. It shells out to the lich CLI, so the CLI stays the single source of truth.

The roaming checkboxes, in plain English:

  • Stay awake unplugged β€” this once β€” a trip; unticking it (or plugging back in) returns you to your standing setting below
  • Stay awake unplugged β€” always β€” standing setting
  • Stay awake unplugged β€” until idle N min β€” standing setting: unplugged, it stays awake until nobody has touched it for N minutes (N is your configured roam_mins, read live, so the label shows the real number)

The two standing settings are mutually exclusive; the trip rides on top of either. Durations are set with lich config roam_mins and nowhere else β€” the menu stays a switch, not a settings panel. The battery floor applies here exactly as it does from the CLI.

It registers itself as a login item on first launch (SMAppService); uncheck "Start at Login" in its menu if you'd rather it didn't.

Optional: Control Center toggle

macOS 26+, and the one piece with a heavyweight toolchain: full Xcode (Command Line Tools are not enough) plus brew install xcodegen. It is never installed unasked:

Command What it does
lich widget builds on your machine, installs, launches
lich widget remove takes it back out

Without the toolchain, lich widget warns you exactly what's missing and does nothing. (From a clone, controlcenter/build.sh is the same build by hand.)

Then, first time only: right-click the Desktop β†’ "Edit Widgets…" and close it again (forces the control gallery to re-scan β€” known Tahoe quirk), then Control Center β†’ customize β†’ add "Lich". Optionally drag the control onto the menu bar.

The widget is sandboxed and can do exactly one thing: read and write ~/.lich/desired-state. Roaming is not in the widget β€” use the CLI or the menu bar app for that.

Caveats

  • While awake with the lid closed, the machine vents less well. Fine on a desk; don't leave it running in a bag or on a couch cushion. Roaming makes that easier to do by accident β€” the battery floor is a floor, not a thermostat.
  • While disablesleep is 1 (risen and on AC or roaming), manual sleep (Apple menu β†’ Sleep) is also blocked. lich off first if you want that.
  • disablesleep survives reboots β€” it lives in /Library/Preferences/com.apple.PowerManagement.plist and powerd re-applies it at boot (measured, not assumed). So a crash, kernel panic, or hard reboot while risen leaves the Mac sleep-proof at the login window, where no watcher runs to fix it β€” during that window it won't sleep even on battery, lid open or closed. The first login repairs it within ~5 seconds. If a crashed machine has to sit unattended, log in once (or run sudo pmset -a disablesleep 0) before walking away.
  • Control Center shows power glyphs, not a skull β€” it only renders SF Symbols and Apple ships no skull or coffin. The πŸ’€/⚰️ live in the CLI and menu bar.
  • Log: ~/Library/Logs/lich.log.

Support policy

Tested and supported on the latest macOS only (currently macOS 26, "Tahoe" β€” the version this was built and verified on). Earlier versions: you're welcome to install it β€” lich install fails open, meaning every piece tries, warns if it can't, and the CLI keeps working with whatever succeeded β€” but it's untested there, only loosely supported, and gets no version checks, no gates, and no promises.

The formal behavior reference β€” every configuration worth naming, what the code verifiably does about it, and what is merely promised β€” lives in docs/STATE-TABLE.md.

Credits

All code here is original; these projects inspired the approach β€” tmad4000/nosleep (scoped sudoers, cleanup traps), Moarram/wake (minimal pmset wrapping), and hizzt/mac-sleep-tool (power-event-driven LaunchAgent β€” with its missing logout reset fixed here).

MIT licensed.

About

lichbook (lich book): keep your MacBook awake with the lid closed, but only while it's plugged in. Built for Claude Code sessions, AI agents, and remote work on a docked Mac. CLI, menu bar skull, Control Center toggle, and a Claude Code skill.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages