Skip to main content
Photo by Roman Synkevych via Unsplash

Bash Function to Remove Github Ghost Notifications

Every now and then my inbox in Github shows x total unread updates without having actual updates. When I click on it, there are no unread notifications. This is a known issue and it’s been around for a while. The notifications are called “ghost notifications” and they are not visible in the UI. They are only visible in the API and have probably already their own support response template.

Even clicking around and loading any separate repository that indicates having updates does not clear them. The only way to clear them is to use the API — which is why I now have a bash function that does this for me.

To make this work you need an personal Github token - not the new format, but the old one. It needs to have the notifications scope. You can create one in your developer settings. More about the notifications API. Put it in your .env file. or remove lines 2-6 and make the token available in your preferred way.

Then add the following function to your .bashrc setup.

 1g_clear_inbox() {
 2  FILE=${HOME}/.env
 3  if [ -f "${FILE}" ]; then
 4    # shellcheck disable=SC1090
 5    source "${FILE}"
 6  fi
 8  now=$(date -u +%FT%TZ)
 9  if [ -n "${GITHUB_NOTIFICATIONS_TOKEN}" ]; then
10    curl -X PUT \
11      -H "Authorization: Bearer ${GITHUB_NOTIFICATIONS_TOKEN}" \
12      -H "Accept: application/vnd.github.v3+json" \
13      -d "{\"last_read_at\": \"${now}\"}" \
15  else
16    echo "Error: GITHUB_NOTIFICATIONS_TOKEN is not set in .env."
17  fi

Running g_clear_inbox will then mark all notifications as read. This is a destructive action and cannot be undone. So use with caution. I run it on my empty inbox after I am done with all notifications.

I expect this to change, given that we call those Github tokens “classic” these days ;)

Back to top
Back Forward