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.
- 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
Add the plugin to your opencode.json or opencode.jsonc:
{
"plugin": ["opencode-notifications"]
}Restart OpenCode. The plugin will be automatically installed and loaded.
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 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
Focus detection is supported on:
- Linux with X11
- Tmux (works with X11 for window and pane-level detection)
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) |
Create ~/.config/opencode/opencode-notifications.json to customize:
{
"events": {
"complete": true,
"error": true,
"permission": true
}
}{
"events": {
"complete": true,
"error": false,
"permission": true
}
}- 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.
-
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
X11 - Check if xdotool works:
xdotool getactivewindowIf this returns an error, make sure xdotool is installed.
Make sure xdotool is installed and working on X11.
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)
Contributions are welcome! Please feel free to submit a Pull Request.