anomalyco / anomalyco/opencode
cli(v2): positional directory resolved locally even with --server, fails on remote-only paths
@jlongster is already working on this.
Since Sep 6, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
opencode2 <directory> --server <url> fails with a local ENOENT chdir when the directory only exists on the remote server. The CLI resolves the positional directory locally before considering --server, instead of passing it through as the remote location.
Environment
- opencode version: v0.0.0-beta-19192
- OS: macOS 26.6.2 client -> Linux server (6.8.0-139-generic, x86_64)
- Terminal: Ghostty 1.3.1
- Shell: Unavailable (not provided)
- Install/channel: beta
- Active plugins: none found in config
Reproduction
- On the Linux server, have a project at
/home/sasha/ksand start the server (opencode2 serve, reachable over tailscale). - On the macOS client, run either order:
opencode2 "/home/sasha/ks" --server https://<server>opencode2 --server https://<server> "/home/sasha/ks"
- Observe immediate failure before any connection:
ERROR: ENOENT: no such file or directory, chdir '...' -> '/home/sasha/ks'
Expected Behavior
With --server, the positional directory should be sent to the server and resolved server-side as the session location (no local chdir).
Actual Behavior
Both argument orders crash locally in process.chdir() because /home/sasha/ks does not exist on the Mac. V1 had the same class of bug (attach --dir, #5380/#8933/#8981/#11896); V2 reintroduces it via the positional directory argument.
Additional Context
packages/cli/src/commands/handlers/default.ts:19(branchv2):if (requestedDirectory !== undefined) process.chdir(requestedDirectory)runs unconditionally, ignoringrequestedServer.packages/tui/src/app.tsx:212then usesprocess.cwd()aslocation.directory, so even a successful localchdirwould send the local path.- Server side (
packages/server/src/location.ts,requestRef) already supports receiving the directory vialocation[directory]query /x-opencode-directoryheader and falls back to server cwd — the client just never gets that far. - Consistently reproducible. Workaround: connect bare (
opencode2 --server <url>, lands in server cwd) or pre-create the session server-side and attach with--session <id> --continue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.