mcpField
T
tmux

tmux

github.com/johnlindquist開発2762 回インストール46 週間前に更新
リポジトリ

tmux について

tmux でバックグラウンドプロセスを実行・管理するスキルです。セッション、ウィンドウ、ペインの操作や出力取得に加え、エージェント用の専用ソケットも扱います。

主な機能

  1. 01セッションの作成と管理
  2. 02ウィンドウとペインの操作
  3. 03コマンド送信と出力取得
  4. 04エージェント用専用ソケット

活用シーン

  1. 01開発サーバーのバックグラウンド実行
  2. 02テスト出力のファイル保存
  3. 03複数サービスのウィンドウ別管理
  4. 04長時間のビルドの監視

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/johnlindquist/claude --skill tmux

インストール後、Claude Code で/tmuxを入力して読み込まれたか確認します。

詳細

Tmux セッションマネージャー

tmux を使用してバックグラウンドプロセスを実行・管理します。

前提条件

tmux をインストールします:

brew install tmux
# or
apt install tmux

CLI リファレンス

セッションの作成
# Basic session
tmux new-session -d -s mysession

# With window name
tmux new-session -d -s mysession -n mywindow

# With working directory
tmux new-session -d -s mysession -c /path/to/dir

# With initial command
tmux new-session -d -s mysession "npm run dev"

# Combined
tmux new-session -d -s dev -n server -c /project "npm run dev"
セッションの一覧表示
# List all sessions
tmux list-sessions

# Short format
tmux ls

# With format
tmux list-sessions -F "#{session_name}: #{session_windows} windows"
セッションへのキー送信
# Send command
tmux send-keys -t mysession "npm test" Enter

# Send to specific window
tmux send-keys -t mysession:mywindow "command" Enter

# Send without Enter
tmux send-keys -t mysession "partial command"

# Send special keys
tmux send-keys -t mysession C-c        # Ctrl+C
tmux send-keys -t mysession C-d        # Ctrl+D
tmux send-keys -t mysession Escape     # Escape
tmux send-keys -t mysession Up         # Arrow up
出力のキャプチャ
# Capture visible pane
tmux capture-pane -t mysession -p

# Capture with history (last N lines)
tmux capture-pane -t mysession -p -S -100

# Capture all history
tmux capture-pane -t mysession -p -S -

# Save to file
tmux capture-pane -t mysession -p > output.txt
セッションの終了
# Kill specific session
tmux kill-session -t mysession

# Kill all sessions
tmux kill-server
セッションへのアタッチ
# Attach
tmux attach -t mysession

# Attach or create
tmux new-session -A -s mysession
ウィンドウ管理
# New window
tmux new-window -t mysession -n windowname

# Select window
tmux select-window -t mysession:windowname

# Kill window
tmux kill-window -t mysession:windowname

# List windows
tmux list-windows -t mysession
ペイン管理
# Split horizontally
tmux split-window -t mysession -h

# Split vertically
tmux split-window -t mysession -v

# Select pane
tmux select-pane -t mysession:0.1

# Kill pane
tmux kill-pane -t mysession:0.1

ワークフローパターン

開発サーバーをバックグラウンドで実行
# Start server
tmux new-session -d -s devserver -c /project "npm run dev"

# Check output
tmux capture-pane -t devserver -p -S -50

# Stop server
tmux send-keys -t devserver C-c
tmux kill-session -t devserver
出力をキャプチャしながらテストを実行
# Start tests
tmux new-session -d -s tests "npm test"

# Wait and capture output
sleep 30
tmux capture-pane -t tests -p -S - > test-output.txt

# Cleanup
tmux kill-session -t tests
複数のサービス
# Create session with multiple windows
tmux new-session -d -s services -n frontend
tmux new-window -t services -n backend
tmux new-window -t services -n database

# Start each service
tmux send-keys -t services:frontend "npm run dev" Enter
tmux send-keys -t services:backend "go run main.go" Enter
tmux send-keys -t services:database "docker-compose up db" Enter

# Check all services
for win in frontend backend database; do
  echo "=== $win ==="
  tmux capture-pane -t services:$win -p -S -10
done
長時間実行プロセス
# Start process
tmux new-session -d -s build "npm run build:production"

# Monitor progress
watch -n 5 "tmux capture-pane -t build -p -S -20"

# Or periodic check
while tmux has-session -t build 2>/dev/null; do
  sleep 10
  echo "Still running..."
done
echo "Build complete"

ソケットモード(エージェント向け)

エージェントのコンテキストで実行する場合は、専用のソケットを使用します:

SOCKET_PATH="/tmp/agent-tmux-$$"

# Create session with socket
tmux -S $SOCKET_PATH new-session -d -s agent "command"

# Send keys via socket
tmux -S $SOCKET_PATH send-keys -t agent "input" Enter

# Capture via socket
tmux -S $SOCKET_PATH capture-pane -t agent -p

# Cleanup
tmux -S $SOCKET_PATH kill-server
rm -f $SOCKET_PATH

ベストプラクティス

  1. セッションにはわかりやすい名前を付ける - 後から特定しやすくなります
  2. デタッチには -d を使用する - ターミナルをブロックしません
  3. 出力を定期的にキャプチャする - セッションを終了する前に
  4. 作業ディレクトリを設定する - コンテキストには -c /path を使用します
  5. セッションをクリーンアップする - 完了したら終了します
  6. 分離にはソケットを使用する - エージェント間の競合を防ぎます

コメント