Agent teams: stale pane ID prevents spawning new teams after TeamDelete
Description
After a team is deleted with TeamDelete, the internal pane tracking array retains the old iTerm2 pane ID. Spawning agents in a new team fails because the split logic tries to split from the dead pane.
This is distinct from #24385 (panes not closing on shutdown). Even when panes are properly closed and the team is fully deleted, the cached pane ID persists in the session and blocks all subsequent team usage.
Repro steps
TeamCreate→ spawn an agent viaAgentwithteam_name— agent opens in iTerm2 split pane (works fine)shutdown_request→ agent approves shutdown →TeamDeletesucceeds- Close the lingering pane (osascript
tell aSession to closeby unique ID) TeamCreatea second team → spawn a new agent → fails with:
````
Error: Session 'FE23EBFE-6FDD-42B7-A500-2C4DECDE802E' not found
The pane ID from step 1 is gone (pane closed, team deleted), but the split logic still references it.
Expected behavior
After TeamDelete, the pane tracking state should be fully reset. Spawning agents in a new team should work without restarting Claude Code.
Workaround
Restart Claude Code between team runs to clear the session-scoped pane cache.
Root cause (from #24385)
The internal pane tracking array (PW1in the minified source) only supportspush()and full reset — there's no removal of individual entries when a pane closes. The split logic may need to validate the target pane still exists before splitting, or fall back to the leader session.
TeamDelete should trigger a full reset of the pane tracking array, or the split logic should validate the target pane exists and fall back gracefully.
Environment
- macOS 15 (Darwin 25.3.0)
- iTerm2 native split pane mode
- Claude Code with
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗