It’s possible to programmatically upload images to GitHub Issues, Pull Requests and Comments via automation. Finally, though maybe mistakenly, I dunno.

It’s fairly well known that for the longest time, GitHub has not had a programmatic interface for uploading images and attachments. It’s possible in the browser, by dragging-and-dropping your image, but not via something you can script or curl. That’s been a bummer for lots of GitHub Action-powered systems you might imagine, like: automatically attaching demo screenshots or videos on PRs for new features, or attaching failure screenshots or visual diffs from browser tests.

Until now, I guess. Here’s the unofficial, undocumented endpoint:

FILE=cat.jpg
MIME=image/jpeg
REPOSITORY=bensheldon/good_job
TOKEN=$(gh auth token)

curl -s "https://uploads.github.com/user-attachments/assets?name=$FILE&content_type=$MIME&repository_id=$(gh api "repos/$REPOSITORY" --jq .id)" \
  -X POST -H "Authorization: Bearer $TOKEN" \
  -H "Accept: application/json" --data-binary "@$FILE"

# that outputs a JSON response containing the attachment URL, which you can then embed in an image tag into the GitHub content.

That’s it! I mean, you can be more clever than curl or whatever, but that’s the idea. It’s equivalent to dragging-and-dropping an image into an Issue, PR, or Comment.

I don’t know if this endpoint always accepted an Auth Token and no one tried or noticed or talked about it, or if that’s new. My memory was that this endpoint only previously accepted Cookie Auth: circa 2018 I explored different Visual Diff services and the lack of a programmatic API for GitHub attachments meant that to DIY you’d have to use a service like S3, and then a service to authorize S3, and that’s annoying to set up when GitHub Actions could do everything else. I’m pretty sure I tried to fuzz the attachment interface at the time and it didn’t work.

I recently learned all of this was possible because Justin Gordon of Shakacode shared a link to Intercom’s 2x-skills attach-github-assets and I was… skeptical… and then I tried it and it worked!

Ben Sheldon asking Claude to use the attach-github-assets skill to upload a placekitten image as a comment to a GitHub issue, and Claude successfully doing so

It’s very useful, I hope it doesn’t go away.