Skip to content

attach: @ file mentions use client-local path instead of remote directory #13732

@the3asic

Description

@the3asic

Bug

When using opencode attach to connect to a remote OpenCode server, selecting a file via @ mention in the TUI builds a file://... URL using the client machine's process.cwd() (local path), not the remote server's working directory.

This causes the server to resolve the URL on the remote filesystem and try to read a path that only exists on the client (e.g. a macOS path), so the attachment fails / the wrong file is read.

Environment

  • OpenCode CLI: 1.2.4
  • Client: macOS
  • Server: Linux (remote OpenCode server)

Steps to reproduce

  1. Start an OpenCode server on a remote machine (e.g. opencode serve).
  2. On the client machine, run: opencode attach http://<remote-host>:4096 --dir /path/to/project (or attach to a server already running in that project).
  3. In the TUI prompt, type @ and select any file from autocomplete.

Actual

The inserted part uses a file:// URL based on the client's process.cwd() (local path). The server then resolves that URL and tries to read it on the remote filesystem, resulting in file-not-found / incorrect file content.

Expected

@ file mentions during remote attach should resolve against the remote server directory (e.g. the directory returned by path.get() / sync.data.path.directory, or the directory provided via --dir).

Likely cause

packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx currently does:

const fullPath = `${process.cwd()}/${item}`
const urlObj = pathToFileURL(fullPath)

When attached, process.cwd() is client-local.

Suggested fix

Use the remote directory from sync (e.g. sync.data.path.directory, sourced from sdk.client.path.get()) as the base directory for pathToFileURL, with a fallback to process.cwd() for local mode.

Example:

const baseDir = (sync.data.path.directory || process.cwd()).replace(/\/+$/, "")
const fullPath = item.startsWith("/") ? item : `${baseDir}/${item}`
const urlObj = pathToFileURL(fullPath)

Metadata

Metadata

Assignees

Labels

opentuiThis relates to changes in v1.0, now that opencode uses opentui

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions