Caffeinate

A super simple CLI utility for keeping your PC awake.

All it does is:

SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
Sleep(...);

The computer is prevented from sleeping for as long as the program remains running. The display/monitor is still allowed to turn off. SetThreadExecutionState docs here.

And because it is CLI only, it can be used from session 0 (ex: from SSH connection).

Download

Download from the latest GitHub release (runs on 32 and 64bit):

Note: You may have to "unblock" the program after downloading: Right-click the exe file → Properties → Check "Unblock" at bottom right.

Usage

caffeinate.exe [duration] [--help]

The program will remain open and prevent sleep for the given duration, or forever if a duration is not given. Use SIGINT (ctrl+c), SIGHUP, SIGTERM, etc. to kill at any time.

  • Duration may be a whole number with an optional unit, or the word forever.
  • If duration is not given, forever is used.
  • Valid units: s (seconds), m (minutes), h (hours)
  • If a unit is not given, seconds is used.

Examples:

caffeinate.exe         # Forever
caffeinate.exe forever # Forever
caffeinate.exe 30      # 30 seconds
caffeinate.exe 30s     # 30 seconds
caffeinate.exe 120s    # 2 minutes
caffeinate.exe 2m      # 2 minutes
caffeinate.exe 36h     # 36 hours

WSL

Optional: Here is a small bash script for managing Caffeinate from WSL. Calling this script will kill all Caffeinate instances and start a new one in the background, thus ensuring only one is running and allowing you to reset or end the caffeinated duration.

Please modify to set the correct caffeinate.exe path and default duration as desired.

The interface nearly identical to caffeinate.exe, but the script may default the duration to a value other than forever. Also, if a duration of 0 is given, all Caffeinate instances are killed but a new one is not started.

Alternatives

  • Caffeine - If you want a GUI and lots of features.
  • Insomnia - If you want a simple GUI.

I created Caffeinate because I wanted a CLI solution that could be used from session 0. Specifically, to be able to keep my PC awake while SSH'ed into WSL.