[BUG] Mouse clicks don't work in TUI until entering agent view and returning to the session
Bug description
In a normal interactive session, mouse clicks don't do anything in the TUI: clicking UI elements and links has no effect. If I open the agent view (claude agents / FleetView) and then go back to the session, the UI redraws and clicks work for the rest of that session.
This looks like the same root cause that #71465 analyzed. That issue was closed as stale with no maintainer response. The new detail here is that the agent-view round trip fixes it.
Steps to reproduce
- Start
claudein a terminal (in my case over SSH, no tmux). - Try to click an interactive element or link in the TUI. Nothing happens.
- Open the agent view, then return to the same session.
- Click the same kind of element again. Clicks now work.
Expected behavior
Clicks should work as soon as the session starts. Visiting the agent view shouldn't be needed.
Likely cause (based on the analysis in #71465)
In #71465 the reporter traced this in the bundle. Click and hyperlink dispatch are gated on altScreenActive. Wheel dispatch is not:
dispatchClick(e,t){ if(!this.altScreenActive) return false; ... }
getHyperlinkAt(e,t){ if(!this.altScreenActive) return; ... }
altScreenActive is only set from the mouse-tracking mount effect, through an optional chain (d?.setAltScreenActive(true, o)). The mouse-enable escapes (?1000h/?1006h) are written either way. If d is undefined at mount time, the terminal reports clicks but the app drops all of them.
Entering the agent view and coming back remounts the mouse-tracking wrapper. On that remount setAltScreenActive(true) succeeds. That would explain why the round trip "fixes" clicks. It also fits the observation in #71465 that two sessions with identical config behaved differently, which looks like a mount-order race.
Possible fixes, as suggested in #71465:
- gate click/hyperlink dispatch on whether mouse tracking is enabled, not only on
altScreenActive, or - make sure
setAltScreenActive(true)is always called whenever mouse tracking is enabled.
Environment
- Claude Code: 2.1.296 (native install)
- OS: Arch Linux, kernel 7.2.8-arch1-2
- Shell: zsh
- Connection: SSH, no tmux/screen
TERM=xterm-256color,TERM_PROGRAMunset- No
tuisetting insettings.json.CLAUDE_CODE_DISABLE_MOUSEandCLAUDE_CODE_DISABLE_MOUSE_CLICKSare not set.
Related
- #71465: clicks dead, wheel works,
altScreenActivegating analysis (closed as stale) - #96499: entering the agent view leaves the terminal mode changed (keyboard side)
- #66441: cursor invisible after returning from the agents view
- #88946: drag-select only works again after switching away and back
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗