Autorun tmux-automation
Complete CLI testing automation using tmux/byobu sessions with ai-monitor integration. Create automated workflows for testing plugins, CLIs, and terminal applications. Includes session management, keystroke control, output capture, and autonomous monitoring capabilities.
git clone https://github.com/ahundt/autorun
T=$(mktemp -d) && git clone --depth=1 https://github.com/ahundt/autorun "$T" && mkdir -p ~/.claude/skills && cp -r "$T/plugins/autorun/skills/tmux-automation" ~/.claude/skills/ahundt-autorun-tmux-automation && rm -rf "$T"
plugins/autorun/skills/tmux-automation/SKILL.mdAutomated CLI Testing with Session Management
This skill provides comprehensive capabilities for automated testing of CLI applications, plugins, and terminal workflows using tmux/byobu sessions with full ai-monitor integration. Perfect for testing Claude Code plugins, command-line tools, and automated workflows.
Core Commands
Session Management
- Create new detached sessionbyobu new-session -d -s <session-name>
- List all active sessionsbyobu list-sessions
- Attach to existing sessionbyobu attach-session -t <session-name>
- Detach from session (F6)byobu detach-session
- Terminate sessionbyobu kill-session -t <session-name>
- List tmux sessionstmux list-sessions
Window Management
- Create new windowbyobu new-window -t <session-name>
- List windows in sessionbyobu list-windows -t <session-name>
- Kill specific windowbyobu kill-window -t <session-name>:<window-index>
- Select windowbyobu select-window -t <session-name>:<window-index>
Input and Output Control
- Send keystrokes to windowbyobu send-keys -t <session-name> <keys>
- Send Enter/Return keybyobu send-keys -t <session-name> C-m
- Send Ctrl+C interruptbyobu send-keys -t <session-name> C-c
- Capture window outputbyobu capture-pane -t <session-name>
- Capture last N linesbyobu capture-pane -t <session-name> -p -S -<lines>
Tmux Commands (direct)
- Create new detached tmux sessiontmux new-session -d -s <session-name>
- List all tmux sessionstmux list-sessions
- Attach to tmux sessiontmux attach-session -t <session-name>
- Detach from tmux sessiontmux detach
Specific Keystroke Commands
Control Sequences
- Ctrl+C (interrupt/stop current command)C-c
- Ctrl+M (Enter/Return)C-m
- Ctrl+D (EOF/end of input)C-d
- Ctrl+L (clear screen)C-l
- Ctrl+A (tmux prefix, then command)C-a
- Ctrl+Z (suspend current process)C-z
- Tab completionTab
- Escape keyEsc
Byobu Specific Keys
- Create new windowF2
- Split window horizontallyShift+F2
- Split window verticallyCtrl+F2
- Previous windowF3
- Next windowF4
- Reload profileF5
- Detach sessionF6
- Search scrollback bufferF7
- Enter scrollback modeF8
- Configure byobuF9
/Shift+F3
- Move window left/rightShift+F4
/Ctrl+F3
- Focus pane left/rightCtrl+F4
Tmux Prefix Commands (default Ctrl+B)
- Create new windowCtrl+B c
- Kill current windowCtrl+B &
- Rename windowCtrl+B ,
- Next windowCtrl+B n
- Previous windowCtrl+B p
- Split window horizontallyCtrl+B %
- Split window verticallyCtrl+B "
- Switch panesCtrl+B o
- Detach sessionCtrl+B d
- List sessionsCtrl+B s
AI-Monitor Integration
The ai_monitor.py in autorun provides comprehensive tmux monitoring and automation:
Core AI-Monitor Functions
# Start monitoring a session start_monitor(session_id, prompt="Continue working", stop_marker="COMPLETE", max_cycles=5) # Stop monitoring stop_monitor(session_id) # Check if monitor is running check_monitor(session_id)
AI-Monitor Capabilities
- Session Discovery: Automatically finds tmux sessions and windows
- Content Monitoring: Tracks window content changes and detects meaningful updates
- Change Detection: Filters out minor changes (echoes) vs. substantial content updates
- Automatic Re-prompting: Sends continuation prompts when idle (configurable intervals)
- Stop Marker Detection: Automatically stops when specific completion markers appear
- Cycle Management: Limits number of re-prompt cycles to prevent infinite loops
- Window Management: Can target specific windows for monitoring and interaction
autorun Command Integration
autorun provides convenient commands for tmux session automation:
Session Discovery
- Discover and manage all Claude sessions across tmux windows/ar:tabs- Interactive table showing session status (working, awaiting input, etc.)
- Batch operations:
,all:continue
,awaiting:statusA:pwd, B:ls - AI-powered session analysis (uses Claude SDK when available)
Session Management
or/ar:tmux
- Create and manage isolated tmux sessions/ar:tm
- Create new isolated sessioncreate <name>
- List all sessions with health statuslist
- Remove sessions older than 1 hourcleanup
Testing Automation
or/ar:ttest
- Automated CLI testing in isolated sessions/ar:tt- Tests basic functionality, help system, custom commands
- 30-second timeout protection
- Clean session isolation
Related Documentation
- Session discovery user interfacecommands/tabs.md
- Enhanced session managementcommands/tmux-session-management.md
- Advanced automation patternsagents/tmux-session-automation.md
Quick Reference: Commands vs Manual tmux
| Task | Manual tmux Command | autorun Shortcut |
|---|---|---|
| List Claude sessions | (manual) | |
| Create session | | |
| Send to all sessions | | |
| Test CLI | Manual scripting required | |
AI-Monitor Configuration Options
- Custom prompt to send when idle--prompt/-p <text>
- Stop marker to detect completion--stop/-s <string>
- Delay before stopping after detecting stop marker--stop-delay-seconds <n>
- Maximum number of re-prompt cycles--max-retry-cycles/-c <n>
- Maximum runtime in minutes--max-runtime-minutes <n>
- Seconds between checks--check-interval <n>
- Send prompt immediately on start--prompt-on-start
- Target specific windows--start <window_numbers>
Usage Examples
Create Testing Session with AI-Monitor
# Create session (default: autorun) byobu new-session -d -s "autorun" # Navigate and start process byobu send-keys -t "autorun" "cd /path/to/project" C-m byobu send-keys -t "autorun" "npm test" C-m # Start ai-monitor (from separate terminal) python3 ai_monitor.py "autorun" --prompt "Continue testing" --stop "Tests completed" --max-cycles 3
Monitor Claude Code Session
# Create Claude Code session (default: autorun unless user specifies otherwise) byobu new-session -d -s "autorun" byobu send-keys -t "autorun" "cd /project" C-m byobu send-keys -t "autorun" "claude" C-m # Start monitoring for autonomous work python3 ai_monitor.py "autorun" --prompt "Continue working autonomously" --stop "AUTORUN_ALL_TASKS_COMPLETED" --max-cycles 10
Automated Plugin Testing Workflow
# Create session for autorun testing (default: autorun) byobu new-session -d -s "autorun" # Navigate to project (replace with your autorun directory) byobu send-keys -t "autorun" "cd \$HOME/.claude/autorun" C-m # Start Claude Code byobu send-keys -t "autorun" "claude" C-m sleep 5 # Set model to haiku for efficiency byobu send-keys -t "autorun" "/model haiku" C-m sleep 2 # Install plugin locally (replace with your autorun directory) byobu send-keys -t "autorun" "/plugin marketplace add \$HOME/.claude/autorun" C-m sleep 3 # Install plugin byobu send-keys -t "autorun" "/plugin install autorun@autorun" C-m sleep 5 # Test commands byobu send-keys -t "autorun" "/afs" C-m sleep 3 byobu send-keys -t "autorun" "/afst" C-m sleep 3 # Capture output for verification byobu capture-pane -t "autorun" -p -S -20
Error Handling and Recovery
# Check if session exists before operations if byobu list-sessions | grep -q "test-session"; then echo "Session exists, proceeding..." else echo "Session not found, creating..." byobu new-session -d -s "test-session" fi # Interrupt hanging commands byobu send-keys -t "test-session" C-c # Kill and recreate session if needed byobu kill-session -t "test-session" byobu new-session -d -s "test-session"
Common Mistakes and Solutions
CRITICAL: Control Sequence Syntax Errors
❌ Common Mistake: Incorrect Enter Key Syntax
# WRONG - This will NOT work as expected byobu send-keys -t "session_name" "command" "C-m" # WRONG syntax byobu send-keys -t "session_name" "command C-m" # WRONG syntax
✅ CORRECT: Proper Control Sequence Syntax
# CORRECT - Each operation is ALWAYS a separate byobu send-keys command byobu send-keys -t "session_name" "command" # Step 1: Type the command text byobu send-keys -t "session_name" C-m # Step 2: Press Enter to execute byobu send-keys -t "session_name" "cd /path" # Step 1: Type "cd /path" byobu send-keys -t "session_name" C-m # Step 2: Press Enter to execute # EFFICIENCY TIP: Chain operations with && for single-line execution byobu send-keys -t "session_name" C-c && byobu send-keys -t "session_name" C-m # Interrupt + confirm byobu send-keys -t "session_name" C-c # Step 1: Press Ctrl+C interrupt byobu send-keys -t "session_name" C-m # Step 2: Press Enter to confirm (if needed)
Key Rules:
- Control sequences (C-m, C-c, C-d) must be separate arguments, not inside quotes
- Commands go in quotes, control sequences go outside quotes as separate args
= Enter/Return,C-m
= Ctrl+C,C-c
= EOF,C-d
= Clear screenC-l- CRITICAL: Text input and Enter key are ALWAYS separate byobu send-keys operations
- CRITICAL: Enter key (C-m) must ALWAYS be sent as a separate operation after typing text
- CRITICAL: Ctrl+C (C-c) and Enter (C-m) are different operations and must be sent separately when needed
Command Execution Issues
Problem: Commands appear to execute but fail silently
- Cause: Missing proper Enter key sequence (C-m)
- Solution: Always add
as separate argument after commandC-m
Problem: Commands hang or timeout
- Cause: Missing sleep intervals for Claude Code processing
- Solution: Add
between commands, especially after Claude Code startupsleep 2-5
Problem: Session becomes unresponsive
- Cause: Commands failing without proper error handling
- Solution: Use Ctrl+C (
) to interrupt, recreate session if neededC-c
Plugin Installation Issues
Problem: Marketplace addition fails with "not found"
- Cause: Incorrect path syntax or marketplace already exists
- Solution: Use absolute paths and check existing marketplaces first
Problem: Plugin installation fails after marketplace addition
- Cause: Timing issues or plugin name mismatch
- Solution: Wait for marketplace addition to complete, use correct plugin identifier
Discovery: Slash Commands vs Plugin Installation
- Some functionality may be installed as slash commands in
rather than formal plugins~/.claude/commands/ - Check slash commands first:
ls -la ~/.claude/commands/ - Slash commands work immediately without plugin installation
- Example:
,/afs
,/afst
,/afa
may be available as slash commands even when no plugins are installed/afj
Best Practices
- Session Naming: Always use "autorun" as the default session name unless user specifies another tmux session name
- Default Session: Use "autorun" as the default session name for all autorun testing workflows
- Existence Checks: Always verify session existence before operations using
byobu list-sessions - Error Recovery: Implement Ctrl+C handling for stuck commands and session recreation when needed
- Output Verification: Use capture-pane for command result verification and testing validation
- Resource Management: Clean up sessions after testing with
byobu kill-session - Timing: Add appropriate sleep intervals between commands (2-5 seconds for Claude Code startup)
- AI-Monitor Integration: Use ai-monitor for long-running autonomous sessions and automated workflows
- Model Selection: Use haiku for automated tasks to reduce resource usage and improve performance
- Byobu vs Tmux: Prefer byobu commands for user-friendly interface, tmux commands for scripting
- Control Sequences: Always use proper control sequence syntax - commands in quotes, C-m/C-c as separate arguments
- Error Prevention: Test control sequences manually before automation scripts
- Efficiency Operations: Use
to chain byobu commands for single-line execution:&&byobu send-keys C-c && byobu send-keys C-m - Debugging Strategy: Test functionality step-by-step instead of assuming installation state
- Slash Command Priority: Check
first before plugin installation attempts~/.claude/commands/
Implementation Notes
- This skill uses tmux as the primary backend (byobu is a tmux wrapper providing user-friendly interface)
- Byobu provides enhanced F-key shortcuts and session management over tmux
- All tmux commands work with both byobu and tmux sessions (byobu with tmux backend)
- AI-monitor provides the automation layer for autonomous workflows and session monitoring
- Control sequences (C-m for Enter, C-c for interrupt) are critical for proper command execution
- Proper timing and error handling ensure reliable automated testing workflows
- Byobu sessions can be managed with both byobu commands and direct tmux commands
External Resources and References
Documentation Links
-
Byobu Official Documentation - https://www.byobu.org/
- Use when learning byobu-specific features and configuration
- Essential for understanding F-key shortcuts and byobu workflow
- Visit when setting up new byobu environments
-
Tmux Manual - https://github.com/tmux/tmux/wiki
- Reference for advanced tmux commands and scripting
- Use when creating complex session automation scripts
- Essential for understanding tmux prefix commands and scripting
-
Claude Code Skills Documentation - https://docs.claude.com/en/docs/claude-code/skills
- Learn how to create and structure Claude Code skills
- Use when creating additional skills or extending this one
- Essential for understanding skill YAML frontmatter and formatting
-
Claude Code Plugin Documentation - https://docs.claude.com/en/docs/claude-code/plugins
- Reference for Claude Code plugin development
- Use when developing or debugging Claude Code plugins
- Essential for understanding plugin architecture and hook systems
-
Claude Code Plugin Examples - https://raw.githubusercontent.com/anthropics/claude-code/refs/heads/main/plugins/README.md
- Official examples and patterns for Claude Code plugins
- Use when implementing plugin features or debugging issues
- Essential for understanding best practices from official plugins
Testing and Automation Resources
-
AI-Monitor Integration (autorun) -
src/autorun/ai_monitor.py- Built-in tmux monitoring and automation capabilities
- Use for autonomous session monitoring and automated re-prompting
- Essential for long-running automated workflows and testing
-
Bash Scripting Guide - https://www.gnu.org/software/bash/manual/
- Reference for creating automated test scripts
- Use when writing complex test automation scripts
- Essential for proper error handling and process control
When to Use Each Resource
Setup Phase:
- Visit Byobu Documentation when first setting up your testing environment
- Check Claude Code Skills Documentation when creating new skills
- Review tmux Manual when learning advanced session management
Development Phase:
- Use AI-Monitor integration for implementing autonomous workflows
- Reference Claude Code Plugin Examples when developing plugins
- Consult Bash Scripting Guide for complex automation scripts
Debugging Phase:
- Check Claude Code Plugin Documentation when troubleshooting plugin issues
- Review tmux Manual when debugging session management problems
- Use AI-Monitor logs when monitoring automated workflows
Best Practices:
- Always reference official Claude Code Plugin Examples for patterns
- Keep Byobu Documentation handy for session management shortcuts
- Use tmux Manual for scripting complex automation scenarios