Context
Part of the gh-gcs epic (#93).
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 set
const ghToken = Bun.spawnSync(["gh", "auth", "token"]).stdout.toString().trim();
if (ghToken) return ghToken;
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
Context
Part of the
gh-gcsepic (#93).When
github-code-searchis invoked as aghextension (gh gcs), users have already authenticated viagh auth login. Requiring them to also exportGITHUB_TOKENis unnecessary friction.Goal
In
src/api.ts, before throwing on a missing token, attempt to retrieve it from theghCLI:The fallback must be silent if
ghis not installed (no crash, no warning).Behaviour
GITHUB_TOKENsetGITHUB_TOKENunset,gh auth logindonegh auth tokenGITHUB_TOKENunset,ghnot installedgh auth login."Implementation notes
src/api.tsin the token resolution functionBun.spawnSyncexits with a non-zero code if not authenticated — handle this gracefullyAcceptance criteria
gh gcs --org fulll "query"works withoutGITHUB_TOKENaftergh auth loginGITHUB_TOKENcontinues to take precedence overgh auth tokenghCLI does not crash the process — it falls through to the existing errorbun test && bun run lintpass