Skip to content

opencode attach without --dir uses server cwd instead of client cwd #14460

Closed

Description

@rexdotsh

Description

When I run opencode attach <url> without --dir, attach starts in the server process directory (where opencode serve was started), not in the directory where I ran attach.

It seems the attach request is missing the client directory context when --dir is omitted, so the server falls back to its own working-directory default.

Plugins

None

OpenCode version

1.2.10

Steps to reproduce

  1. In terminal A:
    • cd /tmp/a
    • opencode serve --port 4096
  2. In terminal B:
    • cd /tmp/b
    • opencode attach http://localhost:4096
  3. Attach starts in /tmp/a instead of /tmp/b.

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on Feb 20, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or closely related to existing issues. Please check:

  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 20, 2026
  3. rmk40 commented on Feb 20, 2026

    @rmk40
    Contributor

    This sounds like it's working as it's should. If you're attaching, why would you expect opencode to start in a different directory than where it was started as a server?

  4. rexdotsh commented on Feb 20, 2026

    @rexdotsh
    ContributorAuthor

    This sounds like it's working as it's should. If you're attaching, why would you expect opencode to start in a different directory than where it was started as a server?

    Fair, I think this is actually a regression from #8969 though?

    #6715 specifically made attach pass the client's process.cwd() as the default directory. After #8969 refactored the --dir handling, the no---dir path started returning undefined, which means no directory header gets sent and the server just falls back to its own cwd.

    For context, I run opencode serve as a long-lived system service and connect to it from different project directories. In that setup the server's startup directory isn't really useful as a default, the directory I'm running attach from is what I'd expect it to use. And --dir is already there for when you want to override that.

  5. github-actions commented on Apr 22, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions