feat(dashboard): spawn claude in new tmux window when \$TMUX is set
test / unit (pull_request) Successful in 18s
test / integration (pull_request) Successful in 1m10s

Option 3 from `docs/research/claude-code-pane-in-dashboard.md`,
opt-in by environment. When the dashboard runs inside tmux
(\$TMUX is set), both the new-agent (`n`) attach AND the
re-attach (Enter) paths spawn claude with
`tmux new-window -n <slug> docker exec -it … claude …` instead
of taking over the terminal via `curses.endwin`. The dashboard
keeps rendering in its current tmux pane; the operator switches
to the new window via tmux's normal nav.

Outside tmux the existing handoff path is unchanged — the
dispatch is a single `_in_tmux()` check per attach.

Mechanics:

  - `DockerBottle.claude_docker_argv` extracted from `exec_claude`,
    so both subprocess.run AND `tmux new-window` can build on the
    same docker-exec argv (preserving `--append-system-prompt-file`).
  - `_attach_via_tmux` in dashboard.py wraps the docker argv with
    `tmux new-window -n <slug> …` and returns immediately. Status
    line: `[slug] opened in new tmux window`.
  - `_build_tmux_attach_argv` split out as a pure helper so the
    wrapping shape is unit-tested without shelling out.

467 unit tests pass (2 new for `_build_tmux_attach_argv`).
This commit is contained in:
2026-05-26 14:00:03 -04:00
parent c8c72debff
commit 62ceab7485
3 changed files with 95 additions and 11 deletions
@@ -379,6 +379,29 @@ class TestBottleForSlug(unittest.TestCase):
self.assertEqual("", hint)
class TestTmuxAttachArgv(unittest.TestCase):
"""Pure builder for the tmux new-window argv. The subprocess
invocation is environment-dependent; here we lock the argv
shape so a regression in the wrapping surfaces in CI."""
def test_wraps_docker_argv_with_named_new_window(self):
docker_argv = [
"docker", "exec", "-it",
"claude-bottle-dev-abc",
"claude", "--dangerously-skip-permissions", "--continue",
]
argv = dashboard._build_tmux_attach_argv(docker_argv, "dev-abc")
self.assertEqual(
["tmux", "new-window", "-n", "dev-abc", *docker_argv],
argv,
)
def test_slug_lands_in_window_name_slot(self):
argv = dashboard._build_tmux_attach_argv(["docker", "exec", "x"], "my-bottle")
self.assertEqual("-n", argv[2])
self.assertEqual("my-bottle", argv[3])
class TestStopBottleFlow(unittest.TestCase):
"""Explicit per-bottle stop (PRD 0020 chunk 4). The non-owned
path is the one safe to test without curses + docker — the