← ClaudeAtlas

stop-hook-dedup-guardlisted

Use when a Claude Code Stop hook sends a Telegram (or other) notification and the same message arrives duplicated at nearly the same timestamp. Symptom is two identical "⏳ Running…" + message pairs appearing within seconds of each other after closing Claude Code.
williamblair333/Uncle-J-s-Refinery · ★ 3 · AI & Automation · score 73
Install: claude install-skill williamblair333/Uncle-J-s-Refinery
# Stop Hook Dedup Guard ## Overview When multiple Claude Code sessions are open simultaneously, every one fires the Stop hook on close. If the hook sends a Telegram notification you get N identical messages at the same timestamp. A file-based dedup window — record the last send time, skip if within N seconds — fixes it in one guard block. ## Diagnosis - Two (or more) identical Telegram messages at nearly the same timestamp - Messages appear as pairs — same content repeated within 1–5 seconds - Reproducible when multiple CC windows or projects were open **Root cause:** Each CC session maintains its own Stop hook registration. When two sessions close around the same time, both trigger the hook independently with no coordination. ## Fix: File-Based Dedup Window Add this guard at the top of the hook script, before any `notify` / `curl` / `telegram` call: ```bash DEDUP_FILE="/tmp/$(basename "$0")-last-sent" DEDUP_WINDOW=15 # seconds if [ -f "$DEDUP_FILE" ]; then last_sent=$(cat "$DEDUP_FILE") now=$(date +%s) age=$(( now - last_sent )) if [ "$age" -lt "$DEDUP_WINDOW" ]; then exit 0 # duplicate within window — skip silently fi fi date +%s > "$DEDUP_FILE" # ... rest of hook (send notification, etc.) ... ``` The first invocation writes the timestamp and proceeds; any subsequent invocation within the window exits silently. ## Tuning | Parameter | Default | Notes | |-----------|---------|-------| | `DEDUP_WINDOW` | 15s | CC sessions closing "si