Skip to content

fix(tui): fall back to local cwd when editor spawns in attach mode#30583

Open
pcadena-lila wants to merge 1 commit into
anomalyco:devfrom
pcadena-lila:fix/editor-attach-cwd
Open

fix(tui): fall back to local cwd when editor spawns in attach mode#30583
pcadena-lila wants to merge 1 commit into
anomalyco:devfrom
pcadena-lila:fix/editor-attach-cwd

Conversation

@pcadena-lila
Copy link
Copy Markdown

Issue for this PR

Closes #30582

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

In opencode attach mode, the /editor command (ctrl+x e) fails silently because the server's project directory (e.g. /home/user/project) does not exist on the local machine where the TUI client runs.

Editor.open() passes the server-reported project.instance.path().worktree as cwd to Process.spawn(). When that path doesn't exist locally, the spawn fails and the editor never opens.

This fix checks whether the resolved cwd exists on the local filesystem before using it. If it doesn't (as is always the case in remote attach mode), it falls back to process.cwd().

How did you verify your code works?

  1. Started opencode serve --port 4096 on a remote Linux machine
  2. Forwarded port: ssh -L 4096:127.0.0.1:4096 <remote>
  3. Ran opencode attach http://localhost:4096 locally (macOS, iTerm2)
  4. Pressed ctrl+x e — editor ($EDITOR=nvim) now opens correctly
  5. Verified standalone mode (opencode directly) still works as before

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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 anomalyco#30582
@ethan605
Copy link
Copy Markdown

ethan605 commented Jun 3, 2026

I can confirm that the fix works for me (with a relatively similar setup). Thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/editor command (ctrl+x e) does not work in opencode attach mode

2 participants