Loading...
Loading...
cmux ターミナル内での操作スキル。ペイン分割、サブエージェント起動・監視・結果回収、コマンド送信、画面読み取り、通知に使用。CMUX_* 環境変数が存在する場合にトリガーされる。
npx skill4agent add hummer98/using-cmux using-cmuxCMUX_SOCKET_PATHcmux identify # 自分のワークスペース・サーフェスを確認
cmux list-workspaces # 全ワークスペース一覧
cmux tree # トポロジー表示(階層構造)window:1workspace:2pane:3surface:4--id-format uuids注意:で複数行を送る場合はsendが必須。詳細は「send の改行ルール」を参照。send-key return
| 操作 | コマンド |
|---|---|
| ペイン分割 | |
| 新ワークスペース | |
| コマンド送信 | |
| キー送信 | |
| 画面読み取り | |
| サーフェス/WS 終了 | |
| 一覧表示 | |
\ncmux send --surface surface:1 "echo hello\n"\nsend-key return\nsend-key return# ✅ 正しい方法
cmux send --surface surface:1 "line 1"
cmux send-key --surface surface:1 return
cmux send --surface surface:1 "line 2"
cmux send-key --surface surface:1 return
# ❌ 間違い — \n は途中改行にならない
cmux send --surface surface:1 "line 1\nline 2\n"\n\nsend-keysend# ✅ 正しい方法
cmux send-key --surface surface:N ctrl+c
# ❌ 間違い — リテラルテキストが送られるだけ
cmux send --surface surface:N "C-c"
cmux send --surface surface:N "\x03"
cmux send-key --surface surface:N "C-c" # → Unknown key エラーctrl+cctrl+dctrl+zreturntabescapesend-key --help--surface--workspace# ✅ 正しい方法 — --workspace で指定(focused surface に自動解決)
cmux send --workspace workspace:N "command\n"
cmux read-screen --workspace workspace:N
cmux send-key --workspace workspace:N return
# ❌ 間違い — --surface で他ワークスペースのサーフェスを指定
cmux send --surface surface:S "command\n" # → "Surface is not a terminal" エラー
cmux read-screen --surface surface:S # → 同上--surface--workspacecmux list-pane-surfaces # 全サーフェス一覧
screen=$(cmux read-screen --surface surface:N) # 各サーフェスの状態を確認
# シェルプロンプト($ や ❯)のみ → 遊休 → 再利用可能new-splitnew-workspaceWS=$(cmux new-workspace --cwd $(pwd) | awk '{print $2}')
cmux rename-workspace --workspace $WS "Researcher-1" # 用途がわかる名前を付ける注意: PTY 遅延初期化問題(後述)により、ワークスペースを GUI 上で一度表示する必要がある場合がある。
cmux send --workspace $WS "claude --dangerously-skip-permissions\n"は信頼できるタスクにのみ使うこと。--dangerously-skip-permissions
read-screenscreen=$(cmux read-screen --workspace $WS)
# "trust" 検出 → 承認
cmux send-key --workspace $WS return❯read-screen --workspace $WS# 単一行
cmux send --workspace $WS "指示テキスト\n"
cmux set-status $WS "調査中" --icon hammer # ステータスを設定
# 複数行(send-key return で改行)
cmux send --workspace $WS "1行目の指示"
cmux send-key --workspace $WS return
cmux send --workspace $WS "2行目の指示"
cmux send-key --workspace $WS return❯read-screen --workspace $WScmux clear-status $WS # ステータスをクリア
result=$(cmux read-screen --workspace $WS --scrollback) # 全出力取得
cmux close-workspace --workspace $WS # 不要なら閉じるcmux new-workspaceselect-workspacecmux send --surface surface:Ncmux read-screen --surface surface:NSurface is not a terminalsurface.send_textqueued: truesurface.read_textTerminal surface not found# ワークスペース作成後に GUI 表示を強制する
WS=$(cmux new-workspace --cwd $(pwd) | awk '{print $2}')
# ワークスペースのインデックスを取得
WS_INDEX=$(cmux tree --json | python3 -c "
import json, sys
data = json.load(sys.stdin)
for w in data['windows']:
for ws in w['workspaces']:
if ws['ref'] == '$WS':
print(ws['index'] + 1)")
# AppleScript でメニュークリック → PTY 初期化
osascript -e "
tell application \"System Events\"
tell process \"cmux\"
click menu item \"ワークスペース $WS_INDEX\" of menu 1 of menu bar item \"表示\" of menu bar 1
end tell
end tell"
sleep 2
# 元のワークスペースに戻る
ORIG_INDEX=1 # 元のワークスペースの index+1
osascript -e "
tell application \"System Events\"
tell process \"cmux\"
click menu item \"ワークスペース $ORIG_INDEX\" of menu 1 of menu bar item \"表示\" of menu bar 1
end tell
end tell"surface.send_textsurface.read_textsurface_ref| 問題 | 対処 |
|---|---|
| 出力が空 / 古い | |
| 長い出力が切れる | |
| 特定行数だけ欲しい | |
| surface が見つからない | |
| PTY 遅延初期化問題。上記ワークアラウンド参照 |
read-screencmux refresh-surfacesread-screencmux new-split right # → surface:N
cmux send --surface surface:N "npm run dev\n"
# ポーリングで "ready" 等のキーワードを検出
screen=$(cmux read-screen --surface surface:N)# アプリ内通知(ペインハイライト、サイドバーバッジ。Cmd+Shift+U で移動)
cmux notify --title "完了" --body "ビルドが成功しました"
# macOS 通知センター(サウンド付き、別アプリ使用中でも表示)
osascript -e 'display notification "ビルド完了" with title "Claude" sound name "Glass"'cmux notifyosascriptcmux set-status mykey "作業中" --icon hammer --color "#0099ff" # サイドバーに表示
cmux clear-status mykey
cmux set-progress 0.5 --label "ビルド中..." # プログレスバー(0.0〜1.0)
cmux clear-progresscmux browser --helpcmux new-pane --type browser --url <url>| 変数 | 説明 |
|---|---|
| cmux ソケットのパス。存在すれば cmux 内で動作中 |
| 現在のワークスペース ID |
| 現在のサーフェス ID |
| ミス | 正しい方法 |
|---|---|
| 各行を個別に |
| UUID でサーフェスを指定する | 短縮 refs を使う: |
| サブエージェントを同一ワークスペースに配置 | 別ワークスペース ( |
| |
| Trust プロンプトを見逃してハングする | 起動後に |
| |
| |
| 遊休ペインがあるのに新しく split する | |
| ワークスペースに名前を付けない | |
| コマンド | 説明 |
|---|---|
| 環境情報 / トポロジー表示 |
| 一覧表示 |
| ワークスペース・ペイン作成 |
| 入出力操作 |
| 画面バッファ強制更新 |
| リソース終了 |
| 選択・名前変更 |
| 通知・ステータス・進捗 |
| シグナル待機 |