Add a self-hosted "Stargazers over time" chart to any GitHub repo's README. GitHub now restricts the stargazers endpoint to a repo's own admins/collaborators, s
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-star-history-chart-b9da8837b89a ,按照其中的说明把「star-history-chart」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Add a "Stargazers over time" chart that renders from a static SVG committed to the repo and refreshes itself weekly — no external chart service, no broken images.
GitHub now restricts the /stargazers endpoint to a repository's own admins and
collaborators. Unauthenticated requests return {"message":"Requires authentication"}, which breaks every third-party live-chart service
(star-history.com free tier, starchart.cc, etc.) for all repos. The only
reliable fix is to generate the chart yourself with an authenticated token and
commit a static image. Inside GitHub Actions, the repo's own GITHUB_TOKEN can
read its own stargazers, so the whole thing runs with zero secrets to configure.
scripts/generate_star_history.py — fetches stargazers (authenticated),
renders a clean, light/dark-adaptive SVG..github/workflows/star-history.yml — weekly cron + manual trigger that
regenerates and commits docs/star-history.svg.mkdir -p scripts .github/workflows docs
cp skills/git/star-history-chart/scripts/generate_star_history.py scripts/generate_star_history.py
cp skills/git/star-history-chart/assets/star-history.yml .github/workflows/star-history.yml
The script needs the
requestspackage:pip install requests. It resolves the repo fromSTAR_HISTORY_REPO, thenGITHUB_REPOSITORY(set automatically in Actions), then theorigingit remote — so no edits are required for it to work in a different repo.
Use a token that can read the repo's stargazers (as owner/collaborator). The GitHub CLI provides one:
GITHUB_TOKEN=$(gh auth token) python scripts/generate_star_history.py
This writes docs/star-history.svg. For a repo with many thousands of stars the
first run paginates the whole stargazer list and can take a couple of minutes.
Verify it rendered (optional, macOS): qlmanage -t -s 800 -o . docs/star-history.svg
Add or replace the star chart section. Point the image at the local SVG. Set the link target to wherever you want clicks to go (the repo, a docs page, or your own site):
## Stargazers over time
[](https://github.com/OWNER/REPO/stargazers)
If replacing a broken star-history.com / starchart.cc embed, swap only the
image URL to docs/star-history.svg and keep or update the link target.
git add scripts/generate_star_history.py .github/workflows/star-history.yml docs/star-history.svg README.md
git commit -m "feat(readme): self-hosted stargazers chart with weekly auto-refresh"
git push
The workflow runs every Monday at 04:00 UTC. To refresh immediately without waiting: GitHub → Actions → "Update Star History" → Run workflow.
STAR_HISTORY_OUTPUT (default docs/star-history.svg).STAR_HISTORY_REPO=owner/name..line, .area, .dot CSS and WIDTH/HEIGHT
constants near the top of generate_star_history.py. The chart is
theme-aware via a prefers-color-scheme: dark block, so it looks right in
both GitHub light and dark modes.cron expression in the workflow.GITHUB_TOKEN.requests plus the Python standard library.