GitHub Forker
Fork GitHub repositories extracted from text or images. You need GITHUB_TOKEN set in the
environment with repo permissions.
What you do
- 1. Extract all GitHub repository URLs from the input (text, image, or both)
- Fork each repository via the GitHub API
- Star the original repository after a successful fork
- Report results clearly
Step 1: Extract GitHub URLs
From text
Scan the input for patterns matching:
- -
https://github.com/{owner}/{repo} (with or without trailing slash, path, or fragment) - INLINECODE2 (without scheme)
- INLINECODE3 only when context makes it clearly a GitHub repo
Normalize each match to the canonical form: https://github.com/{owner}/{repo}
Strip any extra path segments — you only need owner and repo name.
From images
When the user provides an image (screenshot, photo, diagram), use your vision capabilities to
read the image and identify any GitHub URLs or repo references visible in it. Apply the same
extraction rules as above to whatever text you find.
Truncated URLs
URLs are often cut off in screenshots or social media previews, like:
When you detect a truncated URL (ends with ... or …, or the repo name is clearly incomplete):
- 1. Search GitHub for matching repos:
curl -s -L \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/search/repositories?q={owner}/{partial}+in:full_name&per_page=5"
Use whatever partial info you have — owner + partial repo name is ideal; owner alone works too.
- 2. Use context to pick the best match. Look at surrounding text, tweet content, project name
mentioned, description keywords, and star count. If one result stands out clearly:
- The repo name starts with the visible partial (e.g.
op... →
openchamber matches)
- The description aligns with what the user said (e.g. "UI真好" → pick the UI-focused one)
- It has significantly more stars than the others
If you're confident, proceed directly and tell the user your reasoning:
CODEBLOCK1
- 3. Ask the user only when genuinely uncertain — when multiple results are plausible and
context doesn't help distinguish them:
CODEBLOCK2
Never fork a truncated URL without either a confident inference or explicit user confirmation.
Step 2: Fork via GitHub API
For each unique {owner}/{repo} pair, call the fork endpoint:
CODEBLOCK3
The -L flag is required — GitHub's API returns a 307 redirect that must be followed.
- - If
GITHUB_TOKEN is not set, tell the user to set it and stop:
export GITHUB_TOKEN="ghp_..." # classic PAT (recommended)
# To persist across sessions, add to ~/.zshrc or ~/.bash_profile
- - Fork requests are async on GitHub's side — a 202 response means "accepted", not "done".
- If a repo is already forked, GitHub returns the existing fork (not an error) — that's fine.
- Handle HTTP errors:
-
401: bad or expired token
-
403: token lacks fork permission. For
classic PATs, need
repo or
public_repo scope. For
fine-grained PATs, need "Administration: Read and write" permission (not just
contents).
-
404: repo not found or private (token has no access)
Step 3: Star the original repository
After a successful fork, star the original repo:
CODEBLOCK5
A 204 response means success. Star failures are non-fatal — if starring fails, note it in the
report but don't treat the overall operation as failed.
Step 4: Report results
After all forks are attempted, show a clear summary:
CODEBLOCK6
If the token's authenticated username isn't obvious, extract it from the fork response
(full_name field gives your-username/repo-name).
Edge cases
- - No URLs found: Tell the user clearly — "No GitHub repository URLs found in the input."
- Private repos: Fork will fail with 404 if the token doesn't have access; report the error.
- Duplicate URLs: Deduplicate before forking — fork each unique repo once.
- Non-repo URLs: Ignore
github.com/ paths that aren't owner/repo format (e.g., github.com/features, github.com/login).
GitHub Forker
从文本或图像中提取GitHub仓库并进行Fork操作。你需要在环境中设置具有仓库权限的GITHUB_TOKEN。
操作步骤
- 1. 提取输入内容(文本、图像或两者)中的所有GitHub仓库URL
- Fork每个仓库(通过GitHub API)
- Star原始仓库(Fork成功后)
- 报告结果(清晰明了)
步骤1:提取GitHub URL
从文本中提取
扫描输入内容,匹配以下模式:
- - https://github.com/{owner}/{repo}(可带或不带尾部斜杠、路径或片段)
- github.com/{owner}/{repo}(无协议头)
- {owner}/{repo}(仅当上下文明确指向GitHub仓库时)
将每个匹配项规范化为标准格式:https://github.com/{owner}/{repo}
去除任何多余的路径段——你只需要所有者名称和仓库名称。
从图像中提取
当用户提供图像(截图、照片、图表)时,使用你的视觉能力读取图像,识别其中可见的任何GitHub URL或仓库引用。对找到的文本应用上述相同的提取规则。
截断的URL
URL在截图或社交媒体预览中经常被截断,例如:
- - github.com/openchamber/op...
- github.com/some-owner/proj…
当你检测到截断的URL(以...或…结尾,或仓库名称明显不完整)时:
- 1. 在GitHub上搜索匹配的仓库:
bash
curl -s -L \
-H Authorization: Bearer $GITHUB_TOKEN \
-H Accept: application/vnd.github+json \
https://api.github.com/search/repositories?q={owner}/{partial}+in:full
name&perpage=5
使用你拥有的任何部分信息——所有者+部分仓库名称是最理想的;仅所有者名称也可以。
- 2. 利用上下文选择最佳匹配。 查看周围文本、推文内容、提及的项目名称、描述关键词和星标数。如果某个结果明显突出:
- 仓库名称以可见部分开头(例如op... → openchamber匹配)
- 描述与用户所说的内容一致(例如UI真好 → 选择专注于UI的那个)
- 它的星标数明显高于其他结果
如果你有把握,直接进行并告知用户你的推理:
github.com/openchamber/op... → 推断为 openchamber/openchamber ⭐1.5k(OpenCode的桌面UI,与上下文UI真好匹配)
- 3. 仅在真正不确定时询问用户——当多个结果都合理且上下文无法区分它们时:
发现截断的URL github.com/foo/bar... — 您指的是哪个仓库?
1. foo/barista ⭐420 — 咖啡店POS系统
2. foo/baroque ⭐38 — 巴洛克音乐生成器
输入数字(或输入0跳过):
在没有把握的推断或用户明确确认的情况下,切勿Fork截断的URL。
步骤2:通过GitHub API进行Fork
对于每个唯一的{owner}/{repo}对,调用Fork端点:
bash
curl -s -L -X POST \
-H Authorization: Bearer $GITHUB_TOKEN \
-H Accept: application/vnd.github+json \
-H X-GitHub-Api-Version: 2022-11-28 \
https://api.github.com/repos/{owner}/{repo}/forks
-L标志是必需的——GitHub的API会返回一个必须跟随的307重定向。
- - 如果未设置GITHUB_TOKEN,告知用户设置它并停止:
bash
export GITHUB
TOKEN=ghp... # 经典PAT(推荐)
# 要跨会话持久化,请添加到~/.zshrc或~/.bash_profile
- - Fork请求在GitHub端是异步的——202响应表示已接受,而非已完成。
- 如果仓库已被Fork,GitHub会返回现有的Fork(而非错误)——这没问题。
- 处理HTTP错误:
-
401:令牌错误或已过期
-
403:令牌缺少Fork权限。对于
经典PAT,需要repo或public_repo范围。对于
细粒度PAT,需要Administration: Read and write权限(不仅仅是contents)。
-
404:仓库未找到或为私有(令牌无访问权限)
步骤3:Star原始仓库
成功Fork后,Star原始仓库:
bash
curl -s -L -X PUT \
-H Authorization: Bearer $GITHUB_TOKEN \
-H Accept: application/vnd.github+json \
-H X-GitHub-Api-Version: 2022-11-28 \
https://api.github.com/user/starred/{owner}/{repo}
204响应表示成功。Star失败是非致命的——如果Star失败,在报告中注明,但不要将整个操作视为失败。
步骤4:报告结果
在所有Fork尝试完成后,显示清晰的摘要:
发现X个仓库:
✓ owner/repo — 已Fork → https://github.com/YOUR_USERNAME/repo ⭐ 已Star
✓ owner/repo — 已Fork → https://github.com/YOUR_USERNAME/repo (Star失败:<原因>)
✗ owner/repo — 失败:<原因>
如果令牌的认证用户名不明显,从Fork响应中提取(full_name字段给出your-username/repo-name)。
边界情况
- - 未找到URL:清晰告知用户——输入中未找到GitHub仓库URL。
- 私有仓库:如果令牌没有访问权限,Fork将失败并返回404;报告错误。
- 重复URL:在Fork前去重——每个唯一仓库只Fork一次。
- 非仓库URL:忽略不是owner/repo格式的github.com/路径(例如github.com/features、github.com/login)。