claude-code - 💡(How to fix) Fix [BUG] Agent spawning steals tmux focus from the user's pane [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#49184Fetched 2026-04-17 08:48:30
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4commented ×1

Error Message

Error Messages/Logs

Fix Action

Fix / Workaround

Workaround: None found. Tested tmux set-hook after-split-window "select-pane -l" — focus still jumps (hook may fire before Claude Code's focus switch completes, or Claude Code may use a different mechanism than split-window).

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

(This intersects with #23615 but is distinct)

When Claude Code spawns Agent Teams teammates, it creates new tmux panes that steal focus from the user's active pane — the cursor jumps to the new agent pane every time a teammate is spawned.

Impact: When spawning multiple agents in quick succession (common for parallel workloads), the user's pane loses focus repeatedly. Particularly disruptive for daemon-style Claude sessions that spawn agents autonomously — the human loses their cursor mid-typing and can break the command being tmux send-keys pasted

Workaround: None found. Tested tmux set-hook after-split-window "select-pane -l" — focus still jumps (hook may fire before Claude Code's focus switch completes, or Claude Code may use a different mechanism than split-window).

Suggested fix: Add the -d flag to pane creation calls so new panes are created without stealing focus. If Claude Code uses send-keys or another mechanism to switch focus after creation, that should also be gated.

What Should Happen?

Expected: New pane is created in the background. User's focus stays on their active pane.

Error Messages/Logs

Steps to Reproduce

  1. Be working in a tmux session with Claude Code
  2. Spawn an Agent Teams teammate (via the Agent tool)
  3. Focus jumps to the new pane

Claude Model

Not sure / Multiple models

Is this a regression?

No, this never worked

Last Working Version

No response

Claude Code Version

2.1.110

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

iTerm2

Additional Information

No response

extent analysis

TL;DR

Add the -d flag to pane creation calls in Claude Code to prevent new panes from stealing focus.

Guidance

  • Investigate how Claude Code creates new panes and switches focus to determine the exact method used, as the suggested fix assumes a specific mechanism.
  • Verify that adding the -d flag to pane creation calls does not introduce any unintended side effects, such as preventing necessary focus changes.
  • If Claude Code uses send-keys or another mechanism to switch focus after creation, ensure that this is also modified to respect the -d flag or an equivalent focus-control mechanism.
  • Test the fix with various scenarios, including spawning multiple agents in quick succession, to ensure the focus remains on the user's active pane.

Example

No code snippet is provided as the issue does not include specific code details, but the fix involves modifying the pane creation calls, potentially similar to tmux new-pane -d if Claude Code uses tmux commands directly.

Notes

The effectiveness of the suggested fix depends on how Claude Code interacts with tmux. If Claude Code does not use standard tmux commands for pane creation and focus management, a different approach may be necessary.

Recommendation

Apply the workaround by adding the -d flag to pane creation calls, as this directly addresses the reported issue of focus being stolen by new panes, and it is a targeted change that should minimize potential side effects.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING