opencode-caffeinate
v0.1.3
Published
Prevent macOS sleep while OpenCode sessions are active
Maintainers
Readme
opencode-caffeinate
Prevent macOS from sleeping while OpenCode sessions are active.
What it does
This plugin automatically runs caffeinate -dim when an OpenCode session starts, keeping your Mac awake during long AI coding sessions. When all sessions end, caffeinate is stopped to restore normal power management.
Flags used:
-d: Prevent display sleep-i: Prevent idle sleep-m: Prevent disk sleep
Installation
From npm (recommended)
Add to your opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-caffeinate"]
}From local files
Clone this repo to your plugins directory:
# Global plugins
git clone https://github.com/nguyenphutrong/opencode-caffeinate.git ~/.config/opencode/plugins/opencode-caffeinate
# Or project-level
git clone https://github.com/nguyenphutrong/opencode-caffeinate.git .opencode/plugins/opencode-caffeinateRequirements
- macOS only - The
caffeinatecommand is macOS-specific - Bun >= 1.0.0
- OpenCode with plugin support
How it works
- When a session is created (
session.createdevent), the plugin registers the session in/tmp/opencode-caffeinate/sessions/ - A single
caffeinateprocess is spawned if not already running (tracked via PID file at/tmp/opencode-caffeinate/caffeinate.pid) - Multiple parallel OpenCode instances are supported - sessions are tracked across processes
- When a session ends (
session.idleorsession.deletedevents), the session is unregistered - When all sessions across all instances end, caffeinate is stopped automatically
Cross-process synchronization: The plugin uses file-based session tracking to correctly handle multiple OpenCode instances running in parallel. Each session creates a PID file, and stale sessions (crashed processes) are automatically detected and ignored.
Development
# Install dependencies
bun install
# Run tests
bun run test
# Type check
bun run --bun tsc --noEmitLicense
MIT
