Keep your Mac running with the lid closed — without walking through an airport holding it half open.
nosleep on # disable sleep until you say otherwise
nosleep off # re-enable
nosleep 3600 # disable for 1 hour, auto-re-enable
nosleep # 30 minutes (the safe default — auto-recovers)That's it. ~200 lines of bash, zero dependencies, no telemetry.
# Curl (works on any Mac, no dependencies):
curl -fsSL https://raw.githubusercontent.com/tmad4000/nosleep/main/install.sh | bash
# Or via Homebrew:
brew install tmad4000/nosleep/nosleep && nosleep --setupEither path installs the binary to /usr/local/bin/nosleep, then runs nosleep --setup once to grant passwordless access to pmset (and only pmset). Fully reversible — nosleep --uninstall removes everything.
Manual install
curl -o /usr/local/bin/nosleep https://raw.githubusercontent.com/tmad4000/nosleep/main/nosleep.sh
chmod +x /usr/local/bin/nosleep
nosleep --setupOn May 13, 2026, Business Insider ran a story called "Good news, AI coders: You can keep your laptop running while closed" about developers walking around with their MacBook lids cracked open so their AI agents wouldn't die mid-task. One quoted developer:
"didn't know" about the tricks. "I think it's too much friction."
The friction is real — Apple's built-in caffeinate only prevents idle sleep. The moment you close the lid, your Mac sleeps anyway and your long-running coding agent, training job, download, or background task dies.
There's exactly one knob that actually works: sudo pmset -a disablesleep 1. But it prompts for a password every time, so nobody uses it. nosleep is that knob, wrapped to need a password exactly once (during setup), with a clean Ctrl+C trap so it can't leave your machine awake forever.
That's the whole product.
nosleep # 30 minutes (safe default, auto-recovers)
nosleep 3600 # 1 hour
nosleep 28800 # 8 hours (overnight job)
nosleep on # indefinitely, until you run `nosleep off`
nosleep off # re-enable sleep right now
nosleep status # show current sleep state
nosleep --help # full help
nosleep --versionAliases for on/off/status: --on/-on/-o, --off/-off/-O, --status/-s. All work the same.
Workflow for a long agent session:
nosleep on
# ...close the lid, walk to the coffee shop, your agent keeps running...
nosleep off # when you're doneWorkflow for a finite task:
nosleep 7200 # 2 hours
# Ctrl+C any time to cleanly re-enable sleepThe rescue lever: if you ran nosleep on an hour ago and aren't sure whether you're still in indefinite mode, just run plain nosleep. It overrides indefinite mode and auto-recovers in 30 minutes, with a clear "overriding indefinite mode" message. Use it whenever you're not sure.
nosleep is a 150-line bash wrapper around one Apple-supported command:
sudo pmset -a disablesleep 1 # disable sleep
sudo pmset -a disablesleep 0 # re-enable sleepThe --setup step writes a single sudoers rule at /etc/sudoers.d/pmset:
your_username ALL=(ALL) NOPASSWD: /usr/bin/pmset
That grants passwordless access to only pmset — not "all sudo," just the power-management binary Apple already ships. Everything else still needs your password.
The timed mode (nosleep 3600) installs a trap on INT and TERM, so closing the terminal or Ctrl+C cleanly re-enables sleep. The script will never leave your Mac unable to sleep on its own.
No telemetry, no analytics, no phone-home. Every command except nosleep update is local-only — they only invoke /usr/bin/pmset on your Mac. Read the source — it's ~200 lines.
The single network call in the script is the opt-in nosleep update command, which fetches the installer from GitHub to upgrade your local binary. It only fires when you ask for it. No background checks, no version pings, no update banners.
nosleep update # If you installed via curl
brew upgrade nosleep # If you installed via HomebrewBoth are idempotent — safe to run any time.
nosleep --uninstallRemoves the binary at /usr/local/bin/nosleep, removes /etc/sudoers.d/pmset, and re-enables sleep. Or, if you installed via Homebrew:
brew uninstall nosleep
sudo rm /etc/sudoers.d/pmset # if you ran --setupQ: Won't this drain my battery if I forget to turn it off?
A: Yes — that's why timed mode exists. nosleep 3600 auto-re-enables after an hour. The --on / --off mode is for sessions you actively manage.
Q: Is this safe to run with the lid closed?
A: Yes, that's the entire point. The Mac will continue running on battery (or AC if plugged in) until you call --off or the timer expires.
Q: Does this work on Apple Silicon?
A: Yes, M1/M2/M3/M4 all use the same pmset interface.
Q: Why not just use Amphetamine?
A: Amphetamine is great if you want a GUI. nosleep is for people who live in the terminal — one command, scriptable, no app to install, no menu bar icon. Use whichever fits.
Q: Does this prevent the screen from turning off too?
A: disablesleep affects system sleep, not display sleep. Combine with caffeinate -d if you also want the display to stay on.
Q: What about clamshell mode with an external monitor?
A: That already works on macOS by default when connected to power + external display + keyboard. nosleep is for the no-external-monitor case — i.e. you actually want your closed laptop to keep computing.
| OS | Equivalent |
|---|---|
| Linux (systemd) | systemd-inhibit --what=sleep --who=me --why="long task" sleep 3600 |
| Linux (any) | Disable suspend in your DE settings, or xset s off; xset -dpms |
| Windows | powercfg /requestsoverride PROCESS yourapp.exe SYSTEM or use Don't Sleep |
This repo is macOS-only by design. The pattern is the same everywhere: find your OS's "disable suspend" knob, wrap it in something that auto-cleans up.
Issues and PRs welcome. Keep it small. The whole appeal of this tool is that you can read every line in 30 seconds.
If you ship a port for another OS, link it here and I'll add a row to the table.
Originally part of vibe-coding-guide, spun out as a standalone repo after the May 13, 2026 Business Insider story made it clear a lot of people needed this.
Built by @tmad4000. MIT licensed.
