dsh-opencode-go-proxy: Providing a reverse proxy for local OpenCode Go within DSH

Introduction

When integrating OpenCode Go into DSH, clients often cannot “directly connect” to the upstream: requests must include session and client-related headers specified by OpenCode, otherwise the upstream will reject them or behave abnormally. A common practice is to run a local reverse proxy script separately, manually inject headers, and then modify the baseURL in the model configuration. @wjj-8283/dsh-opencode-go-proxy package this logic as a DSH plugin: it attaches to the profile’s webserver when dsh starts (or shares the port with DSH), forwards requests to the OpenCode Go upstream, and adds the required headers before sending. The following sections explain what it is, how to install it, and how to connect it to DSH’s model settings.

What is this

Maintainer wjj-8283 published wjj-8283/dsh-opencode-go-proxy on GitHub, categorized as a Networking Tool in the community catalog. The plugin’s positioning is: Local OpenCode Go reverse proxy—it automatically attaches the reverse proxy to DSH’s own webserver when dsh starts (sharing the port with DSH), forwards to https://opencode.ai by default, and injects x-opencode-session, x-opencode-request, x-opencode-client, x-opencode-project, and a User-Agent compliant with OpenCode requirements before forwarding.

Implementation-wise, it’s a modification of the opencode-go-proxy-win script in the repository: the top-level startup of opencode-go-proxy.mjs was changed to an importable proxy.js; the original opencode-go-proxy-start-minimal.bat was changed to be automatically launched by the plugin’s apply when dsh starts; the stopping method changed from manual Ctrl+C to automatic shutdown when the dsh application is uninstalled. Package name: @wjj-8283/dsh-opencode-go-proxy, version 0.1.0, license MIT, runtime requirement: Node.js >= 22.

Core Features

  1. Automatic bundle loading: Inserts the host Loader via dsh.bundle.patch and cordis.patch.yml. After installation into a profile, it enters dsh.profile.bundles and is automatically loaded the next time dsh starts with that profile.
  2. Webserver mode (default): The reverse proxy is mounted under the profile webserver’s prefix path (default /api/opencode-proxy/v1). Clients just point baseURL to this path, no need to remember a second port (port follows each profile’s webserver, e.g., web defaults to 3080, qq defaults to 3220).
  3. Path mapping: The path after the mount prefix is mapped back to the upstream API root (default upstreamBasePath=/zen/go/v1). For example, .../api/opencode-proxy/v1/responses is forwarded to https://opencode.ai/zen/go/v1/responses; if the stripped path already contains the upstreamBasePath prefix, it won’t be doubled (idempotent).
  4. Authentication and header injection: Forward Authorization as-is; API Key is still sent by the client via environment variables (e.g., OC_GO_API_KEY). The proxy side adds OpenCode session/request headers and replaces the User-Agent.
  5. Standalone mode (optional): When there’s no webserver or you need an independent port, it can listen on the default 8787, with client baseURL as http://127.0.0.1:8787.
  6. Status check: In webserver mode, access GET /api/opencode-proxy/status through the profile’s webserver.

Installation and Activation

The plugin is a bundle, requiring a local path to be installed into a specific profile (replace the path with your local clone or downloaded directory, as shown in the README example below):

dsh plugin --profile web add /Users/wjj/repos/dsh/opencode-go-proxy-plugin
dsh plugin --profile qq  add /Users/wjj/repos/dsh/opencode-go-proxy-plugin

After installation into the profile, it will be automatically loaded the next time you start with dsh --profile <name>. If you modify the plugin source code, you need to restart the dsh process for the corresponding profile (e.g., restart dsh web for the web profile) to switch from the old behavior to the webserver mount address.

Typical Usage

Client baseURL (Default webserver mode)

The reverse proxy shares the port with DSH’s webserver. Simply point the OpenCode Go client or DSH provider’s baseURL to the mount prefix:

  • web profile: http://127.0.0.1:3080/api/opencode-proxy/v1
  • qq profile: http://127.0.0.1:3220/api/opencode-proxy/v1

Connecting to DSH Model Settings

In DSH’s llm-pi-ai.providers, change the baseURL of the OpenCode Go provider (example name oc-go) from direct connection to proxy address. Direct connection example:

oc-go:
  displayName: OpenCode Go
  apiKeyEnv: OC_GO_API_KEY
  api: openai-responses
  baseURL: https://opencode.ai/zen/go/v1   # originally direct connection
  reasoning: high
  models: [...]

Taking the web profile as an example, change to use the proxy:

oc-go:
  displayName: OpenCode Go
  apiKeyEnv: OC_GO_API_KEY
  api: openai-responses
  baseURL: http://127.0.0.1:3080/api/opencode-proxy/v1   # changed to proxy address
  reasoning: high
  models: [...]

Notes:

  • Only affects providers configured with oc-go, doesn’t change other default models (e.g., configurations where agent-default-model is still deepseek-official are unaffected).
  • If a session needs to use OpenCode, set the session or global default model to oc-go and the specific model (e.g., muse-spark-1.2-contributor).
  • The proxy must be running on that profile’s webserver; after modifying the plugin for the web profile, restart dsh web to use 3080/api/opencode-proxy/v1 instead of the old standalone 8787 method.

Optional standalone

Set mode to standalone in settings, then use port (default 8787) to start an independent service. Clients use:

http://127.0.0.1:8787

Configuration Options

The settings namespace is dsh-opencode-go-proxy:

Configuration Default Value Description
enabled true Start immediately upon launch
mode webserver webserver (mount to DSH webserver prefix) or standalone (independent port)
mountPath /api/opencode-proxy/v1 Mount prefix in webserver mode
upstreamBasePath /zen/go/v1 Real API root mapped to upstream (idempotent stacking)
port 8787 Listening port in standalone mode
upstreamHost opencode.ai Upstream host
upstreamProto https Upstream protocol
opencodeUa opencode/1.18.29 cli Injected User-Agent

Environment variables PROXY_PORT, UPSTREAM_HOST, UPSTREAM_PROTO, UPSTREAM_PORT, OPENCODE_UA serve as fallbacks only when the corresponding settings are not set.

Use Cases and Considerations

Who it’s for: Developers who already use or plan to use OpenCode Go (openai-responses, etc.) in DSH, need to uniformly inject OpenCode request headers locally, and don’t want to maintain separate bat/mjs startup scripts long-term.

Permissions and Security: The plugin runs with the current dsh process permissions and forwards requests containing API Keys to the configured upstream. Before installation, you should read the repository source code and the MIT license to confirm that the upstream and mount paths comply with your environment policies. The community catalog SkillHub Plugin Page and GitHub repository are independent of each other and are not official DeepSeek/Magic Data application stores; DSH ecosystem emphasizes “everything is a plugin”, and the catalog site is maintained by the community.

Dependencies: Requires Node.js 22+; default upstream is https://opencode.ai, host/proto can be adjusted via settings or environment variables.

Conclusion

dsh-opencode-go-proxy brings the local reverse proxy required by OpenCode Go into the DSH lifecycle: by default it shares the same port as the profile webserver, changing one line in the provider’s baseURL switches from direct connection to local proxy, and automatically handles OpenCode headers and User-Agent. For further details, refer to the repository README.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye