{"record":{"id":"6f5772b678c56ee1","repo":"JuliusBrussee/caveman","slug":"managed-gemini-cli-routing-is-unsupported-because","errorCode":null,"errorMessage":"managed Gemini CLI routing is unsupported because Gemini CLI cannot send separate Caveman and upstream credentials","messagePattern":"managed Gemini CLI routing is unsupported because Gemini CLI cannot send separate Caveman and upstream credentials","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":7106,"sourceCode":"  const start = stripped.indexOf(GEMINI_NATIVE_ENV_BEGIN);\n  const finish = stripped.indexOf(GEMINI_NATIVE_ENV_END);\n  if ((start === -1) !== (finish === -1) || (start !== -1 && finish < start)) {\n    throw new Error(\"existing Gemini Caveman routing block is corrupted; run `caveman doctor gemini`\");\n  }\n  if (start !== -1) stripped = `${stripped.slice(0, start)}${stripped.slice(finish + GEMINI_NATIVE_ENV_END.length)}`.trim();\n  const block = [\n    GEMINI_NATIVE_ENV_BEGIN,\n    `GEMINI_BASE_URL=${route}`,\n    `GOOGLE_GEMINI_BASE_URL=${route}`,\n    `GOOGLE_VERTEX_BASE_URL=${appendUrlPath(route, \"/vertex\")}`,\n    GEMINI_NATIVE_ENV_END,\n  ].join(\"\\n\");\n  return { text: `${stripped}${stripped ? \"\\n\\n\" : \"\"}${block}\\n`, block };\n}\n\nfunction geminiNativeMutations(gw: string, mcpBinary: string): NativeMutation[] {\n  if (wrapMode(gw) === \"managed\") {\n    throw new Error(\"managed Gemini CLI routing is unsupported because Gemini CLI cannot send separate Caveman and upstream credentials\");\n  }\n  const settingsPath = geminiSettingsPath();\n  const settingsBefore = fileBytes(settingsPath);\n  const settings = parseJsonFileObject(settingsPath, settingsBefore);\n  assertNativeHooksShape(settingsPath, settings, \"gemini\");\n  if (settings.mcpServers !== undefined && (typeof settings.mcpServers !== \"object\" || settings.mcpServers === null || Array.isArray(settings.mcpServers))) {\n    throw new Error(`${settingsPath} mcpServers must be a JSON object; refusing to overwrite it`);\n  }\n  const servers = settings.mcpServers && typeof settings.mcpServers === \"object\" && !Array.isArray(settings.mcpServers)\n    ? settings.mcpServers as Record<string, unknown>\n    : {};\n  const previousMcp = servers.caveman;\n  const installedMcp = { command: mcpBinary, args: [] };\n  servers.caveman = installedMcp;\n  settings.mcpServers = servers;\n  const withHooks = nativeHooksDocument(\"gemini\", nativeShrinkEnabled(), settings);\n\n  const envPath = join(geminiConfigDir(), \".env\");","sourceCodeStart":7088,"sourceCodeEnd":7124,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L7088-L7124","documentation":"`geminiNativeMutations()` refuses to manage Gemini CLI routing in `managed` wrap mode because Gemini CLI cannot send separate Caveman and upstream credentials — a single auth channel means managed mode's credential separation is impossible. Native (local) wrap mode is required for Gemini.","triggerScenarios":"Calling `geminiNativeMutations(gw, mcpBinary)` while `wrapMode(gw) === \"managed\"` — i.e. the CLI is configured to route through a managed gateway but the user/native-integration path targets Gemini CLI.","commonSituations":"User switched their Caveman plan/config to a managed gateway (or set the managed gateway URL) but keeps using Gemini CLI as the agent; org config forces managed mode; running the same setup command across agents where managed mode works for Claude but not Gemini.","solutions":["Switch wrap mode to local/native for Gemini (e.g. remove the managed gateway setting or run with local mode) and re-run setup","Use a supported agent (e.g. Claude CLI) if you must stay in managed wrap mode","Check `caveman config`/env for the gateway/mode setting and change it to the local gateway URL","Ask Caveman support/issue tracker if managed Gemini routing is available in newer versions"],"exampleFix":"// before\nCAVEMAN_GATEWAY=https://gw.managed.caveman.dev   # managed mode\n// after\nCAVEMAN_GATEWAY=http://127.0.0.1:<local-port>    # local wrap mode\n$ caveman setup","handlingStrategy":"validation","validationCode":"// Ensure local wrap mode before configuring Gemini natively:\nif (wrapMode(process.env.CAVEMAN_GATEWAY ?? '') === 'managed') {\n  throw new Error('Gemini CLI requires local wrap mode; switch off the managed gateway');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await cavemanSetup(['gemini']);\n} catch (e) {\n  if (String(e.message).includes('managed Gemini CLI routing is unsupported')) {\n    // switch gateway config to local mode (or pick a supported agent) and retry\n  }\n  throw e;\n}","preventionTips":["Use the local gateway when the agent is Gemini CLI; reserve managed mode for supported agents","Check `caveman config` for the current wrap mode before running setup","Document per-agent mode requirements in team onboarding docs","Validate CAVEMAN_GATEWAY points at the local instance in shell profiles used for Gemini work"],"tags":["gemini","unsupported-mode","managed-gateway","auth"],"backgroundTag":"unsupported-operation","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}