{"record":{"id":"6ddd297fa4a8e690","repo":"abhigyanpatwari/GitNexus","slug":"opencode-cli-not-found-install-opencode-cli-and-e","errorCode":null,"errorMessage":"OpenCode CLI not found. Install OpenCode CLI and ensure `opencode` is on PATH.","messagePattern":"OpenCode CLI not found\\. Install OpenCode CLI and ensure `opencode` is on PATH\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/wiki/local-cli-client.ts","lineNumber":244,"sourceCode":"  };\n\n  if (provider === 'opencode') {\n    delete env.OPENCODE_SERVER_PASSWORD;\n    delete env.OPENCODE_SERVER_USERNAME;\n  }\n\n  return env;\n}\n\nexport async function callOpenCodeLLM(\n  prompt: string,\n  config: LocalCLIConfig,\n  systemPrompt?: string,\n  options?: CallLLMOptions,\n): Promise<LLMResponse> {\n  const commandInfo = getDetectedCommand('opencode');\n  if (!commandInfo) {\n    throw new Error(\n      'OpenCode CLI not found. Install OpenCode CLI and ensure `opencode` is on PATH.',\n    );\n  }\n\n  const workingDirectory = config.workingDirectory || process.cwd();\n  const fullPrompt = systemPrompt ? `${systemPrompt}\\n\\n---\\n\\n${prompt}` : prompt;\n  // OpenCode does not expose a Codex-style read-only sandbox / no-tools flag,\n  // so we rely on its non-interactive permission model and tolerate any\n  // non-JSON stdout warnings in the parser.\n  const args = ['run', '--format', 'json', '--dir', workingDirectory];\n\n  if (config.model) {\n    args.push('--model', config.model);\n  }\n\n  const response = await runLocalCLI('opencode', commandInfo, args, config, fullPrompt, options);\n  return { content: parseOpenCodeEventStream(response.content) };\n}","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/52924ef12c2290ceee4612526a828ec4cdf2047f/gitnexus/src/core/wiki/local-cli-client.ts#L226-L262","documentation":"callOpenCodeLLM resolves the `opencode` executable through getDetectedCommand('opencode') before doing anything else. If detection fails (no opencode binary reachable on the PATH of the GitNexus process), it throws immediately with install guidance rather than spawning and failing cryptically.","triggerScenarios":"Enabling wiki generation or any local-LLM step with provider 'opencode' on a machine where the opencode binary is not installed, is installed under a bin directory absent from PATH, or GitNexus runs in an environment with a stripped PATH (IDE-launched shells, launchd, minimal CI containers, nvm node bin mismatch).","commonSituations":"Fresh machine without opencode; installed via a non-default package manager prefix (pnpm/bun global dirs) not on PATH; running GitNexus from an IDE terminal or systemd/launchd unit where PATH differs from the login shell; switching wiki provider to 'opencode' without ever installing it.","solutions":["Install OpenCode CLI: `curl -fsSL https://opencode.ai/install | bash` or `npm install -g opencode-ai`.","Verify resolution in the same environment GitNexus runs in: `which opencode && opencode --version`.","Add the install's bin directory to PATH (export PATH=\"$PATH:$HOME/.opencode/bin\" or the npm global bin dir) in the shell profile, service unit, or CI env.","If you cannot install it, switch the wiki generator's provider away from 'opencode' so GitNexus never attempts detection."],"exampleFix":"# before: binary not on PATH of the GitNexus process\n$ gitnexus wiki generate --provider opencode\nError: OpenCode CLI not found. Install OpenCode CLI and ensure `opencode` is on PATH.\n\n# after: install, verify, retry\n$ npm install -g opencode-ai\n$ which opencode && opencode --version\n$ gitnexus wiki generate --provider opencode","handlingStrategy":"validation","validationCode":"import { execFileSync } from 'node:child_process';\n\nfunction opencodeAvailable(): boolean {\n  try {\n    execFileSync(process.platform === 'win32' ? 'where' : 'which', ['opencode'], { stdio: 'ignore' });\n    return true;\n  } catch {\n    return false;\n  }\n}\n\nif (config.wiki?.provider === 'opencode' && !opencodeAvailable()) {\n  throw new Error('opencode selected for wiki but not on PATH — install it or change provider');\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await callOpenCodeLLM(prompt, config);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('OpenCode CLI not found')) {\n    // configuration problem, not transient: switch provider or surface install instructions\n    return useNonLLMWikiFallback();\n  }\n  throw err;\n}","preventionTips":["Verify `which opencode` inside the exact environment gitnexus runs in (CI, IDE, service units strip PATH).","Install opencode in a standard bin location or add its bin dir to PATH in the service/CI env.","Add a startup check for the configured provider's binary before launching long jobs."],"tags":["opencode","cli-not-found","path","local-llm","wiki","environment"],"backgroundTag":"command-not-found","analyzedSha":"52924ef12c2290ceee4612526a828ec4cdf2047f","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}