ai
Claude Code skills I use and am happy to share.
| Skill |
What it does |
mac-keep-awake |
Stops a Mac sleeping while any Claude Code session — including background subagents — is still reasoning, and lets it sleep normally once everything goes idle. |
mac-keep-awake
macOS sleeps mid-run and your work stops. The usual fixes don't hold: caffeinate wrapped
around a session releases at the end of the turn while a subagent is still working, and
pmset -a sleep 0 trades the problem for a laptop that cooks in a bag.
This holds a sleep assertion exactly while at least one session is reasoning. Hooks write a
marker per session; a launchd supervisor turns the union of those markers into a single,
never-lapsing caffeinate -i, and drops it once the last one clears.
Nothing needs sudo. Nothing changes your pmset timeouts.
Install
claude plugin marketplace add ylexus/ai
claude plugin install ai@ylexus
That is all of it. The plugin supplies the hooks itself, so nothing edits your
settings.json, and no clone or symlink has to stay in the right place. claude plugin update ai@ylexus takes a new version.
What it puts on your machine, since it is fair to know before enabling a plugin that runs
on every session: a launchd LaunchAgent (com.ylexus.claude-awake) and a copy of the
supervisor at ~/.local/share/claude-awake/, both created on the first session after install
by the plugin's SessionStart hook. Marker files live in ~/.cache/claude-awake/. No sudo,
no pmset changes, no network access. claude plugin uninstall ai@ylexus stops the hooks;
scripts/uninstall.sh removes the LaunchAgent and the rest.
The LaunchAgent runs that copy rather than the plugin's own file on purpose — a plist stores
an absolute path, and a plugin's directory moves on every update and is later reclaimed.
Prefer not to use plugins? scripts/install.sh from a clone does the same job by writing the
hooks into settings.json.
bash skills/mac-keep-awake/scripts/status.sh # is it working?
bash skills/mac-keep-awake/scripts/uninstall.sh # take it off
Why it is shaped this way
Three findings drove the design, all of them the hard way:
- A gap of any length is fatal. macOS does not restart the idle-sleep timer when an
assertion drops — it re-evaluates it. The timer has already elapsed underneath, so the Mac
sleeps the instant the assertion lapses (measured: 5 seconds). A chain of renewed
caffeinate calls therefore cannot work; one untimed assertion is the only robust shape.
Stop is not the end of the work. Background subagents keep reasoning after the parent
turn ends, and UserPromptSubmit never fires again for them. Arming on PreToolUse and
releasing only after a grace window is what covers them.
- A black screen is not sleep. The display sleeps on its own timeout, and
powerd,
backupd, AddressBookSourceSync and sharingd all block idle sleep on their own account
for many minutes. Only Entering Sleep state in pmset -g log proves anything.
The full diagnosis — the log evidence, the sleep-reason table, the confounders, and two bugs
that only surfaced under verification — is in
references/diagnosis.md.
Verified, not assumed
Both directions were tested on real hardware with the sleep timeouts temporarily lowered:
- Positive — a subagent still working after the parent turn's
Stop, 11 minutes,
223 samples: one unchanging caffeinate pid, zero samples with nothing holding sleep, no
sleep. The markers oscillated between armed and grace eight times; the grace absorbed each.
- Negative — nothing reasoning: the assertion released at 21:27:22 and
Entering Sleep state due to 'Idle Sleep' landed at 21:27:29, on battery.
The rig is scripts/claude-awake-verify.sh, and the procedure is in the skill.
Requirements
macOS (uses launchd, caffeinate and pmset), Claude Code, and python3 for the
settings.json patch. Tested on macOS 26.6.
Licence
MIT — see LICENSE.