Capture and inspect content from tmux sessions, windows, and panes — locally or over SSH. Useful for sharing terminal output with LLMs, debugging across multiple terminals, or monitoring long-running processes.
SSH
All capture and list functions accept SSH kwargs to target a remote machine: use host for an SSH alias, or ip + user + optional keyfile.
def pane( n:int=None, # Number of scrollback lines to capture, in addition to visible area (None uses default_tmux_lines, which is 500 if not otherwise set) pane:int|str=None, # Pane number to capture from (accepts both integers for window IDs and "%{int}" for global pane IDs) session:str=None, # Session name to target window:int=None, # Window number to target*, capture_output:bool=True, text:bool=True, ret:bool=True, host:str=None, # Optional SSH Host ip:str=None, # Optional SSH IP user:str=None, # Optional SSH user keyfile:str=None, # Optional SSH keyfile):
def list_panes( session:str=None, # Session name to list panes from window:int=None, # Window number to list panes from*, capture_output:bool=True, text:bool=True, ret:bool=True, host:str=None, # Optional SSH Host ip:str=None, # Optional SSH IP user:str=None, # Optional SSH user keyfile:str=None, # Optional SSH keyfile):
List panes for a session/window (or current if none specified)
def panes( session:str=None, # Session name to target window:int=None, # Window number to target n:int=None, # Number of scrollback lines to capture*, capture_output:bool=True, text:bool=True, ret:bool=True, host:str=None, # Optional SSH Host ip:str=None, # Optional SSH IP user:str=None, # Optional SSH user keyfile:str=None, # Optional SSH keyfile):
def sessions( n:int=None, # Number of scrollback lines to capture*, capture_output:bool=True, text:bool=True, ret:bool=True, host:str=None, # Optional SSH Host ip:str=None, # Optional SSH IP user:str=None, # Optional SSH user keyfile:str=None, # Optional SSH keyfile):
Grab history from all panes in all windows of all sessions as {session: {'win_num:name': {pane_num: content}}}
# pprint(sessions())
# pprint(sessions(host='hack'))
Searching nested results
windows() and sessions() return nested dicts. Use flatten_dict to search them as (path, content) tuples, where path identifies the session/window/pane source. The path string uses // separators showing the hierarchy, e.g. "mysession//0:bash//1" means session "mysession", window 0 named "bash", pane 1.
For example, find error lines across all tmux history:
errors = [(path, line)for path, content in flatten_dict(sessions(n=2000))for line in content.splitlines()if'error'in line.lower()]
Or find panes containing a command you remember:
found = {path: content for path, content in flatten_dict(windows(n=2000)) if'curl'in content}