diff --git a/packages/opencode/src/cli/cmd/tui.ts b/packages/opencode/src/cli/cmd/tui.ts index 87f6f982..04e90978 100644 --- a/packages/opencode/src/cli/cmd/tui.ts +++ b/packages/opencode/src/cli/cmd/tui.ts @@ -100,7 +100,7 @@ export const TuiCommand = cmd({ UI.empty() UI.println(UI.logo(" ")) const result = await Bun.spawn({ - cmd: [process.execPath, "auth", "login"], + cmd: [...getOpencodeCommand(), "auth", "login"], cwd: process.cwd(), stdout: "inherit", stderr: "inherit", @@ -112,3 +112,25 @@ export const TuiCommand = cmd({ } }, }) + +/** + * Get the correct command to run opencode CLI + * In development: ["bun", "run", "packages/opencode/src/index.ts"] + * In production: ["/path/to/opencode"] + */ +function getOpencodeCommand(): string[] { + // Check if OPENCODE_BIN_PATH is set (used by shell wrapper scripts) + if (process.env["OPENCODE_BIN_PATH"]) { + return [process.env["OPENCODE_BIN_PATH"]] + } + + const execPath = process.execPath.toLowerCase() + + if (Installation.isDev()) { + // In development, use bun to run the TypeScript entry point + return [execPath, "run", process.argv[1]] + } + + // In production, use the current executable path + return [process.execPath] +}