xa.tmux
Pure tmux wrappers.
No Claude Code knowledge lives here. Every public function takes a
binary keyword so callers can override the tmux executable (tests,
cross-platform installs, remote-host bridges).
Key gotchas encoded below:
session_target(name)returnsf"{name}:"— the trailing colon is essential. A bare session name can be silently resolved as a window or pane spec and mis-target a different session.list_sessionsreturns an empty list (not raises) when the tmux server isn’t running; tmux exits non-zero in that case and we absorb it.
- class xa.tmux.TmuxPane(target: str, pid: int, current_command: str, current_path: str)[source]
Minimal view of one tmux pane, from
list-panes -a.
- class xa.tmux.TmuxSession(name: str, created: int, activity: int, attached: bool)[source]
Minimal view of one tmux session, from
list-sessions.
- xa.tmux.capture_pane(name: str, *, lines: int = 200, binary: str = 'tmux') str[source]
Return the last
linesof the targeted pane, or ‘’ on failure.namemay be a session name (targets its active pane) or a full pane ref (session:@w.%p) for an exact pane.
- xa.tmux.descendants(pid: int) list[int][source]
All transitive descendant PIDs of
pid.Scans
/proc/*/status; silently tolerates races (processes dying mid-scan). Not available on non-Linux platforms — returns[]if/procis absent.
- xa.tmux.list_panes(*, binary: str = 'tmux') list[TmuxPane][source]
Every pane on the server, or
[]when no server is running.targetis the full pane ref, the same shape claude records in its ephemeral session file, so the two views join without parsing.
- xa.tmux.list_sessions(*, binary: str = 'tmux') list[TmuxSession][source]
Return all live tmux sessions; empty list if server isn’t running.
- xa.tmux.new_session(name: str, *, command: str, binary: str = 'tmux') None[source]
Create a detached tmux session running
commandas its pane’s program.commandis passed to a shell: the caller is responsible for quoting. Useshlex.quotefor untrusted parts.
- xa.tmux.pane_count(name: str, *, binary: str = 'tmux') int[source]
Number of panes (across all windows) in the session; 0 if gone.
- xa.tmux.pane_current_path(name: str, *, binary: str = 'tmux') str | None[source]
Working directory of the targeted pane’s program, or None.
This is where a pane’s shell would run a command, which is what
claude remote-control -ckeys its per-directory record on.
- xa.tmux.pane_pid(name: str, *, binary: str = 'tmux') int | None[source]
Return the pid of the first pane’s program, or None if the session is gone.
- xa.tmux.pane_pids(name: str, *, binary: str = 'tmux') list[int][source]
PIDs of every pane program in the session (all windows, all panes).
Empty list when the session is gone.
namemay be a session name or a full pane ref —-sscopes to the containing session either way.
- xa.tmux.pane_target(ref: str) str[source]
Target string for pane-scoped commands (capture, send-keys).
Accepts either a bare session name or a full tmux pane ref (
session:@window.%pane— the shape claude records in its ephemeral session file). A bare name targets the session’s active pane, which may not be the claude pane in a multi-window session — pass the full ref whenever you have one. Session names in xa match[A-Za-z0-9_.-]so they can never contain a:.>>> pane_target('foo') 'foo:' >>> pane_target('foo:@1.%2') 'foo:@1.%2'
- xa.tmux.pipe_pane_to_file(name: str, *, path: Path, binary: str = 'tmux') None[source]
Start streaming the pane’s output to
path(append mode).Uses
-oso a duplicate call toggles the pipe off, matching edualc’s behavior. tmux stops piping automatically when the pane dies.
- xa.tmux.proc_comm(pid: int) str[source]
Return the
commname of a pid (kernel-level process name), ‘’ if unreadable.
- xa.tmux.rename_session(old_name: str, new_name: str, *, binary: str = 'tmux') None[source]
Rename a live tmux session.
Both names must match the strict
[A-Za-z0-9_.-]{1,48}pattern used elsewhere inxa; callers should validate before calling.