An OpenCode plugin that prevents Windows sleep/hibernation while the AI is actively processing.
OpenCode issue #16954: When a computer goes to sleep during an OpenCode session, the TUI gets stuck and stops producing output after wake. This plugin prevents sleep only during active processing — not while idle.
Uses the Windows Power Request API (PowerCreateRequest, PowerSetRequest, PowerClearRequest) via Bun FFI to register DISPLAY and SYSTEM power requests. These appear in powercfg /requests as:
DISPLAY:
[PROCESS] opencode.exe
opencode: display required
SYSTEM:
[PROCESS] opencode.exe
opencode: system required
The plugin hooks into OpenCode's session lifecycle:
session.status: busy→ activates power requests (prevents sleep)session.status: idle→ deactivates power requests (allows sleep)session.error→ deactivates power requests (safety fallback)
Add to your OpenCode config (~/.config/opencode/opencode.jsonc):
OpenCode will automatically install it from GitHub on next server start.
| Method | Path |
|---|---|
| Run dialog | WIN+R → %USERPROFILE%\.config\opencode\opencode.jsonc |
| PowerShell | notepad $env:USERPROFILE\.config\opencode\opencode.jsonc |
| Explorer | Paste %USERPROFILE%\.config\opencode\ in address bar |
Note: Use
.jsonc(not.json) so you can include comments.
- Windows (uses
kernel32.dllPower Request API) - OpenCode with plugin support
- Bun (used for FFI)
After restarting OpenCode, run an elevated PowerShell:
# 1. Idle - should show NOTHING from opencode.exe
powercfg /requests
# 2. Send a message to OpenCode, then while it's processing:
powercfg /requests
# Should show 1 DISPLAY + 1 SYSTEM request from opencode.exe
# 3. After response completes:
powercfg /requests
# Should show NOTHING again- Entirely AI-coded using OpenCode
- Uses
PowerCreateRequest/PowerSetRequest(notSetThreadExecutionState) so requests appear inpowercfg /requests - Counter-based tracking: multiple "busy" events increment counter, single "idle" event forces full cleanup
- Cleans up handles via
PowerClearRequest+CloseHandleon deactivation - Only runs on Windows (
process.platform === "win32")
| Plugin | Platform | Method |
|---|---|---|
opencode-caffeinate |
macOS | caffeinate -dim |
opencode-sleep-inhibitor |
Linux/macOS | systemd-inhibit / caffeinate |
| this plugin | Windows | Power Request API |
MIT
{ "plugin": ["jkirsch-code/opencode-caffeinate-win32"] }