{"record":{"id":"f895c19d00e13f0a","repo":"JuliusBrussee/caveman","slug":"multiple-provider-credentials-detected-pass-pro","errorCode":null,"errorMessage":"multiple provider credentials detected; pass --provider","messagePattern":"multiple provider credentials detected; pass --provider","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/create-caveman-agent/src/index.ts","lineNumber":139,"sourceCode":"    \"TEMP\", \"TMP\", \"TMPDIR\", \"LANG\", \"LC_ALL\", \"LC_CTYPE\", \"TZ\", \"CI\", \"NO_COLOR\", \"FORCE_COLOR\",\n    \"HTTP_PROXY\", \"HTTPS_PROXY\", \"NO_PROXY\", \"http_proxy\", \"https_proxy\", \"no_proxy\",\n    \"NPM_CONFIG_CACHE\", \"NPM_CONFIG_REGISTRY\", \"NPM_CONFIG_USERCONFIG\",\n    \"npm_config_cache\", \"npm_config_registry\", \"npm_config_userconfig\",\n  ]) {\n    if (process.env[key] !== undefined) env[key] = process.env[key];\n  }\n  return env;\n}\n\nasync function chooseProvider(flag: string | undefined): Promise<Provider> {\n  if (flag !== undefined) return parseProvider(flag);\n  const detected: Provider[] = [];\n  if (process.env.ANTHROPIC_API_KEY) detected.push(\"anthropic\");\n  if (process.env.OPENAI_API_KEY) detected.push(\"openai\");\n  if (process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY) detected.push(\"google\");\n  if (detected.length === 1) return detected[0]!;\n  if (!process.stdin.isTTY || !process.stdout.isTTY) {\n    throw new Error(\n      detected.length === 0\n        ? \"no provider credential detected; pass --provider\"\n        : \"multiple provider credentials detected; pass --provider\",\n    );\n  }\n  const rl = createInterface({ input: process.stdin, output: process.stdout });\n  try {\n    const answer = await rl.question(\"Provider (anthropic/openai/google): \");\n    return parseProvider(answer);\n  } finally {\n    rl.close();\n  }\n}\n\nfunction projectFiles(name: string, provider: Provider): Record<string, string> {\n  return {\n    \"package.json\": `${JSON.stringify({\n      name,","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/create-caveman-agent/src/index.ts#L121-L157","documentation":"Provider auto-detection requires an unambiguous signal: if two or more credential env vars (ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY) are set, the initializer cannot choose for you. In a TTY it would prompt interactively, but non-interactive runs (no TTY on stdin or stdout) throw with this message instead of guessing.","triggerScenarios":"Non-interactive run (piped stdin/stdout, CI) with, e.g., both ANTHROPIC_API_KEY and OPENAI_API_KEY exported, and no --provider flag.","commonSituations":"Developer shells with several provider keys loaded by a shared .envrc/.zshrc, CI jobs that import a bundle of secrets, or containers built with all keys baked in.","solutions":["Pass --provider explicitly to disambiguate.","Or unset the credentials you do not want used for this run (e.g. `env -u OPENAI_API_KEY npm create ...`) so exactly one remains.","Keep per-project .env files with only the relevant provider key instead of a global kitchen-sink env."],"exampleFix":"# before: both keys set, CI run fails\n# after\nnpm create @caveman-ai/agent@latest myapp --provider openai","handlingStrategy":"validation","validationCode":"function detectedProviders(): string[] {\n  const out: string[] = [];\n  if (process.env.ANTHROPIC_API_KEY) out.push(\"anthropic\");\n  if (process.env.OPENAI_API_KEY) out.push(\"openai\");\n  if (process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY) out.push(\"google\");\n  return out;\n}\n// require detectedProviders().length <= 1, else pass --provider","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Scope exported credentials to the provider each project actually uses.","Pass --provider in automation whenever more than one key may be present.","Audit shared dotfiles (.zshrc, direnv) for multi-key exports."],"tags":["cli","environment","credentials","ambiguity"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}