opencode-notifications
v1.0.0
Published
Smart desktop notifications for OpenCode - only notifies when terminal is not focused (Linux)
Maintainers
Readme
opencode-notifications
Smart desktop notifications for OpenCode - only notifies when the terminal is not in focus.
This is the key differentiator from other notification plugins: if you're already looking at OpenCode, you won't be bothered with redundant notifications.
Features
- Smart focus detection - Only sends notifications when you're NOT looking at the terminal
- X11 support - Focus detection via
xdotool - Tmux support - Detects active tmux window/pane, works with multiple sessions
- Configurable events - Enable/disable notifications for specific event types
- Lightweight - No sound files, no complex dependencies
Installation
Add the plugin to your opencode.json or opencode.jsonc:
{
"plugin": ["opencode-notifications"]
}Restart OpenCode. The plugin will be automatically installed and loaded.
Requirements
X11
xdotool- For window focus detectionnotify-send- For desktop notifications (usually fromlibnotify-bin)
# Debian/Ubuntu
sudo apt install xdotool libnotify-bin
# Fedora
sudo dnf install xdotool libnotify
# Arch
sudo pacman -S xdotool libnotifyTmux
Tmux support works automatically when running OpenCode inside a tmux session. No additional setup is required.
When running inside tmux, notifications are suppressed only when both:
- The terminal window is focused (X11 level)
- The tmux window containing the OpenCode pane is active
This means you'll still receive notifications if:
- You switch to a different tmux window
- You're in a different tmux session
- The terminal itself is not focused
Platform Support
Focus detection is supported on:
- Linux with X11
- Tmux (works with X11 for window and pane-level detection)
Events
The plugin notifies on these OpenCode events:
| Event | Description |
|-------|-------------|
| complete | Generation/task completed (session.idle) |
| error | An error occurred (session.error) |
| permission | Permission needed (permission.asked) |
Configuration
Create ~/.config/opencode/opencode-notifications.json to customize:
{
"events": {
"complete": true,
"error": true,
"permission": true
}
}Disable specific events
{
"events": {
"complete": true,
"error": false,
"permission": true
}
}How It Works
- When the plugin loads, it captures the window ID of the terminal running OpenCode
- Before sending any notification, it checks if that window is still focused
- If the terminal IS focused, the notification is skipped (you're already looking at it!)
- If the terminal is NOT focused, the notification is sent
This simple approach ensures you're only notified when you need to be.
Troubleshooting
Notifications not appearing
Check if
notify-sendis installed:notify-send "Test" "Hello"Check your notification daemon:
- GNOME: Notifications should work out of the box
- KDE: Notifications should work out of the box
Focus detection not working
X11 - Check if xdotool works:
xdotool getactivewindowIf this returns an error, make sure xdotool is installed.
Notifications always showing (even when terminal is focused)
Make sure xdotool is installed and working on X11.
Tmux: Notifications showing when pane is visible
If you're getting notifications even when the tmux pane running OpenCode is visible:
- Make sure the tmux window is active (not just visible in a split)
- Check that
TMUX_PANEenvironment variable is set (it should be automatic)
License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
