A lightweight PowerShell script that mimics macOS's caffeinate — preventing your Windows PC from going to sleep.
Useful for:
- Preventing system idle or display sleep during long operations
- Simulating
caffeinate -i -dbehavior on Windows - Devs, gamers, streamers, or anyone who needs to keep their system awake
- ✅ Prevents system sleep and/or display sleep
- ✅ Supports timeout with
-t(in seconds) - ✅ Gracefully exits and restores sleep settings
- ✅ Supports basic cross-terminal execution (
cmd,PowerShell,Windows Terminal)
| Flag | macOS equivalent | Description |
|---|---|---|
-i |
caffeinate -i |
Prevent system idle sleep |
-d |
caffeinate -d |
Prevent display sleep |
-s |
caffeinate -s |
Alias for -i, for consistency |
-m |
caffeinate -m |
Not supported on Windows (logs a warning) |
-t <sec> |
caffeinate -t |
Timeout in seconds; keeps awake for duration |
-
Download the files Grab these two files from this repository:
caffeinate.ps1caffeinate.cmd
Place them in a user-level script folder like:
C:\Users\<YourUsername>\ScriptsCreate this folder if it doesn't exist.
-
Add that folder to your system PATH This allows you to run
caffeinatefrom any terminal.📌 Option A: With PowerShell
$scriptPath = "$HOME\Scripts" [Environment]::SetEnvironmentVariable("Path", "$env:Path;$scriptPath", "User")
📌 Option B: Manually
- Press
Win + S→ search for “Environment Variables” - Open “Edit the system environment variables”
- Click
Environment Variables - Under
User variables, findPath→ clickEdit - Add a new entry:
C:\Users\<YourUsername>\Scripts
- Press
-
Done ✅ Now you can run:
caffeinate -d -i
From PowerShell, cmd, or Windows Terminal just like on macOS.
Run from terminal (PowerShell or cmd):
caffeinate -i # Prevent system idle sleep indefinitely
caffeinate -d -i # Prevent both display and idle sleep
caffeinate -d -i -t 600 # Prevent sleep for 10 minutes (600 seconds)