777genius/claude-notifications-go

Ghostty cwd-fallback focuses an arbitrary tab when multiple sessions share a working directory — should require unambiguous match

開放

#115 建立於 2026年7月13日

 (0 則留言) (0 個反應) (0 位負責人)Go (100 個分叉)auto 404
bughelp wanted

倉庫指標

星標
 (759 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Summary

When a session has no captured ghostty_terminal_id, the Ghostty click-to-focus falls back to cwd matching (ghosttyFocusAppleScript in ax_focus_darwin.go), which focuses the first terminal whose working directory matches:

if termDir is normalizedCandidate then
    focus t
    return true
end if

With several Claude Code sessions running in tabs that share a working directory (very common: multiple sessions on one repo), this actively switches to an arbitrary — often dormant — tab that is not the session that sent the notification. That's worse than not switching tabs at all: the user is teleported to the wrong session.

Repro

  1. Open 3+ Ghostty tabs in the same directory, run claude in each.
  2. Ensure a session has no stored terminal ID (the common case, see companion capture issue).
  3. Click its notification → an unrelated tab in that directory gets focused.

Fix (verified locally)

Only tab-switch when the cwd match is unambiguous — count matches; if more than one terminal matches the candidate path, return false and let the existing AXDocument window-level fallback handle it (raises the window without changing tab selection):

set matchCount to 0
set matchedTerminal to missing value
repeat with t in allTerminals
    try
        set termDir to my normalizePath(working directory of t)
        if termDir is normalizedCandidate then
            set matchCount to matchCount + 1
            set matchedTerminal to t
        end if
    end try
end repeat
if matchCount is 1 then
    focus matchedTerminal
    return true
end if
if matchCount is greater than 1 then
    return false
end if

Unique-directory sessions keep exact-tab focus; ambiguous ones degrade gracefully to window focus instead of a wrong guess.

貢獻者指南