Skip to content

Commit d5f397a

Browse files
authored
fix(tui): open external editor in worktree cwd (#29130)
1 parent 5ca613e commit d5f397a

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,11 @@ export function Prompt(props: PromptProps) {
509509
const nonTextParts = store.prompt.parts.filter((p) => p.type !== "text")
510510

511511
const value = text
512-
const content = await Editor.open({ value, renderer })
512+
const content = await Editor.open({
513+
value,
514+
renderer,
515+
cwd: project.instance.path().worktree || project.instance.directory() || process.cwd(),
516+
})
513517
if (!content) return
514518

515519
input.setText(content)

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,11 @@ export function Session() {
965965

966966
if (options.openWithoutSaving) {
967967
// Just open in editor without saving
968-
await Editor.open({ value: transcript, renderer })
968+
await Editor.open({
969+
value: transcript,
970+
renderer,
971+
cwd: project.instance.path().worktree || project.instance.directory() || process.cwd(),
972+
})
969973
} else {
970974
const exportDir = process.cwd()
971975
const filename = options.filename.trim()
@@ -974,7 +978,11 @@ export function Session() {
974978
await Filesystem.write(filepath, transcript)
975979

976980
// Open with EDITOR if available
977-
const result = await Editor.open({ value: transcript, renderer })
981+
const result = await Editor.open({
982+
value: transcript,
983+
renderer,
984+
cwd: project.instance.path().worktree || project.instance.directory() || process.cwd(),
985+
})
978986
if (result !== undefined) {
979987
await Filesystem.write(filepath, result)
980988
}

packages/opencode/src/cli/cmd/tui/util/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CliRenderer } from "@opentui/core"
66
import { Filesystem } from "@/util/filesystem"
77
import { Process } from "@/util/process"
88

9-
export async function open(opts: { value: string; renderer: CliRenderer }): Promise<string | undefined> {
9+
export async function open(opts: { value: string; renderer: CliRenderer; cwd?: string }): Promise<string | undefined> {
1010
const editor = process.env["VISUAL"] || process.env["EDITOR"]
1111
if (!editor) return
1212

@@ -19,6 +19,7 @@ export async function open(opts: { value: string; renderer: CliRenderer }): Prom
1919
try {
2020
const parts = editor.split(" ")
2121
const proc = Process.spawn([...parts, filepath], {
22+
cwd: opts.cwd,
2223
stdin: "inherit",
2324
stdout: "inherit",
2425
stderr: "inherit",

0 commit comments

Comments
 (0)