Proposal: OSC 9 terminal notifications for TUI toasts #2942

Closed
opened 2026-02-16 17:37:55 -05:00 by yindo · 1 comment
Owner

Originally created by @mcheviron on GitHub (Nov 18, 2025).

Summary

Add optional OSC 9 desktop notifications from the TUI, triggered when important events occur (starting with TUI toasts for agent completion and approvals), similar to how the Codex TUI and Claude Code surface notifications when the terminal is not in focus.

Motivation

  • OpenCode is TUI-first, and many terminals (kitty, iTerm2, etc.) support OSC 9 notifications to surface important events when the terminal is not focused.
  • Codex TUI and Claude Code both send notifications so users know when an agent has finished or needs attention; adding a small, optional version here improves UX parity without external dependencies.

Proposed Scope (minimal version)

  • Add a small helper in that emits an OSC 9 sequence to stdout when running in a TTY (ESC ] 9 ; BEL).
  • Centralize usage through the existing toast system rather than calling OSC 9 all over the place:
    • In , when toast.show is called, also emit an OSC 9 notification using either the toast title or message.
    • The server and TUI event handling logic raise tui.toast.show events for noteworthy moments like:
      • When the agent finishes responding for the active session (for example, when the session transitions to idle).
      • When a new permission or approval is required for the active session.
    • The TUI then shows a visual toast and, via the helper, emits OSC 9 so supported terminals can show a desktop notification with the same text.

This keeps OSC 9 as a TUI-only concern, reuses existing UI primitives, and keeps the surface area small (no new endpoints, no SDK changes) while still giving a good default experience.

Possible Extensions / Open Questions

  • Add a simple config toggle under config.tui.notifications to enable/disable OSC 9 notifications or restrict them to certain events.
  • Consider further events (for example, long-running operations finishing) once a minimal version is in.
  • Potentially respect terminal focus if there is a straightforward way to get focus gained/lost signals via the current TUI stack, mirroring Codex TUI behavior of only notifying when unfocused.

If this sounds reasonable, I can open a PR implementing this.

Originally created by @mcheviron on GitHub (Nov 18, 2025). ### Summary Add optional OSC 9 desktop notifications from the TUI, triggered when important events occur (starting with TUI toasts for agent completion and approvals), similar to how the Codex TUI and Claude Code surface notifications when the terminal is not in focus. ### Motivation - OpenCode is TUI-first, and many terminals (kitty, iTerm2, etc.) support OSC 9 notifications to surface important events when the terminal is not focused. - Codex TUI and Claude Code both send notifications so users know when an agent has finished or needs attention; adding a small, optional version here improves UX parity without external dependencies. ### Proposed Scope (minimal version) - Add a small helper in that emits an OSC 9 sequence to stdout when running in a TTY (ESC ] 9 ; <message> BEL). - Centralize usage through the existing toast system rather than calling OSC 9 all over the place: - In , when toast.show is called, also emit an OSC 9 notification using either the toast title or message. - The server and TUI event handling logic raise tui.toast.show events for noteworthy moments like: - When the agent finishes responding for the active session (for example, when the session transitions to idle). - When a new permission or approval is required for the active session. - The TUI then shows a visual toast and, via the helper, emits OSC 9 so supported terminals can show a desktop notification with the same text. This keeps OSC 9 as a TUI-only concern, reuses existing UI primitives, and keeps the surface area small (no new endpoints, no SDK changes) while still giving a good default experience. ### Possible Extensions / Open Questions - Add a simple config toggle under config.tui.notifications to enable/disable OSC 9 notifications or restrict them to certain events. - Consider further events (for example, long-running operations finishing) once a minimal version is in. - Potentially respect terminal focus if there is a straightforward way to get focus gained/lost signals via the current TUI stack, mirroring Codex TUI behavior of only notifying when unfocused. If this sounds reasonable, I can open a PR implementing this.
yindo added the discussion label 2026-02-16 17:37:55 -05:00
yindo closed this issue 2026-02-16 17:37:55 -05:00
Author
Owner

@rekram1-node commented on GitHub (Nov 18, 2025):

I think that's an interesting idea

@rekram1-node commented on GitHub (Nov 18, 2025): I think that's an interesting idea
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2942