Skip to content

samiralibabic/opencode-rexd-target

opencode-rexd-target

opencode-rexd-target is an OpenCode plugin that makes selected remote machines feel like local development.

It routes tool calls to REXD, the Remote Execution Daemon, over SSH stdio (ssh ... rexd --stdio).

OpenCode with active REXD target routing tools to a remote machine

What is REXD?

REXD is a lightweight remote execution daemon that exposes process, filesystem, and PTY operations through a JSON-RPC API.

This plugin acts as the OpenCode client layer for REXD targets:

  • On active target: tool calls are routed to remote rexd
  • Without active target: file/shell tools run locally (normal OpenCode behavior)
  • PTY tools are currently remote-only and require an active target

Features

  • /target command handling: list, use, status, clear
  • Transparent tool routing to remote REXD when a target is active
  • Local fallback when no target is active
  • Core remote filesystem and shell support: bash, read, write, list, glob, grep
  • Remote file parity with native REXD methods: edit, apply_patch
  • PTY support via dedicated remote tools: pty_spawn, pty_write, pty_read, pty_list, pty_kill

Requirements

  • OpenCode with plugin support
  • REXD installed on target hosts and reachable over SSH
  • Target registry at ~/.config/rexd/targets.json
  • REXD version with fs.edit and fs.patch support (v0.1.3+). For loginShell compatibility mode, use v0.1.4+.

Install

Latest release:

curl -fsSL https://raw.githubusercontent.com/samiralibabic/opencode-rexd-target/main/scripts/install.sh | bash

Pinned version:

curl -fsSL https://raw.githubusercontent.com/samiralibabic/opencode-rexd-target/main/scripts/install.sh | OPENCODE_REXD_TARGET_VERSION=v0.3.1 bash

The installer places files in your OpenCode config directory:

  • ~/.config/opencode/plugins/rexd-target.js
  • ~/.config/opencode/commands/target.md

Post-install setup (required)

  1. Ensure every target host runs REXD v0.1.4 or newer.
  2. Create/update ~/.config/rexd/targets.json on your local machine.
  3. Restart OpenCode so the plugin is reloaded.
  4. Run /target list and then /target use <alias>.

Configure targets

Example ~/.config/rexd/targets.json:

{
  "version": 1,
  "targets": {
    "prod": {
      "transport": "ssh",
      "host": "example.com",
      "user": "deploy",
      "loginShell": false,
      "workspaceRoots": ["/srv/app"],
      "defaultCwd": "/srv/app"
    }
  }
}

loginShell is optional and defaults to false.

  • false (default): predictable non-login shell execution for automation.
  • true: compatibility mode for legacy targets that require login-shell startup files.

Usage

In OpenCode:

  • /target list
  • /target use <alias>
  • /target status
  • /target clear

Active target state is persisted per chat session under ~/.config/opencode/rexd-target/sessions/ and refreshed during normal remote use, so active chats are not pruned as stale.

Updating (existing users)

Update in this order:

  1. Update rexd on remote target hosts.
  2. Update this plugin locally.
  3. Restart OpenCode.
  4. Reconnect in each chat with /target use <alias>.

Update commands:

# 1) remote hosts
curl -fsSL https://raw.githubusercontent.com/samiralibabic/rexd/main/scripts/install.sh | REXD_VERSION=v0.1.4 bash

# 2) local plugin
curl -fsSL https://raw.githubusercontent.com/samiralibabic/opencode-rexd-target/main/scripts/install.sh | OPENCODE_REXD_TARGET_VERSION=v0.3.1 bash

If you update the plugin before rexd, remote edit/apply_patch calls can fail with method-not-found errors on older servers.

If your repo still has an old .opencode/rexd-state.json from previous versions, it can be removed.

Note: this plugin now preserves OpenCode UI metadata for edit and apply_patch so TUI diff rendering works the same way as native tools.

As of v0.2.5, plugin bash results also mirror output into metadata.output so OpenCode's Bash tool panel reliably shows command body output.

Troubleshooting

  • Bash tool shows header but no body output:
    • Update to v0.2.5 or newer.
    • Restart OpenCode after installing.
    • If needed, clear/reselect target with /target clear then /target use <alias>.

Development

make typecheck
make build

Open-source docs

  • License: LICENSE
  • Contributing: CONTRIBUTING.md
  • Code of conduct: CODE_OF_CONDUCT.md
  • Security policy: SECURITY.md

About

OpenCode plugin routing tools to remote REXD targets over SSH with local fallback. REXD: https://github.com/samiralibabic/rexd

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors