Repository navigation
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Context
GITHUB_TOKEN must currently be set manually in the environment before running github-code-search. Many users already have the GitHub CLI (gh) installed and authenticated via gh auth login, which duplicates the token setup step unnecessarily.
Solution
- When
GITHUB_TOKENis not set, detect whether theghCLI is installed and, if so, retrieve a token viagh auth token. GITHUB_TOKEN(the env var) still takes precedence whenever it's set — zero added subprocess calls on that path.- If
ghis not installed, orgh auth tokenfails (not logged in, no scopes, etc.), fall back to today's existing error message unchanged. - Isolate the
ghsubprocess detection/invocation in a dedicated module (e.g.src/gh-cli.ts), with the resolution decision implemented as a pure, dependency-injected function so it can be unit tested without actually spawning a process — per the "pure functions first" architecture principle inAGENTS.md. The actualBun.which/ subprocess spawn call is the sole non-tested I/O call site in that module (same convention asrender/terminal.tsfor Bun APIs). - Apply the same fallback to both the search commands (default +
query) and theupgradesubcommand, which already usesGITHUB_TOKENopportunistically.
Acceptance Criteria
- When
GITHUB_TOKENis set, it is always used as-is;ghis never invoked. - When
GITHUB_TOKENis unset,ghis installed and authenticated, the token returned bygh auth tokenis used transparently. - When
GITHUB_TOKENis unset andghis not installed (orgh auth tokenfails/returns empty), the existing "GITHUB_TOKEN environment variable is not set" error is shown, unchanged. - Behavior is identical for the
upgradesubcommand's optional token usage. - Documented in
docs/reference/environment.md,docs/getting-started/index.md, andREADME.md.
Definition of Done
- Unit tests for the pure resolution logic (dependency-injected
ghdetection/execution — no real subprocess spawned in tests). -
bun test,bun run lint,bun run format:check,bun run knip,bun run build.tsall green. - Docs and the VitePress site reflect the new behavior end to end.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity
Fall back to gh auth token when GITHUB_TOKEN is not set
Fall back to gh auth token when GITHUB_TOKEN is not set