Skip to content

Instantly share code, notes, and snippets.

@mcanouil
Created September 24, 2025 14:05
Show Gist options
  • Select an option

  • Save mcanouil/4037a16f28c52a5a865923d91b19deb7 to your computer and use it in GitHub Desktop.

Select an option

Save mcanouil/4037a16f28c52a5a865923d91b19deb7 to your computer and use it in GitHub Desktop.
Get rid of GitHub ghost notification
#!/usr/bin/env bash
# https://github.com/orgs/community/discussions/6874
DAYS_AGO=${1:-7}
# Cross-platform: prefer BSD -v, fall back to GNU -d
if date -v -"${DAYS_AGO}"d +%Y >/dev/null 2>&1; then
DATE=$(date -v -"${DAYS_AGO}"d +%Y-%m-%d)
else
DATE=$(date -d "${DAYS_AGO} days ago" +%Y-%m-%d)
fi
echo "${DATE}"
gh api --paginate "/notifications?all=true&since=${DATE}T00:00:00Z" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" | jq -s '.[]' > notifications.json
for THREAD_URL in $(jq -r '.[] | select(.url) | .url' notifications.json); do
echo "gh api -X DELETE \"${THREAD_URL}\" \
-H \"Accept: application/vnd.github+json\" \
-H \"X-GitHub-Api-Version: 2022-11-28\""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment