| name | tmux |
| description | Use tmux for background tasks, TUI testing, and debugging layouts. Philosophy: No background bash - use tmux for full observability and direct interaction. |
tmux - No Background Bash Philosophy
Core Philosophy
No background bash. Use tmux. Full observability, direct interaction.
Instead of implementing complex background task management in your application:
| โ ๅบ็จๅ
ๅฎ็ฐ | โ
็จ tmux |
|---|
& ๅๅฐ่ฟ่ก๏ผไธขๅคฑ่พๅบ | tmux session ไฟๆ่ฟ่ก๏ผ้ๆถๆฅ็ |
| ้่ฆๅฎ็ฐ job control | tmux ๅทฒๆๅฎๆด็ session ็ฎก็ |
| ่พๅบไธๅฏ่ง | tmux attach ้ๆถ้่ฟ |
| ่ฟ็จ้พไปฅ็ฎก็ | tmux ls / tmux kill-session |
tmux gives you:
- Full observability - always see what's happening
- Direct interaction - attach and type commands
- Persistence - detach and reattach later
- Isolation - each task in its own session
โ Safety Rules โ READ FIRST
Agent ่ฏฏๆไฝ tmux kill-server ๆพๅฏผ่ด็จๆทไธขๅคฑๅ
จ้จ tmux sessionใ
ไปฅไธ่งๅๆฏ็กฌ็บฆๆ๏ผ่ฟๅๅณๅฏ่ฝ้ ๆไธๅฏๆขๅค็ๆฐๆฎไธขๅคฑใ
็ปๅฏน็ฆๆญข
| ็ฆไปค | ๅๅ |
|---|
็ฆๆญข tmux kill-server | ้ๆฏๆดไธช tmux ๆๅกๅจ๏ผๆๆ็จๆท session ๅ
จ้จๆถๅคฑ |
| ็ฆๆญข้ๅๆๆ session ๅนถๆน้ kill | ้้
็ฌฆๅฏ่ฝๅฝไธญ็จๆท็ session๏ผๆๅไธไธช session ่ขซๆๅ server ไนไผ้ๅบ |
| ็ฆๆญข kill ไธๆฏไฝ ๅๅปบ็ session | ไฝ ไธ็ฅ้ๅ
ถไป session ็็จ้ |
็ฆๆญขๅๅฏไธ pane ๅ้ exit / C-d | pane ๅ
ณ้ญ โ window ๅ
ณ้ญ โ session ๅ
ณ้ญ๏ผ่ฟ้้ๅบ |
ๆญฃ็กฎๅๆณ
tmux kill-session -t "my-agent-task" 2>/dev/null
tmux -L agent-$$ new-session -d -s "my-task" "..."
tmux -L agent-$$ kill-session -t "my-task"
tmux list-sessions
ๅฆๆ้่ฆ"ๅนฒๅ็ฏๅข"
tmux kill-server
for s in $(tmux list-sessions -F '#{session_name}' 2>/dev/null | grep '^my-prefix-'); do
tmux kill-session -t "$s" 2>/dev/null
done
TMUX_SOCK="tmux -L agent-$$"
$TMUX_SOCK new-session -d -s "task" "..."
$TMUX_SOCK kill-session -t "task"
Quick Reference
Session Management
tmux new -s <name>
tmux new -s build -d
tmux attach -t <name>
tmux detach (Ctrl-b d)
tmux ls
tmux kill-session -t <name>
Window & Pane Operations
Ctrl-b %
Ctrl-b " # Split horizontal (top/bottom)
Ctrl-b <arrow> # Navigate panes
Ctrl-b x # Kill pane
Ctrl-b z # Toggle pane zoom (fullscreen)
Ctrl-b Ctrl-<arrow> # Resize pane
Ctrl-b { / } # Swap panes
# Windows
Ctrl-b c # New window
Ctrl-b n / p # Next / Previous window
Ctrl-b <number> # Go to window number
Ctrl-b , # Rename window
Ctrl-b & # Kill window
Sending Commands (for scripting)
tmux send-keys -t <session> "command" Enter
tmux send-keys -t <session> Escape
tmux send-keys -t <session> C-c
tmux send-keys -t <session> C-o
tmux send-keys -t <session> M-x
tmux send-keys -t <session> Space
tmux send-keys -t <session> Up
tmux capture-pane -t <session> -p
tmux capture-pane -t <session> -p > out.txt
Common Workflows
Long-Running Build / Test
tmux new -s build
go build ./...
tmux attach -t build
Debugging Layout (Go + Delve)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Pane 0: Program โ
โ $ go run ./cmd/ai โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Pane 1: Delve Debugger โ
โ (dlv) break main.main โ
โ (dlv) continue โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
tmux new -s debug -d
tmux split-window -v -t debug
tmux send-keys -t debug:0.0 "go run ./cmd/ai" Enter
tmux send-keys -t debug:0.1 "dlv attach \$(pgrep ai)" Enter
tmux attach -t debug
TDD Layout (Code + Test Watch)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Pane 0: Program โ Pane 1: Test Watch โ
โ $ go run ./cmd/ai โ $ go test -v ./... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Pane 2: Logs / Shell โ
โ $ tail -f /var/log/ai.log โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
tmux new -s tdd -d
tmux split-window -h -t tdd
tmux split-window -v -t tdd:0.0
tmux send-keys -t tdd:0.0 "go run ./cmd/ai" Enter
tmux send-keys -t tdd:0.1 "go test -v ./..." Enter
tmux send-keys -t tdd:0.2 "tail -f /var/log/ai.log" Enter
tmux attach -t tdd
Multiple Worktrees in Parallel
tmux new -s worktrees -d -c $(git rev-parse --show-toplevel)
tmux rename-window -t worktrees:0 "main"
for wt in $(git worktree list --porcelain | grep "^worktree" | cut -d' ' -f2); do
name=$(basename "$wt")
tmux new-window -t worktrees -n "$name" -c "$wt"
done
tmux attach -t worktrees
TUI Testing Pattern
Automated testing of terminal applications with controlled environment:
#!/bin/bash
SESSION="tui-test"
TMUX="tmux -L test"
cleanup() {
$TMUX kill-session -t $SESSION 2>/dev/null
}
trap cleanup EXIT
$TMUX new-session -d -s $SESSION -x 120 -y 40
$TMUX send-keys -t $SESSION "go run ./cmd/ai" Enter
sleep 2
$TMUX capture-pane -t $SESSION -p > /tmp/initial-state.txt
$TMUX send-keys -t $SESSION "help" Enter
sleep 1
$TMUX capture-pane -t $SESSION -p > /tmp/after-help.txt
if grep -q "Available commands" /tmp/after-help.txt; then
echo "โ
Test passed: Help command works"
else
echo "โ Test failed: Help command not working"
cat /tmp/after-help.txt
exit 1
fi
$TMUX send-keys -t $SESSION Escape
$TMUX send-keys -t $SESSION C-c
echo "โ
All tests passed"
Special Keys Reference
| Key | tmux send-keys syntax |
|---|
| Escape | Escape |
| Enter | Enter |
| Space | Space |
| Tab | Tab |
| Backspace | BSpace |
| Delete | DC |
| Insert | IC |
| Home | Home |
| End | End |
| Page Up | PPrior |
| Page Down | PPage |
| Arrow keys | Up Down Left Right |
| Ctrl+X | C-x (lowercase) |
| Alt+X | M-x (lowercase) |
| Shift+Tab | BTab |
| F1-F12 | F1 F2 ... F12 |
Configuration
Add to ~/.tmux.conf:
set -g mouse on
set -g base-index 1
setw -g pane-base-index 1
set -g history-limit 50000
set -g default-terminal "screen-256color"
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind r source-file ~/.tmux.conf \; display "Config reloaded!"
set -g status-right '#(git branch 2>/dev/null | grep -e "\*" | sed "s/* //") | %H:%M'
set -s escape-time 0
set -g allow-rename off
Integration with ad Editor
When running ai as a plugin in ad editor:
tmux new -s ad-dev -d
tmux split-window -h -t ad-dev
tmux send-keys -t ad-dev:0.0 "ad ." Enter
tmux send-keys -t ad-dev:0.1 "# shell for go test, git, etc." Enter
tmux attach -t ad-dev
Checking Background Task Status
When you've started a long-running task in tmux, use these commands to check status:
| Task | Command |
|---|
| List all sessions | tmux ls |
| Check if session exists | tmux ls | grep <name> |
| View current output | tmux capture-pane -t <name> -p |
| View last N lines | tmux capture-pane -t <name> -p -S -50 |
| Attach to session | tmux attach -t <name> |
| Send interrupt (Ctrl+C) | tmux send-keys -t <name> C-c |
| Kill session | tmux kill-session -t <name> โ ็ฆๆญข kill-server |
| Wait for completion | tmux_wait.sh <name> [timeout] |
Example workflow:
tmux new -s build -d "go build ./... 2>&1 | tee /tmp/build.log"
tmux capture-pane -t build -p -S -20
tmux attach -t build
~/.ai/skills/tmux/bin/tmux_wait.sh build 600
When to Use
| Scenario | tmux Pattern |
|---|
| Long build/test | Single session, detach |
| Debugging | Split pane: program + debugger |
| TDD workflow | Split pane: program + test watch |
| Multiple features | Window per worktree |
| TUI testing | Automated script with capture-pane |
Summary
Don't implement background task management in your app. Use tmux.
- โ
Simple - no code to write
- โ
Observable - always see output
- โ
Interactive - attach anytime
- โ
Persistent - survives disconnect
- โ
Standard - everyone knows tmux