💡

Claude CodeのHooks機能を使って欲しいタイミングでずんだもんに呼んでもらう

に公開

今まではMCPサーバーを利用していたのですが、ツール実行がAIに依存していてため動作が安定していませんでした。

7/1 に追加されたHooks機能を使えば任意のタイミングで確実にコマンドを実行することができ、これの代わりにならないかと早速試してみました。

やり方

早速結論ですが、下記の設定で動きます。Vibe Codingなので何が実行されているのかは何も理解していません。
下記のいずれかのファイルに追記してください。

~/.claude/settings.json - User settings
.claude/settings.json - Project settings
.claude/settings.local.json - Local project settings (not committed)

動作タイミングはClaude Codeがユーザに実行確認を求めるタイミングタスクが完了したタイミングです。
文言は適当なので自由に変更するとよいでしょう。


  "hooks": {
    "Notification": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "bash -c 'read -r j; txt=\"クロードコードが呼んでいます。\"; f=$(mktemp /tmp/vv_XXXXXX.wav); curl -s -X POST \"http://127.0.0.1:50021/audio_query?speaker=1\" --get --data-urlencode text=\"${txt}\" | curl -s -X POST -H \"Content-Type: application/json\" -d @- \"http://127.0.0.1:50021/synthesis?speaker=1\" -o \"$f\"; afplay \"$f\"; rm \"$f\"'"
          }
        ]
      }
    ],
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "bash -c 'read -r j; txt=\"すべてのタスクが終了しました。\"; f=$(mktemp /tmp/vv_XXXXXX.wav); curl -s -X POST \"http://127.0.0.1:50021/audio_query?speaker=1\" --get --data-urlencode text=\"${txt}\" | curl -s -X POST -H \"Content-Type: application/json\" -d @- \"http://127.0.0.1:50021/synthesis?speaker=1\" -o \"$f\"; afplay \"$f\"; rm \"$f\"'"
          }
        ]
      }
    ]
  }
}

Discussion