gh-attach
它能做什么
这个工具可以把文件(比如图片、PDF 或视频)上传到 GitHub,也可以从 GitHub 下载文件。它会把本地文件转换成一个可分享的链接,这个链接可以直接在 GitHub 上查看,也可以从现有链接下载文件。
适用场景
- ✓需要在 GitHub 的 pull request(PR)、issue 或评论中添加图片或文档时。
- ✓想在项目中嵌入前后对比图时。
- ✓收到一个 GitHub 附件链接,需要下载文件时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/skills/gh-attach/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“把我电脑上的这张图片附加到 issue #123 中。”
每周 5 个新技能,1 分钟读完。
工作原理
工具会使用一个名为 'gh-attach' 的程序把你的文件发送到 GitHub,并生成一个链接。然后这个链接会被添加到你的 pull request、issue 或评论中。如果要下载,你提供链接,工具就会把文件保存到你的电脑上。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Upload and download GitHub user-attachments (gh-attach)
GitHub has no public API for user-attachments. The web UI uses an internal
endpoint that mints github.com/user-attachments URLs whose visibility follows the
repository they belong to. gh-attach
(MIT, sudosubin) replicates that drag-and-drop flow as a gh CLI extension, so an
agent can upload a local file from the terminal, get a URL back, and later download
an attachment URL to a file.
Overview
This skill drives gh-attach to turn a local file (screenshot, image, PDF, zip,
log, or video) into a hosted GitHub user-attachments URL, then embeds that URL
into a pull request, issue, or comment. It also downloads an existing attachment
URL back to a local file. GitHub auto-renders the URL as an image, video, or file
wherever it is pasted, and the URL inherits the repository's visibility, so a
private-repo upload stays private. It works against GitHub Cloud and GitHub
Enterprise Server.
When to Use This Skill
Use this skill when asked to:
- "Attach a screenshot to the PR" or "add an image to the PR description"
- "Attach this file (PDF, zip, log, video) to the issue or comment"
- "Embed before/after screenshots" in a PR, issue, or README
- "Download this GitHub attachment" from a
user-attachmentsURL
How It Works
Step 1: Verify prerequisites
gh auth status # gh installed and authenticated
gh extension install sudosubin/gh-attach --pin v0.4.2 --force
gh extension list | grep -F 'sudosubin/gh-attach' # require the reviewed v0.4.2 release
Uploads use a GitHub user_session browser cookie, not the gh token (that
endpoint rejects tokens). By default gh must be authenticated so gh-attach can
select the matching browser account (Chromium family, Firefox family, or Safari).
If the wrong account is selected, add --browser <name> --profile <name>. Obtain
explicit approval before allowing the pinned extension to access that interactive
browser profile. Headless and CI uploads are intentionally unsupported: never export,
store, or pass a raw user_session cookie to the extension.
Step 2: Upload
# Use an absolute quoted path; -R is optional inside a repo working dir.
URL=$(gh attach "/abs/path/screenshot.png" -R <owner>/<repo>)
gh attach prints the URL on one line to stdout. For GitHub Enterprise Server,
use -R host/owner/repo. Capture the output; it is the embeddable reference.
Step 3: Embed into the PR / issue / comment
printf '## Screenshots\n\n%s\n' "$URL" \
| gh pr comment <pr> -R <owner>/<repo> --body-file -
Use gh pr edit, gh issue comment, or gh issue edit with --body-file - for
other targets. Always pass --body-file - (not inline --body) so multi-line
bodies and special characters cannot break shell quoting. GitHub auto-renders the
URL, so paste it as-is.
Step 4: Download
# Specify the destination explicitly.
gh attach download "$URL" -O "/abs/path/out.png"
Downloads of private attachments use the active gh token, with browser cookies as
an authorization fallback.
Examples
- Attach a screenshot to PR #42: upload the file, then append the URL under a
## Screenshotsheading in the PR body withgh pr edit ... --body-file -. - Embed before/after screenshots in a README: upload both files, paste the two URLs into the README at the relevant section.
- Download an attachment for review: run
gh attach download "$URL" -O out.zipto fetch auser-attachmentsfile locally.
Best Practices
- Resolve globs to absolute paths first, and quote paths that contain spaces or Unicode.
- For display sizing, embed an HTML tag instead of the bare URL:
<img width="800" src="$URL">. - Keep uploads interactive. Do not place a GitHub browser session in CI, an environment variable, a secret store consumed by this extension, or an agent log.
gh-attachcan upload multiple files concurrently and emit Markdown or JSON output with jq-style filtering when you need to script around the result.
Limitations
- Interactive session cookie required. A
user_sessioncookie grants full account access and is not scoped like a PAT. The supported path is the reviewed, pinned extension reading an explicitly approved local browser profile; CI and headless cookie injection are out of scope.
…
常见问题
文件在 GitHub 上是怎么显示出来的?
GitHub 会根据内容类型,自动把链接显示为图片、视频或文件。如果文件位于私有仓库中,链接只对有该仓库访问权限的人有效。
我的电脑上需要安装 GitHub 吗?
需要。你要安装并配置好 'gh' 程序,因为这个工具需要和它配合使用。
上传文件安全吗?
只要上传的是你打算分享的文件,就是安全的。上传到私有仓库的文件会保持私密。要特别注意,绝不要泄露该工具内部使用的“user session cookie”,因为它拥有你账户的完整访问权限。
详情
作者的原始描述
Upload and download GitHub user-attachments (screenshots, PDFs, zips, videos) from the terminal; use when asked to attach or embed a file in a PR, issue, or comment, or download an attachment URL.
热度
- GitHub 星标
- 48k
- 排名
- #6276
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。