Initial commit: Claude Code notification hook for telert.reily.app

- Add notification hook script with environment variable support
- Add README with setup instructions
- Add .gitignore for common files

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Kyle Fang
2025-07-18 09:09:26 +08:00
commit e78b7cdf90
3 changed files with 126 additions and 0 deletions

14
.gitignore vendored Normal file
View File

@@ -0,0 +1,14 @@
# Environment files
.env
.env.local
# OS files
.DS_Store
# Editor files
.vscode/
.idea/
# Temporary files
*.tmp
*.swp

58
README.md Normal file
View File

@@ -0,0 +1,58 @@
# Claude Code Notification Hook
A bash script that sends notifications to [telert.reily.app](https://telert.reily.app) when Claude Code events occur.
## Features
- Receives JSON input from Claude Code hooks
- Extracts message, title, and session_id from the input
- Sends formatted notifications to telert.reily.app
- Includes project name and path in notifications
## Setup
1. Clone this repository:
```bash
git clone git@github.com:zhigang1992/claude-code-notification.git
cd claude-code-notification
```
2. Set up your webhook URL:
```bash
export TELERT_WEBHOOK_URL="https://telert.reily.app/t/YOUR-WEBHOOK-ID"
```
3. Make the script executable:
```bash
chmod +x claude-notification-hook.sh
```
4. Configure Claude Code to use this hook by adding it to your settings.
## Usage
The script reads JSON from stdin and expects the following format:
```json
{
"message": "Your notification message",
"title": "Notification title",
"session_id": "optional-session-id"
}
```
### Example
```bash
echo '{"message": "Test notification", "title": "Test"}' | ./claude-notification-hook.sh
```
## Environment Variables
- `TELERT_WEBHOOK_URL` (required): Your telert.reily.app webhook URL
## Notes
- The script uses basic JSON parsing with grep and cut. For production use, consider using `jq` for more robust JSON parsing.
- Notifications include the current working directory and project name for context.
- The script has a 10-second timeout for sending notifications.

54
claude-notification-hook.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/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": "$title - $project_name",
"channel": "Terminal",
"emoji": "👋",
"text": "[$project_path] $message",
"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 $?