opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: Configurable notification urgency and persistence per event

Open iop098321qwe opened this issue 2 weeks ago • 1 comments

Feature hasn't been suggested before.

  • [x] I searched existing issues and pull requests and did not find an equivalent request.

Describe the enhancement you want to request

Please allow users to configure notification behavior per event, particularly task completion, permission requests, questions, and errors.

Problem

I frequently miss task-completion notifications because they disappear before I notice them. These notifications are important to my workflow, and I would like them to remain visible until explicitly dismissed without changing notification behavior for other applications.

OpenCode currently exposes notification enablement and sound settings, but not notification urgency or persistence.

Requested controls

Where supported by the terminal and operating system, allow users to configure:

  • Whether each event generates a desktop notification.
  • Notification urgency: low, normal, or critical.
  • Persistence: system default, a custom timeout, or until dismissed.
  • Whether notifications appear while OpenCode is focused or only in the background.

Please retain existing behavior as the default.

Platform considerations

I use OpenCode 2.3.0 in Foot on Omarchy Linux. Its notification handler keeps critical notifications visible until dismissed, but normal notifications expire. Setting a zero timeout alone does not make them persistent.

Urgency and persistence are platform-dependent. Unsupported preferences should fall back gracefully, and documentation should explain any terminal or notification-handler limitations.

Benefits

Users could make important events harder to miss while keeping routine notifications unobtrusive, without custom plugins or terminal-specific helper scripts.

iop098321qwe avatar Nov 17 '26 01:11 iop098321qwe

Thanks for the detailed request! In short, you'd like to set, for each event (done, error, permission, question), whether it sends a desktop notification, its urgency, how long it stays up and whether it shows while OpenCode is focused. The current behaviour would stay the default. Maintainers will consider it.

For context, here is what exists today. The attention settings (Alerts docs) are notifications, sound, volume, sound_pack and sounds, with nothing for urgency or how long a notification stays. The built-in notifications plugin asks for a notification only when the terminal is not focused. The TUI sends it through the terminal with just a title and a message.

Related:

  • #51221: asks for native D-Bus notification delivery on Linux instead of terminal escape sequences

Workaround as a plugin

I know you'd rather not need a plugin, but until then this TUI plugin uses notify-send, so your notification daemon gets the urgency directly. It defaults to critical for every event. It type-checks against the plugin API, but I haven't run it inside OpenCode. Save it as ~/.config/opencode/plugins/persistent-notifications/tui.ts:

import { spawn } from "node:child_process"
import { Plugin } from "@opencode/plugin/tui"

type Urgency = "low" | "normal" | "critical"

export default Plugin.define({
  id: "local.persistent-notifications",
  setup(context) {
    const opt = (key: string, fallback: Urgency): Urgency => {
      const value = context.options[key]
      return value === "low" || value === "normal" || value === "critical" ? value : fallback
    }
    const urgency = {
      done: opt("done", "critical"),
      error: opt("error", "critical"),
      permission: opt("permission", "critical"),
      question: opt("question", "critical"),
    }

    const send = (sessionID: string | undefined, level: Urgency, message: string, title?: string) => {
      const session = sessionID ? context.data.session.get(sessionID) : undefined
      if (session?.parentID !== undefined) return // skip subagents
      const child = spawn(
        "notify-send",
        ["--app-name=OpenCode", `--urgency=${level}`, title ?? session?.title ?? "OpenCode", message],
        { stdio: "ignore", detached: true },
      )
      child.on("error", () => {})
      child.unref()
    }

    const dispose = [
      context.data.on("session.execution.succeeded", (e) => send(e.data.sessionID, urgency.done, "Session done")),
      context.data.on("session.execution.failed", (e) => send(e.data.sessionID, urgency.error, e.data.error.message)),
      context.data.on("permission.asked", (e) => send(e.data.sessionID, urgency.permission, "Permission needs input")),
      context.data.on("form.created", (e) =>
        send(e.data.form.sessionID, urgency.question, "Input needs response", e.data.form.title),
      ),
    ]
    return () => dispose.forEach((stop) => stop())
  },
})

To avoid getting two notifications per event, you can turn off the built-in plugin in ~/.config/opencode/cli.json. Note that this also turns off its attention sounds:

{
  "plugins": ["*", "-opencode.notifications"]
}

Limitations: this plugin needs notify-send and runs on the machine where the TUI runs. Unlike the built-in plugin, it notifies whether or not the terminal is focused.

Suggestion for maintainers: the plugin API's attention.notify has no urgency or timeout option. Plugins (and the built-in notifications plugin) could support this request without calling notify-send if attention.notify accepted optional urgency and timeout/persistent fields. The renderer would pass them on where the terminal's notification protocol supports them and keep the current behaviour elsewhere. On top of that, the attention config could gain per-event overrides.

opencodejr[bot] avatar Nov 17 '26 01:11 opencodejr[bot]