surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | #!/bin/bash |
| 2 | # Example: Format teammate idle notification |
| 3 | # |
| 4 | # This script demonstrates how to format raw JSON idle notifications |
| 5 | # into user-friendly display format. |
| 6 | # |
| 7 | # Usage: echo '{"type":"idle_notification","from":"worker-1","timestamp":"..."}' | ./format-idle-notification.sh |
| 8 | |
| 9 | set -euo pipefail |
| 10 | |
| 11 | # Read JSON from stdin |
| 12 | input=$(cat) |
| 13 | |
| 14 | # Parse notification type |
| 15 | notification_type=$(echo "$input" | jq -r '.type // empty' 2>/dev/null || echo "") |
| 16 | |
| 17 | if [[ "$notification_type" == "idle_notification" ]]; then |
| 18 | # Extract fields |
| 19 | worker_name=$(echo "$input" | jq -r '.from // "worker"') |
| 20 | timestamp=$(echo "$input" | jq -r '.timestamp // empty') |
| 21 | |
| 22 | # Format timestamp if present |
| 23 | time_str="" |
| 24 | if [[ -n "$timestamp" ]]; then |
| 25 | # Try to format the timestamp |
| 26 | time_str=$(date -d "$timestamp" '+%H:%M:%S' 2>/dev/null || echo "") |
| 27 | fi |
| 28 | |
| 29 | # Output formatted notification using recommended format: |
| 30 | # ⏺ worker-1 |
| 31 | # ⎿ Status is idle |
| 32 | echo "⏺ $worker_name" |
| 33 | if [[ -n "$time_str" ]]; then |
| 34 | echo " ⎿ Status is idle ($time_str)" |
| 35 | else |
| 36 | echo " ⎿ Status is idle" |
| 37 | fi |
| 38 | |
| 39 | # Output JSON for hook system |
| 40 | if [[ -n "$time_str" ]]; then |
| 41 | jq -n --arg msg "⏺ $worker_name\n ⎿ Status is idle ($time_str)" \ |
| 42 | '{"systemMessage": $msg}' |
| 43 | else |
| 44 | jq -n --arg msg "⏺ $worker_name\n ⎿ Status is idle" \ |
| 45 | '{"systemMessage": $msg}' |
| 46 | fi |
| 47 | else |
| 48 | # Not an idle notification, pass through |
| 49 | echo "$input" |
| 50 | fi |