Repository navigation
Description
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
- On the server, start the opencode service and note a project path that exists only there, e.g.
/home/alice/myproject. - On the client (different home dir, project not checked out), forward the port (
ssh -L 49380:127.0.0.1:49380 server) and runopencode --server http://127.0.0.1:49380 /home/alice/myproject. - The client resolves the positional directory locally → fails with ENOENT before contacting the server.
- 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 withLocation not found: /home/bob/workbecause the client cwd doesn't exist server-side. - The only working route is the HTTP API:
POST /api/sessionwith{"location":{"directory":"/home/alice/myproject"}}, thenopencode --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
opencodejr commentedon Nov 5, 2026
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→ENOENTfor 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:
--server, and it lists the same 'create the session on the server, then-s' workaround./cduses the client's home directory for~and autocomplete when connected to a remote server (fix proposed in fix(tui): use server home for remote directory changes #55203).If you'd like a separate option (such as
--locationor 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.opencodejr commentedon Nov 6, 2026
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 (--locationor 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.