diff --git a/agent_cli/dev/terminals/tmux.py b/agent_cli/dev/terminals/tmux.py index 68c0922d..faac99c5 100644 --- a/agent_cli/dev/terminals/tmux.py +++ b/agent_cli/dev/terminals/tmux.py @@ -122,13 +122,21 @@ def _create_session( session_name: str, ) -> TerminalHandle | None: """Create a detached tmux session and return its initial pane handle.""" - return self._spawn_target( + handle = self._spawn_target( ["tmux", "new-session", "-d", "-s", session_name], path=path, command=command, tab_name=tab_name, session_name=session_name, ) + if handle is None: + return None + subprocess.run( + ["tmux", "set-option", "-t", session_name, "renumber-windows", "off"], # noqa: S607 + capture_output=True, + check=False, + ) + return handle def _spawn_target( self, diff --git a/tests/dev/test_terminals.py b/tests/dev/test_terminals.py index 6f27a2f3..e9a539aa 100644 --- a/tests/dev/test_terminals.py +++ b/tests/dev/test_terminals.py @@ -97,6 +97,35 @@ def test_open_in_session_creates_detached_session_when_missing(self) -> None: session_name="repo-session", ) + def test_create_session_disables_renumber_windows(self) -> None: + """New tmux sessions disable window renumbering.""" + terminal = Tmux() + mock_handle = MagicMock(handle="%42", session_name="repo-session") + with ( + patch.object(terminal, "_spawn_target", return_value=mock_handle) as mock_spawn, + patch("subprocess.run") as mock_run, + ): + handle = terminal._create_session( + Path("/some/path"), + "echo hello", + "test", + session_name="repo-session", + ) + + assert handle is mock_handle + mock_spawn.assert_called_once_with( + ["tmux", "new-session", "-d", "-s", "repo-session"], + path=Path("/some/path"), + command="echo hello", + tab_name="test", + session_name="repo-session", + ) + mock_run.assert_called_once_with( + ["tmux", "set-option", "-t", "repo-session", "renumber-windows", "off"], + capture_output=True, + check=False, + ) + def test_open_in_session_reuses_existing_session(self) -> None: """Outside tmux, a named session gets a new window when it already exists.""" terminal = Tmux()