Skip to content

feat(tui): add terminal notifications via OSC escape sequences#23447

Closed
dexion wants to merge 1 commit intoanomalyco:devfrom
dexion:fix/macos-notifications
Closed

feat(tui): add terminal notifications via OSC escape sequences#23447
dexion wants to merge 1 commit intoanomalyco:devfrom
dexion:fix/macos-notifications

Conversation

@dexion
Copy link
Copy Markdown

@dexion dexion commented Apr 19, 2026

Issue for this PR

Closes #23446

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

macOS desktop notifications from OpenCode appear as "Script Editor" alerts with no click-to-focus. This happens because the app uses osascript -e 'display notification...' which macOS attributes to the Script Editor process.

This PR adds terminal-native notifications via OSC escape sequences that work directly through the terminal emulator (iTerm2, Kitty, etc.), requiring no external tools.

How it works:

  • New util/notify.ts — resolves notification method per terminal and formats OSC sequences
  • New util/osc.ts — shared helper that wraps OSC sequences for tmux/screen passthrough
  • Modified app.tsx — subscribes to session.idle, permission.asked, question.asked events
  • Modified clipboard.ts — refactors OSC 52 clipboard to reuse the shared wrapOscSequence helper
  • Modified tui-schema.ts + tui-migrate.ts — adds configurable notification_method option

Terminal detection ("auto" — default):

Terminal Method Why
iTerm2, Ghostty, Apple Terminal, Warp OSC 9 (\x1b]9;msg\x07) Native notification support with click-to-focus
Kitty, WezTerm, VTE-based OSC 777 (\x1b]777;notify;title;body\x07) Supported via xterm OSC 777
VS Code, Windows Terminal Bell (\x07) No OSC notification support
Other Bell (\x07) Safe fallback

Adapted from @kitlangton's draft PR #23212, but without the large provider.ts Effect/Schema refactor that caused merge conflicts.

How did you verify your code works?

Manual testing on macOS with iTerm2:

# OSC 9 — shows native iTerm2 notification, click focuses the tab
printf '\e]9;OpenCode: Response ready\a'

# OSC 777 — Kitty/WezTerm format
printf '\e]777;notify;OpenCode;Response ready\a'

# Bell fallback
printf '\a'

# tmux passthrough — wraps sequence correctly
TMUX=1 node -e "process.stdout.write('\x1b]9;test\x07')"

Verified that:

  • iTerm2 shows native macOS notification with correct attribution
  • Clicking notification focuses the correct iTerm2 tab
  • notification_method: "off" suppresses all notifications
  • notification_method: "bell" works as fallback in unsupported terminals

Screenshots / recordings

N/A — terminal behavior change, no UI changes in the TUI itself.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Send desktop notifications using terminal-native OSC escape sequences
instead of osascript, fixing the macOS issue where notifications appeared
as 'Script Editor' alerts with no click-to-focus support.

- OSC 9 for iTerm2, Ghostty, Apple Terminal, Warp (native integration)
- OSC 777 for Kitty, WezTerm, VTE-based terminals
- Bell fallback for unsupported terminals
- Auto-detects terminal via TERM_PROGRAM environment variable
- Configurable via notification_method in tui.json (auto|osc9|osc777|bell|off)
- Extracts shared wrapOscSequence helper for tmux/screen passthrough
- Refactors clipboard.ts OSC 52 to reuse the shared helper

Events that trigger notifications:
- session.idle: response ready
- permission.asked: permission required
- question.asked: question asked

Fixes anomalyco#23446
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate PRs Found

1. #23212 — "feat(tui): add terminal notifications"

2. #20963 — "feat(tui): built-in system notifications for session completion"

  • Status: Potentially related earlier work
  • Why: Addresses system notifications for TUI, which overlaps with the session.idle notification feature in the current PR.

The current PR (#23447) is the proper approach as it avoids the merge conflicts from #23212 while implementing the same terminal notification functionality using OSC escape sequences.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 19, 2026
@github-actions github-actions Bot closed this Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS notifications show as 'Script Editor' instead of terminal app — no click-to-focus

1 participant