You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(api): fallback to gh auth token when GITHUB_TOKEN is not set #94
When github-code-search is invoked as a gh extension (gh gcs), users have already authenticated via gh auth login. Requiring them to also export GITHUB_TOKEN is unnecessary friction.
Goal
In src/api.ts, before throwing on a missing token, attempt to retrieve it from the gh CLI:
// Fallback: delegate to gh CLI if GITHUB_TOKEN is not setconstghToken=Bun.spawnSync(["gh","auth","token"]).stdout.toString().trim();if(ghToken)returnghToken;
The fallback must be silent if gh is not installed (no crash, no warning).
Behaviour
Situation
Expected result
GITHUB_TOKEN set
Used as-is (no change)
GITHUB_TOKEN unset, gh auth login done
Token retrieved from gh auth token
GITHUB_TOKEN unset, gh not installed
Error: "No GitHub token found. Set GITHUB_TOKEN or run gh auth login."
Implementation notes
The change lives in src/api.ts in the token resolution function
Bun.spawnSync exits with a non-zero code if not authenticated — handle this gracefully
No new dependency required
Acceptance criteria
Running gh gcs --org fulll "query" works without GITHUB_TOKEN after gh auth login
GITHUB_TOKEN continues to take precedence over gh auth token
Absence of gh CLI does not crash the process — it falls through to the existing error
Activity
shouze commentedon Sep 19, 2026
Closed by #208
gh auth tokenwhen GITHUB_TOKEN is not set #208