mirror of
https://github.com/zhigang1992/claude-code-notification.git
synced 2026-01-12 08:04:24 +08:00
- Add detailed setup instructions for ~/.claude/settings.json - Remove duplicate information from notification text - Move project path to the end of the message on its own line 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
1.4 KiB
Bash
Executable File
55 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Claude Code notification hook for telert.reily.app
|
|
# Reads JSON from stdin and sends notification via curl
|
|
|
|
# Read JSON input from stdin
|
|
input=$(cat)
|
|
|
|
# Extract fields from JSON using basic parsing
|
|
# Note: This is a simple approach - for production use, consider using jq
|
|
message=$(echo "$input" | grep -o '"message"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
|
|
title=$(echo "$input" | grep -o '"title"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
|
|
session_id=$(echo "$input" | grep -o '"session_id"[[:space:]]*:[[:space:]]*"[^"]*"' | cut -d'"' -f4)
|
|
|
|
# Set defaults if fields are empty
|
|
message=${message:-"Claude Code notification"}
|
|
title=${title:-"Claude Code"}
|
|
session_id=${session_id:-"unknown"}
|
|
|
|
# Get current timestamp
|
|
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
|
|
# Get current working directory
|
|
project_path=$(pwd)
|
|
project_name=$(basename "$project_path")
|
|
|
|
# Build JSON payload
|
|
payload=$(cat <<EOF
|
|
{
|
|
"event": "Claude Code - $project_name",
|
|
"channel": "Terminal",
|
|
"emoji": "👋",
|
|
"text": "$message\n\n$project_path",
|
|
"notify": true
|
|
}
|
|
EOF
|
|
)
|
|
|
|
# Check if webhook URL is set
|
|
if [ -z "$TELERT_WEBHOOK_URL" ]; then
|
|
echo "Error: TELERT_WEBHOOK_URL environment variable is not set" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Send notification using curl
|
|
curl -X POST "$TELERT_WEBHOOK_URL" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$payload" \
|
|
--max-time 10 \
|
|
-s \
|
|
-w "\nNotification sent successfully: %{http_code}\n"
|
|
|
|
# Exit with curl's exit code
|
|
exit $?
|