File paths resolved from server's cwd instead of client's cwd when using opencode attach #3241

Closed
opened 2026-02-16 17:39:17 -05:00 by yindo · 1 comment
Owner

Originally created by @ZergRocks on GitHub (Dec 1, 2025).

Description

When running opencode server in one directory and using opencode attach from a different directory, file references (using @ syntax) are resolved relative to the server's working directory instead of the client's current working directory.

This makes it difficult to work with multiple projects while running a single server instance.

Steps to reproduce

  1. Start the server from a parent directory:

    cd ~/Development
    opencode
    
  2. From another terminal, navigate to a subdirectory and attach:

    cd ~/Development/saturdays/saturdays
    opencode attach
    
  3. Try to reference a file that exists in the client's cwd:

    @docs/report.md
    
  4. Server throws ENOENT because it looks for the file at ~/Development/docs/report.md instead of ~/Development/saturdays/saturdays/docs/report.md

Error

ENOENT: no such file or directory, stat '/Users/an/Development/saturdays/saturdays/docs/1_report.md'
    path: "/Users/an/Development/saturdays/saturdays/docs/1_report.md",
 syscall: "stat",
   errno: -2,
    code: "ENOENT"

Expected behavior

When using opencode attach, the client should pass its current working directory to the server, and file paths should be resolved relative to the client's cwd (or allow switching workspace context).

Use case

Running a single OpenCode server instance and attaching from different project directories without needing to restart the server or use absolute paths for every file reference.

Possible solutions

  1. Pass client's cwd to server on attach and use it for path resolution
  2. Add a command like /cd or /workspace to switch the server's working directory context
  3. Support workspace/project switching within a single server session

Related

  • #4686 (similar issue but for remote Windows -> Linux scenario)

Environment

  • OpenCode version: 1.0.x
  • OS: macOS
  • Terminal: Any
Originally created by @ZergRocks on GitHub (Dec 1, 2025). ### Description When running `opencode` server in one directory and using `opencode attach` from a different directory, file references (using `@` syntax) are resolved relative to the **server's working directory** instead of the **client's current working directory**. This makes it difficult to work with multiple projects while running a single server instance. ### Steps to reproduce 1. Start the server from a parent directory: ```bash cd ~/Development opencode ``` 2. From another terminal, navigate to a subdirectory and attach: ```bash cd ~/Development/saturdays/saturdays opencode attach ``` 3. Try to reference a file that exists in the client's cwd: ``` @docs/report.md ``` 4. Server throws ENOENT because it looks for the file at `~/Development/docs/report.md` instead of `~/Development/saturdays/saturdays/docs/report.md` ### Error ``` ENOENT: no such file or directory, stat '/Users/an/Development/saturdays/saturdays/docs/1_report.md' path: "/Users/an/Development/saturdays/saturdays/docs/1_report.md", syscall: "stat", errno: -2, code: "ENOENT" ``` ### Expected behavior When using `opencode attach`, the client should pass its current working directory to the server, and file paths should be resolved relative to the client's cwd (or allow switching workspace context). ### Use case Running a single OpenCode server instance and attaching from different project directories without needing to restart the server or use absolute paths for every file reference. ### Possible solutions 1. Pass client's cwd to server on attach and use it for path resolution 2. Add a command like `/cd` or `/workspace` to switch the server's working directory context 3. Support workspace/project switching within a single server session ### Related - #4686 (similar issue but for remote Windows -> Linux scenario) ### Environment - **OpenCode version**: 1.0.x - **OS**: macOS - **Terminal**: Any
yindo added the opentui label 2026-02-16 17:39:17 -05:00
yindo closed this issue 2026-02-16 17:39:17 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 1, 2025):

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

  • #4686: TUI sends absolute local paths causing ENOENT on server side

Both issues describe the same root problem: file paths are resolved relative to the wrong working directory context (server's cwd instead of client's cwd) when using remote/attach scenarios. While #4686 specifically addresses Windows→Linux remote connections, the underlying path resolution logic is shared.

Feel free to ignore if your specific case differs from the existing issues.

@github-actions[bot] commented on GitHub (Dec 1, 2025): This issue might be a duplicate of existing issues. Please check: - #4686: TUI sends absolute local paths causing ENOENT on server side Both issues describe the same root problem: file paths are resolved relative to the wrong working directory context (server's cwd instead of client's cwd) when using remote/attach scenarios. While #4686 specifically addresses Windows→Linux remote connections, the underlying path resolution logic is shared. Feel free to ignore if your specific case differs from the existing issues.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3241