From 4a9e1a9cc2c3ed57856021e84410afe943dc752f Mon Sep 17 00:00:00 2001 From: Porfirio Quintero Date: Wed, 3 Jun 2026 11:05:19 -0400 Subject: [PATCH] fix(tui): fall back to local cwd when editor spawns in attach mode In attach mode the server's project directory does not exist on the local machine, so Process.spawn fails with an invalid cwd. Check that the resolved cwd exists before using it; fall back to process.cwd() otherwise. Closes #30582 --- packages/opencode/src/cli/cmd/tui/util/editor.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/cli/cmd/tui/util/editor.ts b/packages/opencode/src/cli/cmd/tui/util/editor.ts index 03d91cf6dd10..d6a74f4cc1a0 100644 --- a/packages/opencode/src/cli/cmd/tui/util/editor.ts +++ b/packages/opencode/src/cli/cmd/tui/util/editor.ts @@ -1,4 +1,5 @@ import { defer } from "@/util/defer" +import { existsSync } from "node:fs" import { rm } from "node:fs/promises" import { tmpdir } from "node:os" import { join } from "node:path" @@ -13,13 +14,17 @@ export async function open(opts: { value: string; renderer: CliRenderer; cwd?: s const filepath = join(tmpdir(), `${Date.now()}.md`) await using _ = defer(async () => rm(filepath, { force: true })) + // In attach mode the server's project directory may not exist locally. + // Fall back to the local process cwd so the editor can still spawn. + const cwd = opts.cwd && existsSync(opts.cwd) ? opts.cwd : process.cwd() + await Filesystem.write(filepath, opts.value) opts.renderer.suspend() opts.renderer.currentRenderBuffer.clear() try { const parts = editor.split(" ") const proc = Process.spawn([...parts, filepath], { - cwd: opts.cwd, + cwd, stdin: "inherit", stdout: "inherit", stderr: "inherit",