Claude Code + tmux: 入力待ちウィンドウを点滅させる
Claude Code が入力待ち状態になったとき、tmux ステータスバーのウィンドウタイトルを点滅させて通知する。 ツールの許可待ちでも点滅するので、別のウィンドウで作業中でも Claude Code が待っていることに気づける。
Claude Code の hooks 機能を使い、状態に応じて tmux set-window-option でスタイルを切り替える。
| フック | タイミング | 動作 |
|---|---|---|
Stop |
Claude が処理を終えて入力待ちになった | 点滅を開始 |
PreToolUse |
Claude がツールを使おうとしている(許可待ち含む) | 点滅を開始 |
PostToolUse |
ツールの実行が完了した | 点滅を停止(元に戻す) |
UserPromptSubmit |
ユーザがプロンプトを送信した | 点滅を停止(元に戻す) |
SessionEnd |
Claude Code を終了した | 点滅を停止(元に戻す) |
ツール実行に許可が必要な場合、PreToolUse → 許可待ち → ユーザが許可 → ツール実行 → PostToolUse という流れになる。
PreToolUse で点滅を開始することで、許可待ちの間もユーザに通知できる。
自動許可されるツールの場合は PreToolUse → PostToolUse が即座に実行されるため、点滅はほぼ見えない。
tmux set-window-option を -t なしで実行すると、tmux はクライアントのアクティブウィンドウを対象にする。
hook コマンドは Claude Code の子プロセスとして実行されるが、ユーザが別ウィンドウを見ている場合、
そのアクティブウィンドウに適用されてしまい、意図しないウィンドウが点滅する。
-t $TMUX_PANE を指定することで、Claude Code が動いているペイン(=ウィンドウ)に確実に適用される。
~/.claude/settings.json に追加する。COLOR と ORIGINAL_FORMAT は環境に合わせて置き換える。
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "tmux set-window-option -t $TMUX_PANE window-status-format '#[fg=COLOR,blink] #I #W ' 2>/dev/null; true"
}
]
}
],
"PreToolUse": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "tmux set-window-option -t $TMUX_PANE window-status-format '#[fg=COLOR,blink] #I #W ' 2>/dev/null; true"
}
]
}
],
"PostToolUse": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "tmux set-window-option -t $TMUX_PANE window-status-format 'ORIGINAL_FORMAT' 2>/dev/null; true"
}
]
}
],
"UserPromptSubmit": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "tmux set-window-option -t $TMUX_PANE window-status-format 'ORIGINAL_FORMAT' 2>/dev/null; true"
}
]
}
],
"SessionEnd": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "tmux set-window-option -t $TMUX_PANE window-status-format 'ORIGINAL_FORMAT' 2>/dev/null; true"
}
]
}
]
}
}各コマンドに window-status-current-format の設定を ; で追加する。
アクティブウィンドウは fg/bg を反転させると視認性が良い。
"command": "tmux set-window-option -t $TMUX_PANE window-status-format '#[fg=COLOR,blink,bold] #I #W ' 2>/dev/null; tmux set-window-option -t $TMUX_PANE window-status-current-format '#[bg=COLOR,fg=FGCOLOR,blink,bold] #I #W ' 2>/dev/null; true"# 現在の window-status-format を確認
tmux show-options -gw window-status-format
# 現在の window-status-current-format を確認
tmux show-options -gw window-status-current-format
# ターミナルが blink に対応しているか確認
printf '\e[5mtest\e[0m\n'
# 点滅のデモ(5秒間点滅して元に戻る)
tmux set-window-option -t $TMUX_PANE window-status-format '#[fg=magenta,blink,bold] #I #W '; sleep 5; tmux set-window-option -t $TMUX_PANE window-status-format '#[fg=colour82] #I #W '#[fg=yellow,blink] # 黄色で点滅
#[fg=red,blink,bold] # 赤太字で点滅
#[fg=cyan,blink] # シアンで点滅
#[fg=magenta,blink] # マゼンタで点滅
#[bg=yellow,fg=black,blink] # 黄色背景で点滅(反転)
#[bg=cyan,fg=yellow,blink,bold] # シアン背景・黄色文字で点滅(反転)
tmux のキーバインドで直接点滅を止めることができる。 LLM を経由しないので即座に反映される。
現在の prefix キーバインドを一覧表示して、使われていないキーを探す。
tmux list-keys -T prefixおすすめは b(blink の頭文字で覚えやすい)。
デフォルトの tmux では b は list-buffers に割り当てられているが、
# が同じ機能を持つため、b を上書きしても問題ないことが多い。
もし b が使用中なら B(大文字)も候補になる。
空きかどうかは以下で確認できる:
# 何も表示されなければ空いている
tmux list-keys -T prefix | grep -w bORIGINAL_FORMAT は自分の環境に合わせて置き換える(確認方法は「確認方法」セクションを参照)。
# prefix + b で点滅を停止
bind b set-window-option window-status-format 'ORIGINAL_FORMAT' \; \
set-window-option window-status-current-format 'ORIGINAL_CURRENT_FORMAT'例(colour82 / colour84 の場合):
bind b set-window-option window-status-format '#[fg=colour82] #I #W ' \; \
set-window-option window-status-current-format '#[bg=colour84,fg=colour18]#{?client_prefix,#[bg=colour199],} #I #W 'アクティブウィンドウを点滅対象にしていない場合は window-status-current-format の行は不要。
tmux source-file ~/.tmux.confまたは prefix + r(source-file を割り当てている場合)。
点滅のデモを実行してから prefix + b で止まることを確認する。
# 点滅を開始(テスト用)
tmux set-window-option window-status-format '#[fg=magenta,blink,bold] #I #W '
# → ここで prefix + b を押して点滅が止まることを確認- tmux 内で Claude Code を使っていること
- ターミナルが
blink属性に対応していること