{"record":{"id":"7d1d1ffe873a3c2f","repo":"mastra-ai/mastra","slug":"github-cli-is-not-authenticated-run-gh-auth-login","errorCode":null,"errorMessage":"GitHub CLI is not authenticated. Run gh auth login, then install the plugin again.","messagePattern":"GitHub CLI is not authenticated\\. Run gh auth login, then install the plugin again\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/plugins/install.ts","lineNumber":221,"sourceCode":"    child.stdout?.on('data', options.onOutput);\n    child.stderr?.on('data', options.onOutput);\n  }\n  await child;\n}\n\nasync function assertGithubCliAvailable(githubCli: string): Promise<void> {\n  try {\n    await execa(githubCli, ['--version'], NON_INTERACTIVE_EXEC_OPTIONS);\n  } catch {\n    throw new Error('GitHub CLI is required to install GitHub plugins. Install gh and run gh auth login.');\n  }\n}\n\nasync function assertGithubCliAuthenticated(githubCli: string): Promise<void> {\n  try {\n    await execa(githubCli, ['auth', 'status'], NON_INTERACTIVE_EXEC_OPTIONS);\n  } catch {\n    throw new Error('GitHub CLI is not authenticated. Run gh auth login, then install the plugin again.');\n  }\n}\n\nfunction parseGithubUrl(specifier: string): { owner: string; repo: string; repoSpec: string; ref?: string } {\n  const [urlPart, ref] = specifier.split('#', 2);\n  if (!urlPart) {\n    throw new Error(`Invalid GitHub URL: ${specifier}`);\n  }\n  let url: URL;\n  try {\n    url = new URL(urlPart);\n  } catch {\n    throw new Error(`Invalid GitHub URL: ${specifier}`);\n  }\n\n  if (url.hostname !== 'github.com') {\n    throw new Error('Only github.com plugin URLs are supported');\n  }","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/plugins/install.ts#L203-L239","documentation":"After confirming `gh` exists, installGithubPlugin checks authentication with `gh auth status`. If that command fails (not logged in, expired token, bad keyring), the SDK throws this error because private/authenticated GitHub access would otherwise fail downstream.","triggerScenarios":"Calling installGithubPlugin when `execa(githubCli, ['auth', 'status'])` exits non-zero — no logged-in account, expired OAuth token, or gh cannot read its credentials in a non-interactive environment.","commonSituations":"CI without GH_TOKEN configured; token expired after a password/2FA change; running under a different user/container that lacks gh's config dir (~/.config/gh); GH_TOKEN set to an invalid or under-scoped value.","solutions":["Run `gh auth login` interactively, then retry the install.","In CI, set GH_TOKEN (or GITHUB_TOKEN) to a valid token with repo read access, or run `gh auth login --with-token < token.txt`.","Check `gh auth status` output for expiry and run `gh auth refresh` if the token is stale.","Ensure the process environment/HOME gives gh access to its credentials (~/.config/gh/hosts.yml)."],"exampleFix":"// before (CI)\n- run: mastra plugin install github:owner/private-plugin\n\n// after\n- run: gh auth login --with-token < ./gh-token\n- run: mastra plugin install github:owner/private-plugin","handlingStrategy":"try-catch","validationCode":"import { execFileSync } from 'node:child_process';\nexport function isGhAuthenticated(): boolean {\n  try { execFileSync('gh', ['auth', 'status'], { stdio: 'ignore' }); return true; }\n  catch { return false; }\n}\nif (!isGhAuthenticated()) throw new Error('Run gh auth login before installing GitHub plugins');","typeGuard":null,"tryCatchPattern":"try {\n  await installGithubPlugin(spec);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('not authenticated')) {\n    execSync('gh auth login', { stdio: 'inherit' }); // or set GH_TOKEN in CI\n    return installGithubPlugin(spec); // retry once\n  }\n  throw err;\n}","preventionTips":["Run `gh auth login` during machine setup; verify with `gh auth status`.","In CI, set GH_TOKEN as a secret and use `gh auth login --with-token`.","Refresh tokens proactively (`gh auth refresh`) before they expire."],"tags":["github-cli","authentication","plugins","environment"],"backgroundTag":"gh-cli-not-authenticated","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}