opencode attach --dir fails because it tries to change directory on the client instead of the server #6510

Closed
opened 2026-02-16 18:04:26 -05:00 by yindo · 2 comments
Owner

Originally created by @nyxkrage on GitHub (Jan 16, 2026).

Originally assigned to: @thdxr on GitHub.

Description

When using opencode attach with the --dir flag to connect to a remote server, the command fails because it attempts to change the directory on the local client machine rather than sending the directory path to the server.

The attach command handler calls process.chdir(args.dir) locally before connecting, which fails if the specified directory doesn't exist on the client. Even if it does exist, it passes process.cwd() as the directory to the tui function, so the resolved local path is sent to the server, which is unexpected.

Expected behavior

The --dir flag should be passed to the remote server, which resolves the path relative to where opencode serve was started.

Plugins

N/A

OpenCode version

dev @ 88fd6a294

Steps to reproduce

  1. Start opencode serve on a remote server (e.g., Linux machine in /home/user)
  2. On the remote server, ensure a project directory exists (e.g., my-project)
  3. From a local machine (e.g., macOS), run opencode attach http://:4096 --dir my-project
  4. Observe the error: ENOENT: no such file or directory, chdir '' -> 'my-project'

Screenshot and/or share link

No response

Operating System

N/A

Terminal

N/A

Originally created by @nyxkrage on GitHub (Jan 16, 2026). Originally assigned to: @thdxr on GitHub. ### Description When using opencode attach with the --dir flag to connect to a remote server, the command fails because it attempts to change the directory on the local client machine rather than sending the directory path to the server. The attach command handler calls `process.chdir(args.dir)` locally before connecting, which fails if the specified directory doesn't exist on the client. Even if it does exist, it passes `process.cwd()` as the directory to the `tui` function, so the resolved local path is sent to the server, which is unexpected. ### Expected behavior The --dir flag should be passed to the remote server, which resolves the path relative to where opencode serve was started. ### Plugins N/A ### OpenCode version dev @ 88fd6a294 ### Steps to reproduce 1. Start opencode serve on a remote server (e.g., Linux machine in /home/user) 2. On the remote server, ensure a project directory exists (e.g., my-project) 3. From a local machine (e.g., macOS), run opencode attach http://<remote-ip>:4096 --dir my-project 4. Observe the error: ENOENT: no such file or directory, chdir '<local-cwd>' -> 'my-project' ### Screenshot and/or share link _No response_ ### Operating System N/A ### Terminal N/A
yindo added the bug label 2026-02-16 18:04:26 -05:00
yindo closed this issue 2026-02-16 18:04:26 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 16, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #5380: TUI referencing local directory when using attach --dir to connect to a remote server.
  • #4967: opencode attach: File path duplicates client's relative directory, causing ENOENT
  • #4686: TUI sends absolute local paths causing ENOENT on server side

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 16, 2026): This issue might be a duplicate of existing issues. Please check: - #5380: TUI referencing local directory when using attach --dir to connect to a remote server. - #4967: `opencode attach`: File path duplicates client's relative directory, causing ENOENT - #4686: TUI sends absolute local paths causing ENOENT on server side Feel free to ignore if none of these address your specific case.
Author
Owner

@nyxkrage commented on GitHub (Jan 16, 2026):

Ah yes, this seems to be a duplicate of the first one listed. I assume it didn't come up in my because I searched for the full ENOENT error?

@nyxkrage commented on GitHub (Jan 16, 2026): Ah yes, this seems to be a duplicate of the first one listed. I assume it didn't come up in my because I searched for the full ENOENT error?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6510