Keep your machine awake. Like caffeinate, but with more kick.
A tiny Rust CLI that prevents your computer from sleeping. Works on macOS, Linux and Windows.
brew install riza/tap/cocainecargo install --git https://github.com/riza/cocaine.gitDownload the latest binary for your platform from Releases, extract, and put it in your $PATH.
| Platform | Binary |
|---|---|
| macOS (Apple Silicon) | cocaine-aarch64-apple-darwin.tar.gz |
| macOS (Intel) | cocaine-x86_64-apple-darwin.tar.gz |
| Linux (x86_64) | cocaine-x86_64-unknown-linux-gnu.tar.gz |
| Linux (ARM64) | cocaine-aarch64-unknown-linux-gnu.tar.gz |
| Windows (x86_64) | cocaine-x86_64-pc-windows-msvc.zip |
cocaine [OPTIONS] [COMMAND]...
By default (no flags), cocaine prevents idle system sleep indefinitely until you hit Ctrl+C.
| Flag | Long | Description |
|---|---|---|
-d |
--display |
Prevent the display from sleeping |
-i |
--idle |
Prevent the system from idle sleeping |
-s |
--system |
Prevent the system from sleeping entirely |
-t |
--timeout <SECS> |
Stop after N seconds (default: 0 = indefinite) |
cocaine can run as a background daemon, keeping your machine awake without occupying a terminal.
# Start the daemon (default: prevent idle sleep)
cocaine daemon start
# Start with display-on and a 2-hour timeout
cocaine daemon start -d -t 7200
# Check if the daemon is running
cocaine daemon status
# Stop the daemon
cocaine daemon stopThe daemon writes a PID file to ~/.local/share/cocaine/cocaine.pid (Linux/macOS) or %APPDATA%\cocaine\cocaine.pid (Windows).
# Prevent idle sleep until Ctrl+C
cocaine
# Keep the display on
cocaine -d
# Keep the display on for 1 hour
cocaine -d -t 3600
# Prevent all sleep types
cocaine -d -i -s
# Keep awake while a command runs
cocaine -d -- make build
# Keep awake during a long download
cocaine -s -- curl -O https://example.com/big-file.tar.gzcocaine uses native OS APIs on each platform to prevent sleep:
| Platform | API | Mechanism |
|---|---|---|
| macOS | IOKit IOPMAssertionCreateWithName |
Creates power assertions that are released on exit |
| Linux | systemd-logind D-Bus Inhibit |
Holds an inhibit file descriptor via org.freedesktop.login1 |
| Windows | SetThreadExecutionState |
Sets ES_SYSTEM_REQUIRED / ES_DISPLAY_REQUIRED flags |
Assertions / inhibitors are automatically released when cocaine exits -- whether that's through Ctrl+C, a timeout, or a child command finishing.
# macOS
pmset -g assertions
# Linux
systemd-inhibit --list
# Windows (PowerShell)
powercfg /requests