4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

私の環境:WSL2 + Ubuntu + VSCode(Bash)

Claude Codeを使っていて「○○をしてよいですか? Yes, No」のような選択肢が出現したときや、Claude Codeの動作が完了したときに音が鳴るようにするための設定手順です。音が鳴るようにすると、Claude Codeが裏で動いている間に調べものなど別の作業をしていてもすぐにClaude Codeからのアクションに気づけるので便利です。

1. Claude CodeでHookを設定する

Claude Codeで/hooks コマンドを実行すると、Select hook eventという項目が出てきます。

image.png
NotificationStop の両方に設定を追加します。Notificationは選択肢出現時、StopはClaude Codeの動作完了時の設定です。どちらの設定でも手順は同じです。

2. Matcherの設定

ここは空欄にしたいのですが、この場では空欄にできないため今は任意の文字列を入力し、あとで修正します。修正方法は後ほど「設定確認とMatcherの修正」にて説明します。なお、Matcher設定画面が表示されない場合もありますがそれはそれで問題ありません。

image.png

3. Commandの設定

以下の音を鳴らすコマンドを設定します。beep()のパラメータは、1番目のパラメータが音の周波数(ヘルツ単位)、2番目のパラメータがサウンドの継続時間(ミリ秒単位)になります。お好きなように変更してください。

powershell.exe -c "[console]::beep(500,750)"

image.png

また、1コマンドにつき1回音が鳴るので、&&でコマンドを複数個連結するとその数だけ繰り返し音を鳴らすことができます。

powershell.exe -c "[console]::beep(500,750)" && powershell.exe -c "[console]::beep(500,750)" && powershell.exe -c "[console]::beep(500,750)"

4. Hookの設定の保存

image.png

最後に設定の保存場所を設定します。私はUser settingsを選択していますので、以降はそのテイで説明しています。

5. 設定確認とMatcherの修正

User settingsに保存している場合は~/.claude/settings.jsonを開き、ここまでの設定が正しく反映されているか確認します。正しく設定されている場合、以下のように記述されています(ほかに設定項目がある場合はほかの項目の情報も記述されています)。

~/.claude/settings.json
{
  "hooks": {
    "Notification": [
      {
        "matcher": "hoge",  # matcherの値は「2. Matcherの設定」で設定した文字列になっています。
        "hooks": [
          {
            "type": "command",
            "command": "powershell.exe -c \"[console]::beep(500,750)\""
          }
        ]
      }
    ],
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "powershell.exe -c \"[console]::beep(500,750)\""
          }
        ]
      }
    ]
  },
}

~/.claude/settings.json を直接編集してmatcher の値を空文字列にし、保存します。

~/.claude/settings.json
    # 既存コード省略
    "Notification": [
      {
-        "matcher": "hoge",
+        "matcher": "",
    # 既存コード省略

6. VSCodeの再起動

一度VSCodeを再起動してください。

7. 音が鳴るかを確認

Claude Codeを動かし、選択肢出現時と動作完了時に音が鳴るか確認してください。音が鳴れば設定は完了です。お読みいただきありがとうございました。

追記

この記事ではbeep()を使ったビープ音が鳴るようにしていますが、下のサイトではより効果音然とした音を鳴らすコマンドを紹介しておられます(「ちなみにWindows(WSL)の場合は」という見出しを参照)。

参考記事

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?