[Bug] `ocx opencode` injects nothing when an opencode v2 background service is already running

Open
#9,045 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript
Domain
cli

Research direction

Start in src/cli/opencode.ts at buildOpencodeEnv and the spawn(inv.file, inv.args, { env }) call around lines 696-704, then reproduce with the isolated XDG home in the report by starting an opencode background service before running ocx opencode debug config. Read how the launcher detects or connects to an existing service, and compare the --standalone and cold-autostart paths that already work. Done means a warm service either receives the generated provider.opencodex / providers.opencodex blocks or the launcher stops printing the success line and fails loudly; the fix approach still needs a maintainer decision.

Written by the indexing model from the issue text.

Description

bug cli
Client or integration

Other

Area

CLI

Summary

ocx opencode reports that it wired the proxy and injected its provider blocks, but when an
opencode v2 background service is already running, the launched instance never sees those
blocks. The launcher's only output is a success line, so the failure is silent: the models it
just advertised are absent from the running opencode.

--standalone, and a cold start where no service exists yet, both work.

Reproduction

Isolated home so the test cannot touch a real config; opencode v2.3.2:

export XDG_STATE_HOME=/tmp/ocx-bug1/state XDG_DATA_HOME=/tmp/ocx-bug1/data \
       XDG_CONFIG_HOME=/tmp/ocx-bug1/config XDG_CACHE_HOME=/tmp/ocx-bug1/cache
mkdir -p "$XDG_STATE_HOME" "$XDG_DATA_HOME" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"

# 1. Start the background service the way an earlier plain `opencode` run would.
opencode service set port 51177
opencode service start            # -> http://127.0.0.1:51177

# 2. Launch through the launcher against that warm service.
ocx opencode debug config > c.json
# stderr: "✅ opencode wired to http://127.0.0.1:10100/v1 — 3 model(s) under provider `opencodex`."

# 3. Look for the injected blocks in what the instance actually loaded.
python3 -c '
import json; d=json.load(open("c.json")); out=[]
for s in d:
    info=s.get("info") or {}
    for blk in ("provider","providers"):
        b=(info.get(blk) or {}).get("opencodex")
        if b: out.append((blk,len(b.get("models") or {})))
print("opencodex blocks visible:", out or "NONE")'
# -> opencodex blocks visible: NONE

Controls, same isolated home:

Scenario opencodex blocks loaded
Warm background service, then ocx opencode NONE
ocx opencode debug config --standalone providers, 3 models
Service stopped, then ocx opencode (cold autostart) providers, 3 models
Expected behavior

The launched opencode should load the generated provider.opencodex / providers.opencodex
blocks in every case, or the launcher should refuse to claim success when it cannot deliver them.

Observed behavior

With a warm service the blocks are dropped entirely, and the launcher still prints the success
line, so the user only finds out when the models are missing from the picker.

Likely cause

src/cli/opencode.ts builds the env and spawns opencode with it
(buildOpencodeEnv -> spawn(inv.file, inv.args, { env }), around line 696-704). That env reaches
the client process only. When an opencode v2 background service is already listening, the
client connects to that daemon and the daemon serves config it loaded when it started — before
any OPENCODE_CONFIG_CONTENT existed in its environment. opencode's own help describes
--standalone as "Run with a private server instead of the background service", which matches
the observed split.

What I ruled out

A restart-with-the-runtime-layer fix does not work, so it is not on the table. I started the
service with OPENCODE_CONFIG_CONTENT already set in its own environment, and the daemon still
loaded no opencodex blocks — the variable is not present in the daemon process at all. A
background service therefore cannot be told about the proxy by injection under any restarted
state, which leaves only genuinely different approaches.

Still open, and a maintainer's call: run a private server (--standalone) whenever a service is
warm, which guarantees the injected layer applies but gives up the shared session the service
provides; or make the launcher fail loudly instead of printing the success line when the blocks
cannot be applied; or write a static block through the managed integration path. Each has a real
cost, so this is a report rather than a proposal.

Workaround

A static exported block on disk is read by the service and does work:

ocx export --client opencode   # merge the two blocks into ~/.config/opencode/opencode.json

The catch is that export is a snapshot: it does not follow catalog or visibility changes.

Version

opencodex 2.100.8 (npm install). Also reproduced from a local dev checkout at 9e0e298e
(the current dev tip, package.json version 2.100.0, run as bun bin/ocx.mjs).

Operating system

macOS 27.2.0 (Darwin), Bun 1.4.4, opencode v2.3.2

Logs or error output
$ ocx opencode debug config
✅ opencode wired to http://127.0.0.1:10100/v1 — 3 model(s) under provider `opencodex`.
   Your existing opencode config files are left untouched; only the runtime provider blocks are injected.
RESULT opencodex blocks visible to the warm daemon: NONE
Checks
  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.
Dominant language
TypeScript
Stars
16.9k
Forks
1.3k
Avg merge
1d 4h
Merged PRs (30d)
814

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from lidge-jun/opencodex

All issues in lidge-jun/opencodex

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.