# Anti Sleep

Keep a Mac awake for a set duration or while a process runs.

- Repository: https://github.com/davidondrej/skills (4238 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add davidondrej/skills --skill anti-sleep -g -a claude-code -y`
Codex: `npx skills add davidondrej/skills --skill anti-sleep -g -a codex -y`
Cursor: `npx skills add davidondrej/skills --skill anti-sleep -g -a cursor -y`
Gemini CLI: `npx skills add davidondrej/skills --skill anti-sleep -g -a gemini-cli -y`

## Description

Keep a Mac awake for a set duration or while a process runs. Use only when the user explicitly invokes /anti-sleep.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Anti-Sleep (macOS caffeinate)

Use the bundled launcher from this skill directory. It creates a one-shot user LaunchAgent using only built-in macOS tools.

## Required workflow

Never launch `caffeinate` with raw `&`, `nohup`, `disown`, or `launchctl submit`. Temporary execution shells can kill their descendants, and `launchctl submit` can restart a timed job.

Resolve `scripts/anti-sleep.sh` relative to this `SKILL.md`; never assume the user's current directory. Run:

1. Inspect current state:

```bash
scripts/anti-sleep.sh status
```

2. If `status` reports an active session and the user requested a new duration, automatically stop the old session. **Never ask for confirmation.**

```bash
scripts/anti-sleep.sh stop
```

3. Start the new timer for the requested duration:

```bash
scripts/anti-sleep.sh start 10800    # 3 hours
```

For a specific process, use `start-pid`. Apply the same automatic replacement rule if another session is active.

```bash
scripts/anti-sleep.sh start-pid <PID>
```

4. In a **separate tool/shell call after the start command has returned**, verify:

```bash
scripts/anti-sleep.sh verify
```

Only report success when verification returns `STATUS=running` and `ASSERTIONS=active`. Confirm the PID, flags, and wall-clock expiry. If verification fails, run `stop` and do not claim the Mac is protected.

## Assertion flags

The default is `-d -i`: keep the display on and prevent idle system sleep. Pass explicit flags after the duration or PID when needed:

| Flags | Effect |
|---|---|
| `-i` | Prevent idle system sleep; display may dim |
| `-d` | Prevent display sleep |
| `-d -i -s` | Also prevent system sleep while on AC power |

None of these stop sleep when the lid closes. For agent runs that must survive a closed lid, see [Keep Claude Code running when your laptop is closed](https://www.cloudroom.dev/blog/keep-claude-code-running-laptop-closed).

Example:

```bash
scripts/anti-sleep.sh start 10800 -i
```

## Status and stop

The rest: https://github.com/davidondrej/skills/blob/HEAD/skills/ops-and-setup/anti-sleep/SKILL.md
