{"record":{"id":"a6e6e6f7fcae04b7","repo":"JuliusBrussee/caveman","slug":"opencode-providerid-baseurl-changed-after-enabl","errorCode":null,"errorMessage":"OpenCode ${providerID} baseURL changed after enable; refusing destructive disable","messagePattern":"OpenCode (.+?) baseURL changed after enable; refusing destructive disable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":8359,"sourceCode":"    const text = current.toString(\"utf8\");\n    if (text.includes(GEMINI_NATIVE_ENV_BEGIN) && !text.includes(block)) {\n      throw new Error(\"Gemini routing block changed after enable; refusing destructive disable\");\n    }\n    return Buffer.from(text.replace(`${block}\\n\\n`, \"\").replace(`\\n\\n${block}\\n`, \"\\n\").replace(`${block}\\n`, \"\").replace(block, \"\"));\n  }\n  if (operation.kind === \"opencode-plugin\" || operation.kind === \"pi-extension\") {\n    throw new Error(`${operation.file} changed after enable; refusing destructive disable`);\n  }\n  if (operation.kind === \"opencode-config\") {\n    const root = parseJsonFileObject(operation.file, current);\n    const providers = root.provider && typeof root.provider === \"object\" && !Array.isArray(root.provider) ? root.provider as Record<string, unknown> : {};\n    const routes = operation.owned?.routes && typeof operation.owned.routes === \"object\" && !Array.isArray(operation.owned.routes) ? operation.owned.routes as Record<string, unknown> : {};\n    const previousRoutes = operation.owned?.previous_routes && typeof operation.owned.previous_routes === \"object\" && !Array.isArray(operation.owned.previous_routes) ? operation.owned.previous_routes as Record<string, unknown> : {};\n    for (const providerID of [\"openai\", \"anthropic\"]) {\n      const provider = providers[providerID] && typeof providers[providerID] === \"object\" && !Array.isArray(providers[providerID]) ? providers[providerID] as Record<string, unknown> : {};\n      const options = provider.options && typeof provider.options === \"object\" && !Array.isArray(provider.options) ? provider.options as Record<string, unknown> : {};\n      if (options.baseURL !== undefined && options.baseURL !== routes[providerID]) {\n        throw new Error(`OpenCode ${providerID} baseURL changed after enable; refusing destructive disable`);\n      }\n      if (previousRoutes[providerID] === null || previousRoutes[providerID] === undefined) delete options.baseURL;\n      else options.baseURL = previousRoutes[providerID];\n      if (Object.keys(options).length > 0) provider.options = options;\n      else delete provider.options;\n      if (Object.keys(provider).length > 0) providers[providerID] = provider;\n      else delete providers[providerID];\n    }\n    if (Object.keys(providers).length > 0) root.provider = providers;\n    else delete root.provider;\n    const mcp = root.mcp && typeof root.mcp === \"object\" && !Array.isArray(root.mcp) ? root.mcp as Record<string, unknown> : {};\n    if (mcp.caveman !== undefined && JSON.stringify(mcp.caveman) !== JSON.stringify(operation.owned?.installed_mcp)) {\n      throw new Error(\"OpenCode caveman MCP entry changed after enable; refusing destructive disable\");\n    }\n    if (mcp.caveman !== undefined) {\n      if (operation.owned?.previous_mcp === null || operation.owned?.previous_mcp === undefined) delete mcp.caveman;\n      else mcp.caveman = operation.owned.previous_mcp;\n    }","sourceCodeStart":8341,"sourceCodeEnd":8377,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L8341-L8377","documentation":"During disable/uninstall, the tool rolls back OpenCode provider config it enabled earlier. Before mutating a provider (openai/anthropic), it verifies the recorded route baseURL still matches the live options.baseURL. If the user edited the baseURL after enable, the tool refuses to disable destructively rather than clobbering a hand-modified config.","triggerScenarios":"Running the disable operation when opencode config providers[\"openai\"|\"anthropic\"].options.baseURL is set and !== the baseURL recorded in operation.owned.routes[providerID].","commonSituations":"User pointed the provider at a proxy or self-hosted gateway (e.g. LiteLLM, Azure endpoint) after enabling Caveman, then tried to disable; tooling rewrote the config externally so the journaled route no longer matches.","solutions":["Restore options.baseURL to the value recorded in the enable journal (operation.owned.routes[providerID]), then re-run disable.","Manually edit the OpenCode config to remove Caveman's provider entries instead of using the disable command.","If the new baseURL is intentional, re-run enable so the journal is refreshed, then disable.","Delete the stale journal/operation state if you accept manual config management."],"exampleFix":"// before (config.json)\n\"openai\": { \"options\": { \"baseURL\": \"https://my-proxy.example.com/v1\" } }\n// after - restore the journaled value before disabling\n\"openai\": { \"options\": { \"baseURL\": \"https://api.openai.com/v1\" } }","handlingStrategy":"validation","validationCode":"const cfg = JSON.parse(fs.readFileSync(opencodeConfig, 'utf8'));\nfor (const id of ['openai', 'anthropic']) {\n  const b = cfg?.provider?.[id]?.options?.baseURL;\n  if (b !== undefined && b !== journal.owned?.routes?.[id]) {\n    throw new Error(`baseURL for ${id} differs from journaled value; resolve before disable`);\n  }\n}","typeGuard":"const hasCustomBaseURL = (cfg, id, routes) =>\n  typeof cfg?.provider?.[id]?.options?.baseURL === 'string' &&\n  cfg.provider[id].options.baseURL !== routes?.[id];","tryCatchPattern":"try {\n  await caveman.disable(['opencode']);\n} catch (err) {\n  if (err.message.includes('baseURL changed after enable')) {\n    console.error('Restore the journaled baseURL or disable manually:', err.message);\n  } else throw err;\n}","preventionTips":["Don't hand-edit provider baseURL in OpenCode config while Caveman integration is enabled.","Disable Caveman first, then apply custom baseURL changes.","Keep the enable journal/state file intact until disable completes.","Keep the OpenCode config in git so you can diff/restore before disabling."],"tags":["config","disable-safety","provider-baseurl"],"backgroundTag":"conflicting-config-options","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"}