Skip to content

Instantly share code, notes, and snippets.

@jeremystretch
Created June 12, 2024 14:11
Show Gist options
  • Select an option

  • Save jeremystretch/2c09f76837fc5af787fe9ff7747ecf3f to your computer and use it in GitHub Desktop.

Select an option

Save jeremystretch/2c09f76837fc5af787fe9ff7747ecf3f to your computer and use it in GitHub Desktop.
Mark GitHub notifications as read

I've needed to do this several times to combat "ghost" notifications. These occur when a discussion is created and then deleted (e.g. for spam) before the notofication is read. You may see something like "1-0 of 4" at the bottom of the notifications page.

You can use the GitHub API client to show these notifications:

gh api notifications

To mark all notifications as read, send the API request below with curl. (Update the last_read date as needed.)

curl -L \
  -X PUT \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $TOKEN" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/notifications \
  -d '{"last_read_at":"2024-06-12T00:00:00Z","read":true}'

Unfortunately, this does not delete ghost notifications; it only marks them as read. But this at least fixes the constant notification alert.

@DanSheps
Copy link

DanSheps commented Jul 24, 2024

To delete (mark done) in python:

import requests

TOKEN = '<TOKEN>'

headers = {
    'Accept': 'application/vnd.github+json',
    'Authorization': f'Bearer {TOKEN}',
    'X-Github-Api-Version': '2022-11-28',
}

notifications = requests.get('https://api.github.com/notifications', headers=headers)

for notification in notifications.json():
    print(f"{notification['id']}: {notification['subject']['title']}")
    requests.delete(f'https://api.github.com/notifications/threads/{notification["id"]}', headers=headers)

@KSXGitHub
Copy link

Thank you so much. It's a life saver! I just received a ghost notification (from a now-deleted crypto spam repo) and GitHub UI doesn't let me dismiss it. Other people have the same problem too.

@WHYBBE
Copy link

WHYBBE commented Sep 23, 2025

To delete (mark done) in python:

import requests

TOKEN = '<TOKEN>'

headers = {
    'Accept': 'application/vnd.github+json',
    'Authorization': f'Bearer {TOKEN}',
    'X-Github-Api-Version': '2022-11-28',
}

notifications = requests.get('https://api.github.com/notifications', headers=headers)

for notification in notifications.json():
    print(f"{notification['id']}: {notification['subject']['title']}")
    requests.delete(f'https://api.github.com/notifications/threads/{notification["id"]}', headers=headers)

Great! The Python code deleted the projects that are not shown in the GitHub notifications. Thank you so much!

@xiangzhai
Copy link

Thanks!

@talentestors
Copy link

Thanks!

@Pitasi
Copy link

Pitasi commented Sep 24, 2025

You can also use gh like this:

gh api notifications -X PUT -f last_read_at=2025-09-24T00:00:00Z -f read=true

@hoang-himself
Copy link

The Y Combinator spam got me here. Very neat solution.

@zhenzou
Copy link

zhenzou commented Sep 26, 2025

@Pitasi It works, thank you.

@robkorv
Copy link

robkorv commented Sep 30, 2025

You can also use gh like this:

gh api notifications -X PUT -f last_read_at=2025-09-24T00:00:00Z -f read=true

I've added the date -Iminutes so you get the current time as an iso 8601 string with the precision on minutes.

gh api notifications -X PUT -f last_read_at=$(date -Iminutes) -f read=true

@talentestors
Copy link

I'm having this problem again, and unlike before, it doesn't have the blue dot, it just shows up in the repository. I have now found this COMMENT that solves the problem:

https://github.com/orgs/community/discussions/6874#discussioncomment-14507162

@Pitasi
Copy link

Pitasi commented Oct 17, 2025

You can also use gh like this:

gh api notifications -X PUT -f last_read_at=2025-09-24T00:00:00Z -f read=true

I've added the date -Iminutes so you get the current time as an iso 8601 string with the precision on minutes.

gh api notifications -X PUT -f last_read_at=$(date -Iminutes) -f read=true

i just realized you can omit last_read_at to mark everything as read:

gh api notifications -X PUT -f read=true

@DavidGeeraerts
Copy link

Simplest way to fix:

Switch to [Done](https://github.com/notifications?query=is%3Adone)
Select all from the first page, continue until all moved to "Inbox"
Click on --> Move to Inbox
Switch to [Inbox](https://github.com/notifications)
Select all from the first page
Click all notifications
Hit the Done button

Notifications cleared

@sijad
Copy link

sijad commented Oct 22, 2025

JS version, you can paste it to you browser console
get your token from here:

const TOKEN = '<TOKEN>';

const headers = {
  'Accept': 'application/vnd.github+json',
  'Authorization': `Bearer ${TOKEN}`,
  'X-GitHub-Api-Version': '2022-11-28'
};

async function handleNotifications() {
  const res = await fetch('https://api.github.com/notifications', { headers });
  const notifications = await res.json();

  for (const notification of notifications) {

    const deleteRes = await fetch(
      `https://api.github.com/notifications/threads/${notification.id}`,
      { method: 'DELETE', headers }
    );
  }
}

handleNotifications();

@marklai1998
Copy link

To delete (mark done) in python:

import requests

TOKEN = '<TOKEN>'

headers = {
    'Accept': 'application/vnd.github+json',
    'Authorization': f'Bearer {TOKEN}',
    'X-Github-Api-Version': '2022-11-28',
}

notifications = requests.get('https://api.github.com/notifications', headers=headers)

for notification in notifications.json():
    print(f"{notification['id']}: {notification['subject']['title']}")
    requests.delete(f'https://api.github.com/notifications/threads/{notification["id"]}', headers=headers)

Add ?all=true the get notification endpoint if the notification is mark as read

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment