Skip to content

cli: no way to set a server-side session directory with --server #62072

Closed as duplicate

Description

@andycostintoma

cli: no way to set a server-side session directory with --server

Summary

When a client connects to an OpenCode server on another host (opencode --server <url>), there is no CLI way to start a session in a directory that exists on the server. All directory inputs are resolved on the client, so cross-host workflows need a raw HTTP API call to create the session first, then -s to open it.

Environment

  • opencode version: 2.2.1
  • OS: Linux 7.1.8-200.fc44.x86_64 (client); headless Linux server (same version, reached via SSH port-forward)
  • Terminal: TERM_PROGRAM=ghostty, TERM=xterm-ghostty, COLORTERM=truecolor
  • Shell: zsh
  • Install/channel: latest
  • Active plugins: opencode-secrets, rtk, sound-notify, @tarquinen/opencode-dcp

Reproduction

  1. On the server, start the opencode service and note a project path that exists only there, e.g. /home/alice/myproject.
  2. On the client (different home dir, project not checked out), forward the port (ssh -L 49380:127.0.0.1:49380 server) and run opencode --server http://127.0.0.1:49380 /home/alice/myproject.
  3. The client resolves the positional directory locally → fails with ENOENT before contacting the server.
  4. Launching instead from a local cwd (e.g. ~/work): the TUI starts but the session lands at the server's current location, not the project; CLI subcommands (opencode session list) error with Location not found: /home/bob/work because the client cwd doesn't exist server-side.
  5. The only working route is the HTTP API: POST /api/session with {"location":{"directory":"/home/alice/myproject"}}, then opencode --server <url> -s <session-id>.

Expected Behavior

A CLI-level way to express "start a new session at this directory on the server" — e.g. a --remote-dir/--location flag, resolving the positional path server-side when --server is set, or a setter for the server's current location (/api/location is GET-only today).

Actual Behavior

The positional <directory> argument and cwd are client-side only. A path that exists only on the server fails on the client (ENOENT); a path that exists only on the client fails on the server (Location not found). When client and server have different home directories, no single path can satisfy both.

Additional Context

Workaround wrapper (what we ship today):

sid=$(curl -u "opencode:$pw" -X POST "$url/api/session" \
  -H 'Content-Type: application/json' \
  -d '{"location":{"directory":"/home/alice/myproject"}}' \
  | jq -r '.data.id')
OPENCODE_PASSWORD="$pw" opencode --server "$url" -s "$sid"

Same cross-host setup (TUI against a remote opencode service over an SSH forward) as #62063.

Activity

  1. opencodejr commented on Nov 5, 2026

    @opencodejr

    Thanks for the detailed write-up and the workaround script. I think this is a duplicate of #47665. It describes the same problem: with --server, the positional <directory> is resolved on the client (chdir → ENOENT for server-only paths), and the client's cwd is sent as the session location. It has been reproduced on 2.2.x, and there is a proposed fix in #47818 that is waiting for maintainers to decide how this should work (positional path or a separate option).

    Possible duplicates and related issues, ordered by likelihood:

    If you'd like a separate option (such as --location or a settable /api/location) in addition to that fix, please mention it on #47665. The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. opencodejr commented on Nov 6, 2026

    @opencodejr

    We haven't heard back, so I'm closing this as a duplicate of #47665. That issue covers the same problem: with --server, the positional directory and cwd are resolved on the client, so you can't start a session in a directory that only exists on the server. The proposed fix in #47818 is waiting for maintainers to decide how this should work. Please follow #47665 for updates, and add your idea for a separate option (--location or a settable /api/location) there if it matters to you. If your case turns out to be different, reply here and we can reopen this issue. Thanks for the clear report and the workaround script.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions