TmuxBackend: cached window target (wN1) never invalidates, breaks teammate spawning after window topology changes
Resolved 💬 2 comments Opened Mar 3, 2026 by ArthurAllshire Closed Apr 1, 2026
Bug Description
The TmuxBackend caches the tmux window target string (wN1) at module scope (cli.js:2678) on first successful call to getCurrentWindowTarget(). This cache is never reset or invalidated. When tmux windows are killed and recreated during a long-running session, the cached target becomes stale, causing all subsequent createTeammatePaneWithLeader() calls to fail with:
Could not determine pane count for current window
Reproduction Steps
- Start a Claude Code session in tmux
- Successfully spawn teammates using
Taskwithteam_nameparameter (works fine initially) - Kill some tmux windows (e.g.,
tmux kill-window -t :1) - Create new tmux windows
- Try to spawn teammates again with
Task+team_name - ERROR: "Could not determine pane count for current window"
Root Cause
In cli.js:2678:
wN1is declared at module scope and set once bygetCurrentWindowTarget()getCurrentWindowPaneCount(windowTarget)runstmux list-panes -t <wN1>- After window topology changes,
wN1points to a window/session target that no longer exists tmux list-panesexits non-zero, the function returnsnull, and the error is thrown- The error is reported to Sentry only (via
H6()), not to debug logs, making it hard to diagnose
Key Evidence
- Fresh sessions always work: New Claude processes compute
wN1fresh from current tmux state - Long-running sessions break: After multiple window create/kill cycles, the cache becomes stale
- Workaround: Restart the Claude session to force fresh
wN1computation
Suggested Fix
One of:
- Invalidate on failure: If
getCurrentWindowPaneCount()returnsnull, resetwN1 = nullso the next call recomputes - TTL cache: Expire
wN1after N seconds - Per-instance cache: Don't cache at module scope; compute per
TmuxBackendinstance - Recompute on error: In
createTeammatePaneWithLeader(), if pane count is null, try recomputing window target once before throwing
Option 1 is the simplest and most robust fix.
Environment
- Claude Code version: 2.1.62
- tmux version: 3.4
- Platform: Linux (Ubuntu, running on Sky/AWS)
- Relevant file:
/usr/lib/node_modules/@anthropic-ai/claude-code/cli.jslines 2671-2678
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗