@pedro_klein/pi-caffeinate
Prevent macOS and Linux from sleeping during Pi agent work
Package details
Install @pedro_klein/pi-caffeinate from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@pedro_klein/pi-caffeinate- Package
@pedro_klein/pi-caffeinate- Version
0.2.0- Published
- Jul 3, 2026
- Downloads
- 161/mo · 6/wk
- Author
- pedro_klein
- License
- MIT
- Types
- extension
- Size
- 5.2 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-caffeinate
Prevents the system from sleeping while Pi is working. Spawns a platform-native sleep inhibitor when the agent starts, kills it when the agent finishes.
I built this because long agent runs would let the laptop sleep mid-task, killing the process. This extension solves that without requiring any manual intervention.
Install
pi install npm:@pedro_klein/pi-caffeinate
What it provides
No tools or commands — runs silently in the background.
Events handled:
| Event | Action |
|---|---|
agent_start |
Spawn sleep inhibitor |
agent_end |
Kill sleep inhibitor |
session_shutdown |
Kill sleep inhibitor (crash/quit cleanup) |
While active, shows a ☕ icon in the Pi status bar (requires pi-status).
How it works
On agent_start, spawns a platform-native inhibitor:
| Platform | Command | Notes |
|---|---|---|
| macOS | caffeinate -i -w <pid> |
Prevents idle sleep; -w watches Pi's PID and auto-exits if Pi crashes |
| Linux | systemd-inhibit --what=idle sleep infinity |
Inhibits idle sleep via systemd |
| Other | (no-op) | Silently does nothing |
On agent_end or session_shutdown, kills the inhibitor process.
Multiple concurrent Pi sessions are safe — the OS deduplicates multiple inhibit assertions naturally, so running several sessions adds zero overhead.
Configuration
No configuration required — works out of the box.
Development
pnpm test # run tests
pnpm build # build for publish
pnpm typecheck # type-check without emitting
License
MIT