Tmux
Remote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output
Category: development Source: tmux/tmuxTmux is a community skill for terminal multiplexer control, covering session management, pane navigation, window operations, keystroke automation, and output scraping for remote terminal interaction and CLI automation.
What Is This?
Overview
Tmux provides AI agents and automation tools with the ability to control tmux terminal multiplexer sessions programmatically by sending keystrokes and capturing pane output. It covers session management that creates, attaches, detaches, and lists tmux sessions running in the background, pane navigation that splits windows into multiple panes and switches focus between them for parallel workflows, window operations that create, rename, and switch between multiple window tabs within a single session, keystroke automation that sends commands and keyboard input to specific panes programmatically for interactive CLI control, and output scraping that captures text displayed in panes for processing and verification. The skill enables AI agents to interact with interactive terminal applications that require keystroke sequences and cannot be controlled through standard input redirection, such as database configuration wizards, interactive installers, and menu-driven administration tools.
Who Should Use This
This skill serves AI agents automating interactive CLI tools, developers managing persistent terminal sessions, and automation engineers controlling long-running terminal processes. It is particularly valuable for teams operating in remote server environments where session continuity is critical.
Why Use It?
Problems It Solves
Interactive CLI applications that prompt for user input cannot be automated with simple shell scripts that use standard input redirection. Long-running terminal processes terminate when SSH sessions disconnect or terminal windows close. Managing multiple parallel terminal workflows requires switching between windows manually or running separate terminal emulator instances. Capturing output from interactive applications for verification and processing is difficult when programs update display in place rather than printing new lines.
Core Highlights
Session manager creates and controls persistent terminal sessions in background. Pane controller splits windows and manages multiple parallel terminals. Keystroke sender automates input to interactive CLI applications programmatically. Output scraper captures pane text for processing and verification.
How to Use It?
Basic Usage
tmux new-session -d \
-s automation
tmux send-keys -t \
automation "ls -la" Enter
tmux capture-pane -t \
automation -p
tmux split-window -h -t \
automation
Real-World Examples
tmux new -d -s myapp
tmux send-keys -t myapp \
"python interactive.py" \
Enter
sleep 2
tmux send-keys -t myapp \
"option1" Enter
tmux send-keys -t myapp \
"yes" Enter
tmux capture-pane -t myapp \
-p | grep "Success"
tmux split-window -h
tmux send-keys -t 1 \
"tail -f log.txt" Enter
Advanced Tips
Use tmux capture-pane with history limits to retrieve scrollback buffer content for long-running command output analysis. Specify the -S flag with a negative line number to extend how far back the capture reaches, which is useful when commands produce verbose output over time. Create named sessions for different automation workflows to manage multiple parallel processes independently. Combine tmux with expect scripts for more sophisticated interactive automation with conditional responses based on output patterns. Additionally, use tmux environment variables and configuration files to standardize session layouts across different machines and team members.
When to Use It?
Use Cases
Automate interactive CLI tools that prompt for user confirmation and configuration input during execution. Maintain persistent development environments that survive SSH disconnections and can be reattached from different locations. Monitor multiple log files and processes simultaneously in split panes with centralized output capture for alerting and analysis.
Related Topics
Terminal multiplexers, CLI automation, session management, interactive shells, process control, and remote terminal access.
Important Notes
Requirements
Tmux installed and available in the system PATH for session management commands. Shell environment configured properly with PATH and environment variables for applications. Understanding of tmux command syntax for pane targeting and keystroke sending operations.
Usage Recommendations
Do: use named sessions to organize different automation workflows and avoid conflicts. Add delays between keystroke commands when automating interactive applications to allow processing time. Capture pane output to verify commands executed successfully before proceeding to next steps.
Don't: send keystrokes to the wrong pane by verifying pane targets before automation. Assume commands execute instantly since interactive applications may have processing delays. Leave tmux sessions running indefinitely without cleanup since they consume system resources.
Limitations
Keystroke timing issues can cause automation failures when interactive applications have unpredictable response times. Introducing fixed sleep intervals or polling loops that check captured output before sending the next keystroke can mitigate this problem. Capturing output from applications that use complex terminal control sequences may produce garbled text. Tmux sessions persist until explicitly killed, potentially accumulating over time and consuming resources if not managed properly.