777genius/claude-notifications-go

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

Open

#115 opened on Jul 13, 2026

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Go (100 forks)auto 404
bughelp wanted

Repository metrics

Stars
 (759 stars)
PR merge metrics
 (PR metrics pending)

Description

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.

Contributor guide