Last active
November 8, 2025 19:40
-
-
Save shayonpal/7cd33c21f8cab3d630c471b9a26b0d4a to your computer and use it in GitHub Desktop.
Claude Code Hook to send Discord notification when the agent is waiting for user input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Discord Notification Hook for Claude Code | |
| # Sends a notification to Discord when Claude finishes responding | |
| # | |
| # Documentation on how to create Discord Webhook - https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks | |
| # | |
| # Environment Variables Used: | |
| # - CLAUDE_PROJECT_DIR: Full path to the current project directory | |
| # | |
| # Discord webhook URL | |
| WEBHOOK_URL="https://discord.com/api/webhooks/[redacted]" | |
| # Extract project name from project directory path | |
| if [ -n "$CLAUDE_PROJECT_DIR" ]; then | |
| PROJECT_NAME=$(basename "$CLAUDE_PROJECT_DIR") | |
| else | |
| PROJECT_NAME="Claude Code" | |
| fi | |
| # Detect hardware model | |
| MODEL_NAME=$(system_profiler SPHardwareDataType | grep "Model Name" | awk -F': ' '{print $2}') | |
| # Assign emoji: laptop if MacBook, desktop for everything else | |
| if echo "$MODEL_NAME" | grep -qi "macbook"; then | |
| MACHINE_EMOJI="π»" | |
| TITLE_EMOJI="π»" | |
| else | |
| MACHINE_EMOJI="π₯οΈ" | |
| TITLE_EMOJI="π₯οΈ" | |
| fi | |
| MACHINE="$MACHINE_EMOJI $MODEL_NAME" | |
| # Get current timestamp in readable format | |
| READABLE_TIME=$(date "+%I:%M %p") | |
| # Get ISO 8601 timestamp for Discord | |
| ISO_TIMESTAMP=$(date -u "+%Y-%m-%dT%H:%M:%S.000Z") | |
| # Build JSON payload | |
| JSON_PAYLOAD=$(cat <<EOF | |
| { | |
| "username": "$PROJECT_NAME", | |
| "embeds": [{ | |
| "title": "$TITLE_EMOJI Claude Code Ready", | |
| "color": 5814783, | |
| "fields": [ | |
| { | |
| "name": "π Project", | |
| "value": "$PROJECT_NAME", | |
| "inline": true | |
| }, | |
| { | |
| "name": "π Time", | |
| "value": "$READABLE_TIME", | |
| "inline": true | |
| }, | |
| { | |
| "name": "π₯οΈ Machine", | |
| "value": "$MACHINE", | |
| "inline": false | |
| } | |
| ], | |
| "timestamp": "$ISO_TIMESTAMP" | |
| }] | |
| } | |
| EOF | |
| ) | |
| # Send notification to Discord (suppress output, run in background) | |
| curl -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -d "$JSON_PAYLOAD" \ | |
| "$WEBHOOK_URL" \ | |
| > /dev/null 2>&1 & | |
| # Always exit successfully to not block Claude | |
| exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "hooks": { | |
| "Stop": [ | |
| { | |
| "matcher": "", | |
| "hooks": [ | |
| { | |
| "type": "command", | |
| "command": "~/.claude/hooks/discord-notify.sh", | |
| "run_in_background": true | |
| } | |
| ] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment