A lightweight, cross-platform utility to prevent your system from going to sleep. Perfect for maintaining active connections, downloads, or any process that requires your system to stay awake.
- 🔄 Configurable keep-alive duration
- 💻 Cross-platform support (macOS, Windows, Linux)
- ⚡ Lightweight and efficient
- 🎯 Simple and intuitive to use
- 🛠 Zero configuration required
Download the latest binary for your platform from the GitHub releases page.
- Download the archive for your platform:
# For macOS:
curl -LO https://github.com/stigoleg/keep-alive/releases/latest/download/keep-alive_Darwin_x86_64.tar.gz
# For Linux:
curl -LO https://github.com/stigoleg/keep-alive/releases/latest/download/keep-alive_Linux_x86_64.tar.gz
- Extract the archive:
tar xzf keep-alive_*_x86_64.tar.gz
- Move the binary to a location in your PATH:
sudo mv keepalive /usr/local/bin/
- Download the Windows archive from the releases page
- Extract the archive
- Move
keepalive.exe
to your desired location - (Optional) Add the location to your PATH environment variable
Flags:
-d, --duration string Duration to keep system alive (e.g., "2h30m" or "150")
-c, --clock string Time to keep system alive until (e.g., "22:00" or "10:00PM")
-v, --version Show version information
-h, --help Show help message
The duration can be specified in two ways:
-
Using the duration flag (-d/--duration):
- As a time duration (e.g., "2h30m", "1h", "45m")
- As minutes (e.g., "150" for 2.5 hours)
-
Using the clock flag (-c/--clock):
- 24-hour format: "HH:MM" (e.g., "22:00", "09:45")
- 12-hour format: "HH:MM[AM|PM]" (e.g., "11:30PM", "9:45 AM")
- If the specified time is in the past, it's assumed to be for the next day
Note: You cannot use both duration and clock flags at the same time.
keepalive # Start with interactive TUI
keepalive -d 2h30m # Keep system awake for 2 hours and 30 minutes
keepalive -d 150 # Keep system awake for 150 minutes
keepalive -c 22:00 # Keep system awake until 10:00 PM
keepalive -c 10:00PM # Keep system awake until 10:00 PM
keepalive --version # Show version information
- Start the application without flags to enter interactive mode:
keepalive
- Use arrow keys (↑/↓) or j/k to navigate the menu
- Press Enter to select an option
- Press q or Esc to quit
Keep-Alive uses platform-specific APIs and techniques to prevent your system from entering sleep mode:
- Uses the
caffeinate
command with multiple flags to prevent:- System sleep (
-s
) - Display sleep (
-d
) - Disk idle sleep (
-m
) - System idle sleep (
-i
) - User activity simulation (
-u
)
- System sleep (
- Periodically asserts user activity using both
caffeinate -u
andpmset touch
- Automatically restores system power settings on exit
- Utilizes the Windows
SetThreadExecutionState
API with flags:ES_CONTINUOUS
: Maintain the current stateES_SYSTEM_REQUIRED
: Prevent system sleepES_DISPLAY_REQUIRED
: Prevent display sleep
- Implements a PowerShell-based fallback mechanism for additional reliability
- Restores default power settings on exit
- Primary method: Uses
systemd-inhibit
to prevent:- System idle
- Sleep
- Lid switch actions
- Fallback methods if systemd is not available:
xset
commands to disable screen saver and DPMS- GNOME settings modifications for idle prevention
- Automatically restores all system settings on exit
The application is built with reliability in mind:
- Process Monitoring: Continuously monitors the keep-alive processes and automatically restarts them if they fail
- Graceful Cleanup: Ensures all processes are properly terminated and system settings are restored on exit
- Resource Efficiency: Uses minimal system resources while maintaining effectiveness
The UI provides three main options:
- Keep system awake indefinitely
- Keep system awake for a specified duration
- Quit the application
When running with a timer, the application shows a countdown of the remaining time. You can stop the keep-alive at any time by pressing Enter to return to the menu or q/Esc to quit the application.
- Linux:
- systemd (recommended) or X11
- A terminal that supports TUI applications
- Go 1.21 or later
- Clone the repository:
git clone https://github.com/stigoleg/keep-alive.git
cd keep-alive
- Build the binary:
go build -o keepalive ./cmd/keepalive
Contributions are welcome! Please feel free to submit a Pull Request.
- Bubble Tea - The terminal UI framework that powers the interactive interface
- Lipgloss - Provides the beautiful styling for the terminal UI
- x/sys - Go packages for making system calls, especially useful for the Windows implementation
This project builds upon these excellent tools and APIs to provide a reliable, cross-platform solution for keeping your system awake.
This project is licensed under the MIT License.