Skip to content

About

OpenCode plugin that prevents Windows from sleeping while sessions are active. AI-coded using OpenCode.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

opencode-caffeinate-win32

An OpenCode plugin that prevents Windows sleep/hibernation while the AI is actively processing.

The Problem

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.

How it works

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)

Installation

Add to your OpenCode config (~/.config/opencode/opencode.jsonc):

{
  "plugin": ["jkirsch-code/opencode-caffeinate-win32"]
}

OpenCode will automatically install it from GitHub on next server start.

Windows config path

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.

Requirements

  • Windows (uses kernel32.dll Power Request API)
  • OpenCode with plugin support
  • Bun (used for FFI)

Verification

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

Implementation notes

  • Entirely AI-coded using OpenCode
  • Uses PowerCreateRequest/PowerSetRequest (not SetThreadExecutionState) so requests appear in powercfg /requests
  • Counter-based tracking: multiple "busy" events increment counter, single "idle" event forces full cleanup
  • Cleans up handles via PowerClearRequest + CloseHandle on deactivation
  • Only runs on Windows (process.platform === "win32")

Related projects

Plugin Platform Method
opencode-caffeinate macOS caffeinate -dim
opencode-sleep-inhibitor Linux/macOS systemd-inhibit / caffeinate
this plugin Windows Power Request API

License

MIT

About

OpenCode plugin that prevents Windows from sleeping while sessions are active. AI-coded using OpenCode.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages