# NonSleep > NonSleep keeps a MacBook working with the lid closed and no external display while AI coding agents (Claude Code, Cursor, Codex, omp, Antigravity) or long tasks run, then lets it sleep again the moment they finish. Open source, 100% offline, zero dependencies, macOS 13+ and Linux. Tools like `caffeinate` and Amphetamine rely on `IOPMAssertion`, which only blocks *idle* system sleep. When a MacBook lid closes without an external monitor, macOS forces sleep regardless of any `IOPMAssertion`. NonSleep instead manages `pmset -a disablesleep`, the one switch that survives a closed lid, and binds it to process-tracked, time-limited leases: when the agent turn ends, the process crashes, or the machine reboots, normal sleep is restored automatically. On Linux it uses systemd `logind` inhibitor locks and needs no root. Key properties: - Closed-lid operation with no external display and no power adapter required. - Agent-aware turn lifecycle: official hooks for Claude Code, Cursor, Codex, Antigravity; omp detected through its `"omp agent session"` power assertion; any MCP-capable agent through `nonsleep mcp`. - Fail-safe by design: every request is a lease tied to a PID, an expiry, and the current boot. A LaunchAgent reaper sweeps dead leases every 60 s. - Safety cut-outs: releases on battery below 20%, on serious/critical thermal state, and earlier still when the lid is closed on battery with no external display. - Minimal privilege: a sudoers rule allowing exactly `/usr/bin/pmset -a disablesleep 0` and `… 1`. No root daemon. - Air-gapped: no network code, no telemetry, no third-party packages. - English and Vietnamese interface (`config.language`: `auto`, `en`, `vi`). Install: `git clone https://github.com/Tran-Duc-Duy/nonsleep && cd nonsleep && scripts/install.sh` Primary commands: `nonsleep status`, `nonsleep on [DURATION]`, `nonsleep off`, `nonsleep sleep`, `nonsleep run -- CMD`, `nonsleep wait TARGET…`, `nonsleep auto`, `nonsleep integrate [AGENT…]`, `nonsleep doctor`, `nonsleep history`, `nonsleep mcp`, `nonsleep setup`. ## Docs - [README](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/README.md): install, menu bar app, full CLI reference, config keys, agent integration, benchmarks. - [Agent & developer guide](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/AGENTS.md): architecture, file layout, supported agents, trust invariants. - [Security policy](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/SECURITY.md): threat model, sudoers scope, reporting process, what is in and out of scope. - [Changelog](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/CHANGELOG.md): released versions and behaviour changes. - [Contributing](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/CONTRIBUTING.md): development setup, what a new agent integration requires. ## Source - [Engine](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/Sources/NonSleepKit/NonSleep.swift): state machine reconciling the `disablesleep` flag against live leases. - [Leases](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/Sources/NonSleepKit/Lease.swift): lease model and the cross-process on-disk store. - [Agent hooks](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/Sources/NonSleepKit/Integrations.swift): hook install/remove and event-to-action mapping per agent. - [MCP server](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/Sources/NonSleepKit/MCPServer.swift): stdio JSON-RPC server exposing `nonsleep_status`, `nonsleep_acquire_lease`, `nonsleep_release_lease`. - [Setup](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/Sources/NonSleepKit/Setup.swift): sudoers rule staging, reaper LaunchAgent, CLI symlink. - [CLI](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/Sources/nonsleep/main.swift): every subcommand. ## Optional - [Releases](https://github.com/Tran-Duc-Duy/nonsleep/releases): signed builds with SLSA Level 3 provenance. - [Issues](https://github.com/Tran-Duc-Duy/nonsleep/issues): bug reports and feature requests. - [Install script](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/scripts/install.sh): exactly what installation does. - [Uninstall script](https://github.com/Tran-Duc-Duy/nonsleep/blob/main/scripts/uninstall.sh): restores normal sleep and removes every installed artifact.