anomalyco / anomalyco/opencode

cli(v2): positional directory resolved locally even with --server, fails on remote-only paths

Open
#47,665 3 comments 0 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Sep 6, 2026.

2.0
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

  1. On the Linux server, have a project at /home/sasha/ks and start the server (opencode2 serve, reachable over tailscale).
  2. On the macOS client, run either order:
    • opencode2 "/home/sasha/ks" --server https://<server>
    • opencode2 --server https://<server> "/home/sasha/ks"
  3. 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 (branch v2): if (requestedDirectory !== undefined) process.chdir(requestedDirectory) runs unconditionally, ignoring requestedServer.
  • packages/tui/src/app.tsx:212 then uses process.cwd() as location.directory, so even a successful local chdir would send the local path.
  • Server side (packages/server/src/location.ts, requestRef) already supports receiving the directory via location[directory] query / x-opencode-directory header 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.