Skip to content

Instantly share code, notes, and snippets.

@so298
Last active July 4, 2025 07:52
Show Gist options
  • Save so298/f19e65be27d5f493f91868e822e189be to your computer and use it in GitHub Desktop.
Save so298/f19e65be27d5f493f91868e822e189be to your computer and use it in GitHub Desktop.
Claude Codeのhooks

Claude Code hooksでslack通知を入れる

  1. claude コマンドを起動し、 /hooks を入力し、hooksの設定画面を開く
  2. 以下のような設定を Notification, Stop の両方に設定する
    cat | jq -r --arg host "$(hostname)" '
    {
      channel    : "claude-code",
      username   : "Claude Code",
      icon_emoji : ":claude:",
      text       : (
          "Notification from Claude:\n" +
          "> *session_id*: " + .session_id + "\n" +
          "> *hostname*: "   + $host        + "\n" +
          "> *title*: "      + .title       + "\n" +
          "> *message*: "    + .message
      )
    }' \
    | curl -X POST -H 'Content-Type: application/json' --data @- "$(cat ~/.claude/slack_webhook.txt)"
    
    # Stop ... invoked when claude code stops its action
    curl \
      -X POST \
      -H 'Content-Type: application/json' \
      --data "{\"text\":\"Stopped on $(hostname)\", \"channel\": \"claude-code\", \"username\": \"Cluade Code\", \"icon_emoji\": \":claude:\"}" \
      "$(cat ~/.claude/slack_webhook.txt)"
  3. Slackに incoming webhook のappを追加し、設定画面からwebhookのURLを取得する
  4. webhook URLのみを記載したファイルを ~/.claude/slack_webhook.txt に作成する
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment