Skip to content

fix(installation): respect GITHUB_TOKEN/GH_TOKEN for GitHub API release check#23475

Open
octo-patch wants to merge 1 commit intoanomalyco:devfrom
octo-patch:fix/issue-23461-github-token-upgrade
Open

fix(installation): respect GITHUB_TOKEN/GH_TOKEN for GitHub API release check#23475
octo-patch wants to merge 1 commit intoanomalyco:devfrom
octo-patch:fix/issue-23461-github-token-upgrade

Conversation

@octo-patch
Copy link
Copy Markdown

@octo-patch octo-patch commented Apr 20, 2026

Issue for this PR

Closes #23461

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Problem

opencode upgrade (and the update-check on startup) calls GET https://api.github.com/repos/anomalyco/opencode/releases/latest without authentication. Unauthenticated GitHub API calls are capped at 60 requests/hour per IP. Users behind shared proxies or VPNs quickly exhaust this quota, causing 403 errors:

Error: Unexpected error, check log file...
StatusCode: non 2xx status code (403 GET https://api.github.com/repos/anomalyco/opencode/releases/latest)

Even when GITHUB_TOKEN was set in the environment or the user was authenticated via gh auth login, opencode did not use those credentials.

Solution

Read GITHUB_TOKEN or GH_TOKEN from the environment and, when present, attach it as a Authorization: Bearer <token> header on the GitHub releases request. This raises the rate limit to 5,000 requests/hour, which is sufficient for any realistic usage pattern.

The change is in Installation.latestImpl — only the fallback GitHub API path (used by curl and unknown install methods) is affected. All other version sources (npm registry, Homebrew, Chocolatey, Scoop) are unchanged.

How did you verify your code works?

  • With GITHUB_TOKEN unset: behaviour is identical to before (no header sent).
  • With GITHUB_TOKEN set to a valid PAT: the Authorization header is included, rate limit 5000/hr applies.
  • With GH_TOKEN set (GitHub CLI convention): same as above.

Screenshots / recordings

N/A — this is a backend/CLI change with no UI surface.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When checking for the latest release version, pass the GitHub token from
GITHUB_TOKEN or GH_TOKEN environment variables as a Bearer auth header.
This raises the API rate limit from 60 to 5000 req/hr, preventing 403
errors for users behind shared proxies or VPNs (fixes anomalyco#23461).
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 20, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode upgrade fails with 403 (doesn't respect GITHUB_TOKEN)

1 participant