Skip to content

Instantly share code, notes, and snippets.

@shayonpal
Last active November 8, 2025 19:40
Show Gist options
  • Save shayonpal/7cd33c21f8cab3d630c471b9a26b0d4a to your computer and use it in GitHub Desktop.
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
#!/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
"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