🔔
WezTermでClaude Codeの通知を快適に受け取る設定
WezTermで受け取れるClaude Codeの通知がターミナルベルのみで見逃しやすいので、OS通知に変換する方法を紹介します。
解決方法
~/.config/wezterm/wezterm.lua
に以下を追加:
local wezterm = require 'wezterm'
wezterm.on('bell', function(window, pane)
window:toast_notification('Claude Code', 'Task completed', nil, 4000)
end)
return {
audible_bell = 'SystemBeep', -- 音も鳴らす場合
}
これでClaude Codeからの通知がOS通知として表示されます。以上
Appendix
背景
Claude Codeは長時間タスクの完了時にターミナルベルで通知します。iTerm2では自動的にOS通知になりますが、WezTermではベル音のみです。上記の設定でbellイベントをOS通知に変換できます。
Claude Codeの場合のみ通知する
Claude CodeからのベルのみでOS通知を行う設定:
local function is_claude(pane)
local process = pane:get_foreground_process_info()
if not process or not process.argv then
return false
end
-- 引数に"claude"が含まれているかチェック
for _, arg in ipairs(process.argv) do
if arg:find("claude") then
return true
end
end
return false
end
wezterm.on("bell", function(window, pane)
if is_claude(pane) then
window:toast_notification("Claude Code", "Task completed", nil, 4000)
end
end)
macOS向けオプション
bellイベントハンドラ内に以下を追加できます。
システムサウンドを追加:
wezterm.on('bell', function(window, pane)
window:toast_notification('Claude Code', 'Task completed', nil, 4000)
if wezterm.target_triple:find("darwin") then
wezterm.background_child_process({ "afplay", "/System/Library/Sounds/Submarine.aiff" })
end
end)
音声で通知:
wezterm.on('bell', function(window, pane)
window:toast_notification('Claude Code', 'Task completed', nil, 4000)
if wezterm.target_triple:find("darwin") then
wezterm.background_child_process({ "say", "Claude is calling you" })
end
end)
追記(2025-06-11)
タブの番号を取得して表示すると便利だったので追記します。
以下の関数でタブの番号を取得できるので、通知のメッセージに追加してください。
local function get_tab_id(window, pane)
local mux_window = window:mux_window()
for i, tab_info in ipairs(mux_window:tabs_with_info()) do
for _, p in ipairs(tab_info.tab:panes()) do
if p:pane_id() == pane:pane_id() then
return i
end
end
end
end
Discussion