Skip to content

fix(tmux): turn on focus-events when creating a session - #58

Open
jongracecox wants to merge 1 commit into
mainfrom
worktree/20261014-tmux-focus-events
Open

jongracecox wants to merge 1 commit into
mainfrom
worktree/20261014-tmux-focus-events

Conversation

@jongracecox

Copy link
Copy Markdown
Owner

Summary

Every Claude session fujimoto launches showed tmux focus-events off · add 'set -g focus-events on' to ~/.tmux.conf and reattach. tmux's server-wide focus-events option is off by default, so fujimoto now turns it on itself, the same way it already handles extended-keys.

  • New _ensure_focus_events() in tmux.py: reads show-options -sv focus-events and runs set-option -s focus-events on only if it isn't already on. Logged as tmux.focus_events previous=… changed=….
  • Called by create_session and create_session_with_command immediately after new-session. Claude Code probes tmux show -gv focus-events once at startup and caches the result, so setting it later in the create sequence would race that probe.

Reach to attached clients

tmux has no hook for changes to this option. It sends the outer terminal the focus-reporting enable sequence only in tty_update_features, which runs when a client attaches (checked in the tmux 3.6a source, tty.c / options.c). So the setting reaches new attaches only. That's fine for fujimoto, which always attaches after creating the session. A client that was already attached to some other session picks it up the next time it reattaches.

Tests

  • New TestEnsureFocusEvents: sets the option when it's off, skips setting it when it's already on, sets it when the option can't be read, writes the debug log line, and checks the call order for both create paths.
  • uv run pytest: 1151 passed.

CLAUDE.md is updated: the tmux.py module notes, plus a Gotchas entry next to the extended-keys one.

🤖 Generated with Claude Code

tmux's server-wide focus-events option is off by default, so Claude Code
gets no focus in/out events and shows a "tmux focus-events off" hint in
every session fujimoto launches. Set it right after new-session: Claude
Code reads the option once at startup and caches it, so it has to be on
before claude finishes loading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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