How to move a tmux pane to another session without restarting its process?
Short answer
tmux join-pane -s scratch # active pane of session 'scratch' -> split here
tmux join-pane -h -s scratch:2.1 # a precise pane (window 2, pane 1) of another session
tmux move-window -s scratch:1 -t : # or the whole window -> new window in this session
join-pane and move-window take a source (-s) in another session of the same tmux
server, and the process running in the pane survives the move: tmux re-parents the pane, it
does not restart anything. Typical case: a dev server launched in a quick throwaway session,
pulled into the main workspace without cutting it.
Details
The source can be a session name alone (scratch, meaning its active pane), a
session:window.pane form (scratch:2.1), or a pane id (%7), which is unambiguous and
works across sessions too. With move-window, -t : means “this session, next free index”;
name the session explicitly (-t main:) when running it from a script rather than from
inside tmux.
Once the source session loses its last pane it closes itself, so emptying a scratch session with joins needs no cleanup afterwards.
The limit is the server: sessions of the same server share one process tree, so panes move
freely between them. Two different servers (started with different sockets, tmux -L or
-S) cannot exchange panes; nothing short of restarting the process crosses that boundary.
This is the cross-session variant of pulling a pane from another window with join-pane,
covered earlier in the same cookbook; the targeting rules (qualify the source, prefer pane
ids over bare numbers) apply unchanged.
Verified on tmux 3.2a.