Skip to content

feat(terminal-launch): spawn new sessions into tmux pane when in TMUX (#74)#193

Merged
quangdang46 merged 1 commit into
masterfrom
feat/tmux-pane-spawning
May 22, 2026
Merged

feat(terminal-launch): spawn new sessions into tmux pane when in TMUX (#74)#193
quangdang46 merged 1 commit into
masterfrom
feat/tmux-pane-spawning

Conversation

@quangdang46
Copy link
Copy Markdown
Owner

What

When jcode is launched from inside an attached tmux session, every "open in new terminal" path (resume picker, /split, /selfdev, list_sessions) previously launched an entirely new terminal emulator. That blew the user out of tmux and lost the session/window grouping.

This addresses issue #74: #74

Changes

  • crates/jcode-terminal-launch/src/lib.rs:
    • detected_resume_terminal (unix branch) now returns "tmux" when $TMUX is set (tmux always sets this for processes inside an attached pane). Inserted ahead of KITTY_PID/WEZTERM_* checks so tmux wins over an outer GUI emulator.
    • Added "tmux" to resume_terminal_candidates lists for both Linux and macOS, ahead of the GUI emulators.
    • Added a tmux arm in build_spawn_command that runs:
      tmux split-window -d -c <cwd> '<shell>' \; select-layout tiled
      
      -d keeps focus on the originating pane; select-layout tiled re-flows so the new pane is visible.
  • Test detected_resume_terminal_recognizes_tmux_via_tmux_env covers detection priority.

Tests

$ cargo test -p jcode-terminal-launch
test result: ok. 3 passed; 0 failed

Notes / scope deviation from upstream

Upstream PR 1jehuang#78 puts the dispatch in src/cli/tui_launch.rs next to the --standalone flag handling. This fork extracted spawn dispatch into crates/jcode-terminal-launch (and removed --standalone per #102), so the tmux match arm is added there and reused by all callers automatically.

When jcode is launched from inside an attached tmux session, every
"open in new terminal" path (resume picker, /split, /selfdev, list_sessions)
previously launched an entirely new terminal emulator. That blew the
user out of tmux and lost the session/window grouping.

Detect TMUX via the $TMUX env var (tmux always sets this for processes
inside an attached pane) and add a tmux dispatch arm in
build_spawn_command:

    tmux split-window -d -c <cwd> '<shell>' \; select-layout tiled

`-d` keeps focus on the originating pane; `select-layout tiled` re-flows
so the new pane is visible. Add "tmux" to resume_terminal_candidates
ahead of the GUI emulators on both Linux and macOS so it wins
naturally when present.

Test `detected_resume_terminal_recognizes_tmux_via_tmux_env` covers
detection priority.

Ports upstream PR 1jehuang#78. Local
fork's spawn dispatch lives in `crates/jcode-terminal-launch` rather
than `src/cli/tui_launch.rs` (upstream's layout), so the tmux match
arm is added there and reused by all callers automatically.
Closes #74
@quangdang46 quangdang46 merged commit 87d0a60 into master May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant