macOS's caffeinate, on Windows. Keep your PC and display awake from the
terminal, for as long as a command runs, or for a set time.
caffeinate -d -i npm run build # screen stays on until the build finishesI got too used to running caffeinate -d on my Mac to keep my laptop awake during long tasks. When I switched to Windows, I missed it enough to just build it myself.
This is a minimal Rust CLI that replicates caffeinate on Windows. Run it, your system won't sleep. Kill it with Ctrl+C, everything goes back to normal.
Keep system awake until you stop it:
caffeinateKeep the display awake too (mirrors caffeinate -d on macOS):
caffeinate -dKeep awake for a fixed duration (in seconds):
caffeinate -t 3600Keep awake only while a command runs, then exit automatically:
caffeinate -i npm run build
caffeinate -i rsync -av ~/Pictures/ /Backup/Pictures/
caffeinate -d -i docker build .Flags can be combined. -t and -i are mutually exclusive.
| Flag | What it does |
|---|---|
| (none) | Keep system awake until Ctrl+C |
-d |
Also keep the display on |
-t <seconds> |
Exit automatically after N seconds |
-i <command> |
Exit when the given command finishes |
-
Download
caffeinate.exefrom the latest release. -
Put it in a folder for your command-line tools, such as
C:\tools, and add that folder to your PATH once. In PowerShell:mkdir C:\tools move $HOME\Downloads\caffeinate.exe C:\tools\ [Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";C:\tools", "User")
-
Open a new terminal and run
caffeinate.
The exe isn't code-signed, so SmartScreen may warn you the first time. Click More info, then Run anyway.
If you have Rust installed:
cargo install --git https://github.com/dincertekin/caffeinate-windowsCargo puts caffeinate.exe in ~/.cargo/bin, which is already on your PATH.
Windows exposes a SetThreadExecutionState API that lets a process tell the OS to stay awake. Three flags matter:
ES_SYSTEM_REQUIREDprevents idle sleepES_DISPLAY_REQUIREDalso prevents the display from turning off (what-dadds)ES_CONTINUOUSholds the state until explicitly cleared or the process exits
On Ctrl+C or natural exit, the state is cleared so Windows immediately goes back to normal sleep behavior.