Skip to content

Conversation

@shuv1337
Copy link
Collaborator

@shuv1337 shuv1337 commented Jan 24, 2026

Summary

  • Restores the fork-specific feature where shuvcode attach automatically passes the client's current working directory to the server
  • This regressed during upstream merge of PR fix(attach): allow remote --dir anomalyco/opencode#8969 (commit 8ebb766)
  • Preserves upstream's improvement for remote --dir paths by early-returning when the directory doesn't exist locally

Changes

When no --dir is provided, the attach command now passes process.cwd() as the directory, ensuring file autocomplete, theme discovery, and exports use the client's directory when attaching to a remote server.

Greptile Overview

Greptile Summary

This PR successfully restores a fork-specific feature where shuvcode attach automatically passes the client's current working directory to the server. The regression occurred during the upstream merge of PR anomalyco#8969 (commit 8ebb76647), which added support for remote --dir paths but inadvertently removed the automatic cwd passing when no --dir was specified.

Key changes:

  • When no --dir flag is provided, the attach command now passes process.cwd() as the directory parameter
  • Preserves upstream's improvement: when --dir is provided but doesn't exist locally, the path is passed through to the server (for remote attach scenarios)
  • When --dir is provided and exists locally, changes to that directory and passes it via process.cwd()

Impact:
Ensures that file autocomplete, theme discovery, and exports operate in the client's directory context when attaching to remote servers, rather than using the server's launch directory.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-contained to a single file with clear logic that handles all three scenarios correctly (no --dir, local --dir, remote --dir). The implementation preserves both the fork-specific feature and upstream's remote directory support. The code is straightforward with proper error handling and clear comments explaining the behavior.
  • No files require special attention

Important Files Changed

Filename Overview
packages/opencode/src/cli/cmd/tui/attach.ts Restores fork-specific feature to pass client's cwd to server, with proper handling for remote directories

Sequence Diagram

sequenceDiagram
    participant CLI as CLI Client
    participant Handler as AttachCommand Handler
    participant FS as File System
    participant TUI as TUI (app.tsx)
    participant SDK as SDKProvider
    participant Server as OpenCode Server

    CLI->>Handler: attach <url> [--dir <path>] [--session <id>]
    
    alt --dir provided
        Handler->>FS: process.chdir(args.dir)
        alt chdir succeeds (local directory)
            FS-->>Handler: success
            Note over Handler: Directory changed locally
            Handler->>FS: process.cwd()
            FS-->>Handler: current working directory
            Handler->>TUI: tui({ url, sessionID, directory: cwd })
        else chdir fails (remote directory)
            FS-->>Handler: throws error
            Note over Handler: Directory doesn't exist locally
            Handler->>TUI: tui({ url, sessionID, directory: args.dir })
            Handler->>Handler: return early
        end
    else no --dir provided
        Handler->>FS: process.cwd()
        FS-->>Handler: current working directory
        Handler->>TUI: tui({ url, sessionID, directory: cwd })
    end
    
    TUI->>SDK: Initialize SDK with directory
    SDK->>Server: API calls with x-opencode-directory header
    Note over Server: Uses client's directory for:<br/>- File autocomplete<br/>- Theme discovery<br/>- Exports
    Server-->>SDK: Responses
    SDK-->>TUI: Data
    TUI-->>CLI: Render interface
Loading

The attach command now always passes client's cwd to the server via
the directory parameter. This fork-specific enhancement regressed
during upstream merge (PR anomalyco#8969, commit 8ebb766).

Ensures file autocomplete, theme discovery, and exports use the client's
directory when attaching to a remote server, not the server's launch dir.

Preserves upstream's remote --dir path support by early-returning when
the directory doesn't exist locally.
@shuv1337 shuv1337 changed the base branch from shuvcode-dev to integration January 26, 2026 19:35
@shuv1337 shuv1337 merged commit 2cb1eaa into integration Jan 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants