Skip to content

fix(hooks): use terminal-notifier for macOS notification click-to-focus#2166

Open
1noilimrev wants to merge 3 commits intocode-yeongyu:devfrom
1noilimrev:fix/macos-notification-click-target
Open

fix(hooks): use terminal-notifier for macOS notification click-to-focus#2166
1noilimrev wants to merge 3 commits intocode-yeongyu:devfrom
1noilimrev:fix/macos-notification-click-target

Conversation

@1noilimrev
Copy link

@1noilimrev 1noilimrev commented Feb 27, 2026

Summary

  • Fix macOS notification click behavior where clicking an OpenCode session notification opens Finder instead of focusing the terminal
  • Replace osascript display notification with terminal-notifier -activate $__CFBundleIdentifier as the primary macOS notification backend
  • Gracefully fall back to osascript when terminal-notifier is not installed

Changes

  • src/hooks/session-notification-utils.ts: Added getTerminalNotifierPath export using the existing createCommandFinder factory; added eager pre-resolution in startBackgroundCheck darwin case
  • src/hooks/session-notification-sender.ts: Modified darwin case in sendSessionNotification to try terminal-notifier first with -activate $__CFBundleIdentifier for deterministic click-to-focus, falling back to osascript when terminal-notifier is not available
  • src/hooks/session-notification.test.ts: Added 3 new tests for darwin notification backend selection logic

Screenshots

Testing

bun run typecheck
bun run build
bun test src/hooks/session-notification.test.ts

Expected: typecheck exits 0, build exits 0, 14 tests pass (11 existing + 3 new)

Root cause: osascript -e 'display notification...' attributes notification ownership to Script Editor (com.apple.ScriptEditor2). When clicked, macOS tries to activate Script Editor; when it isn't running, Finder activates as fallback.

Fix: terminal-notifier -activate $__CFBundleIdentifier deterministically activates the terminal that launched OpenCode (e.g., com.mitchellh.ghostty for Ghostty, com.googlecode.iterm2 for iTerm2). The __CFBundleIdentifier env var is set by macOS and identifies the running app, working correctly even inside tmux sessions.

Related Issues


Summary by cubic

Fixes macOS notification clicks opening Finder instead of the terminal. Notifications now use terminal-notifier so clicks focus the terminal that launched OpenCode.

  • Bug Fixes
    • Use terminal-notifier on macOS, adding -activate $__CFBundleIdentifier when available for deterministic click-to-focus.
    • Fall back to osascript when terminal-notifier is not available.
    • Pre-resolve notifier paths on darwin; add backend selection tests with a shared mock helper and try-finally env cleanup.

Written for commit fbe3b54. Summary will update on new commits.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

@1noilimrev
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Feb 27, 2026
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 3 files

Confidence score: 4/5

  • This PR looks safe to merge; the issues are confined to tests and are moderate in severity rather than user-facing code.
  • src/hooks/session-notification.test.ts risks test pollution because process.env.__CFBundleIdentifier cleanup isn’t guarded with try/finally, so a failing assertion could leak state into other tests.
  • There’s also some duplicated mock setup in src/hooks/session-notification.test.ts, which is a maintainability concern but not a functional blocker.
  • Pay close attention to src/hooks/session-notification.test.ts - ensure env var cleanup is robust and consider extracting shared mock setup.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/hooks/session-notification.test.ts">

<violation number="1" location="src/hooks/session-notification.test.ts:372">
P2: Duplicate mock setup code across three test cases. Extract the `notifyCalls` array and `mockCtx` object creation into a shared helper function (e.g., `createMockCtx()`) to improve test maintainability.</violation>

<violation number="2" location="src/hooks/session-notification.test.ts:384">
P2: Test pollution risk: Environment variable mutation without try-finally. This test modifies `process.env.__CFBundleIdentifier` but places cleanup at the end of the test body. If an assertion fails or error is thrown before cleanup runs, the modified environment variable will leak to subsequent tests. Consider using try-finally or moving cleanup to the existing afterEach hook.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@1noilimrev
Copy link
Author

@cubic-dev-ai can u review again?

@cubic-dev-ai
Copy link

cubic-dev-ai bot commented Feb 27, 2026

@cubic-dev-ai can u review again?

@1noilimrev I have started the AI code review. It will take a few minutes to complete.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Addresses macOS notification click-to-focus behavior with a safe fallback to osascript and comprehensive test coverage.

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.

1 participant