{"record":{"id":"4ee0474351e4fc57","repo":"abhigyanpatwari/GitNexus","slug":"provider-cli-found-but-version-failed-exit","errorCode":null,"errorMessage":"${provider} CLI found but --version failed (exit ${(err as { status?: number }).status ?? '?'}). Ensure it is authenticated: run `${COMMANDS[provider]} --version` manually.","messagePattern":"(.+?) CLI found but --version failed \\(exit (.+?)\\)\\.status \\?\\? '\\?'\\}\\)\\. Ensure it is authenticated: run `(.+?) --version` manually\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gitnexus/src/core/wiki/local-cli-client.ts","lineNumber":79,"sourceCode":"    logger.info({ provider, args }, '[local-cli]');\n  }\n}\n\nconst cachedCommands = new Map<LocalAgentProvider, LocalCommand | null>();\n\nexport function detectLocalCLI(provider: LocalAgentProvider): string | null {\n  if (cachedCommands.has(provider)) return cachedCommands.get(provider)?.displayName ?? null;\n  const commandInfo = resolveLocalCommand(provider);\n  try {\n    execFileSync(commandInfo.command, [...commandInfo.argsPrefix, '--version'], {\n      stdio: 'ignore',\n    });\n    cachedCommands.set(provider, commandInfo);\n  } catch (err: unknown) {\n    const isNotFound =\n      err instanceof Error && 'code' in err && (err as NodeJS.ErrnoException).code === 'ENOENT';\n    if (!isNotFound && err instanceof Error) {\n      logger.warn(\n        `${provider} CLI found but --version failed (exit ${(err as { status?: number }).status ?? '?'}). ` +\n          `Ensure it is authenticated: run \\`${COMMANDS[provider]} --version\\` manually.`,\n      );\n    }\n    cachedCommands.set(provider, null);\n  }\n  return cachedCommands.get(provider)?.displayName ?? null;\n}\n\nexport function resolveLocalCLIConfig(overrides?: Partial<LocalCLIConfig>): LocalCLIConfig {\n  return {\n    model: overrides?.model,\n    workingDirectory: overrides?.workingDirectory,\n    requestTimeoutMs: overrides?.requestTimeoutMs,\n  };\n}\n\nexport async function callClaudeLLM(","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/52924ef12c2290ceee4612526a828ec4cdf2047f/gitnexus/src/core/wiki/local-cli-client.ts#L61-L97","documentation":"detectLocalCLI(provider) found the binary (so not ENOENT) but running `<command> --version` via execFileSync exited non-zero — almost always 'installed but not authenticated'. The provider (claude | codex | opencode) is cached as null, so wiki generation will not attempt to use that CLI and falls back elsewhere. The message names the exact manual command to run.","triggerScenarios":"Wiki generation with a local provider configured; resolveLocalCommand succeeds, execFileSync(command, [...argsPrefix, '--version'], { stdio: 'ignore' }) throws with a status code (non-zero exit) and code !== 'ENOENT'. Typical: CLI never logged in, expired credentials, broken install that fails before printing a version.","commonSituations":"Fresh machines with CLIs installed but not authenticated; CI environments without credential stores; token expiry between runs; wrapper scripts (nvm shims, homebrew) exiting non-zero in non-TTY contexts.","solutions":["Run exactly what the message suggests: `claude --version` / `codex --version` / `opencode --version` manually and complete the authentication flow it triggers.","Verify the binary on PATH is the real CLI (`which claude`) and works in a non-TTY shell.","Reinstall or upgrade the provider CLI if --version crashes for non-auth reasons.","Alternatively configure wiki generation to use a provider/model that does not need the local CLI."],"exampleFix":"# before: 'claude CLI found but --version failed (exit 1). Ensure it is authenticated'\nclaude           # complete login\nclaude --version  # verify it now exits 0\nnpx gitnexus wiki  # after: detection succeeds","handlingStrategy":"validation","validationCode":"// Before wiki generation: fail fast with an actionable message\nimport { detectLocalCLI } from 'gitnexus/dist/core/wiki/local-cli-client.js';\nfor (const provider of ['claude', 'codex', 'opencode'] as const) {\n  if (configured(provider) && !detectLocalCLI(provider)) {\n    throw new Error(`${provider} CLI unusable — run \\`${provider} --version\\` and authenticate first`);\n  }\n}","typeGuard":"function isAuthExitFailure(err: unknown): boolean {\n  return err instanceof Error && 'status' in err &&\n    (err as NodeJS.ErrnoException).code !== 'ENOENT'; // found, but exited non-zero\n}","tryCatchPattern":null,"preventionTips":["Authenticate provider CLIs in CI images before wiki jobs (`claude --version` exits 0 when ready).","Cache invalidation: detection caches null — restart the process after authenticating.","Prefer explicit provider/model config that avoids the local CLI when auth is impossible."],"tags":["cli","authentication","wiki","local-provider","version-check"],"backgroundTag":"cli-authentication-failed","analyzedSha":"52924ef12c2290ceee4612526a828ec4cdf2047f","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}