Skip to content

fix(opencode): use ~/.config/opencode for plugin path on macOS - #2655

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-2654
May 10, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/issue-2654

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

wt config plugins opencode install writes the plugin to ~/Library/Application Support/opencode/plugins/worktrunk.ts on macOS, while OpenCode itself looks for user plugins under ~/.config/opencode/ (the macOS Library path is its managed settings directory). Reported in #2654.

The bug came from opencode_plugins_dir() falling back to dirs::config_dir(), which is platform-native (~/Library/Application Support on macOS, %AppData%\Roaming on Windows). The function's own docstring already claimed it wrote to ~/.config/opencode/plugins/, and the CLI help text in src/cli/config.rs says the same — only the runtime disagreed on macOS.

Solution

Mirror OpenCode's documented global-config precedence directly:

$OPENCODE_CONFIG_DIR > $XDG_CONFIG_HOME/opencode > ~/.config/opencode

Linux behaviour is unchanged (the prior dirs::config_dir() fallback already produced $XDG_CONFIG_HOME/.config there). macOS now lands at ~/.config/opencode/plugins/worktrunk.ts, matching the docs and the help text.

Testing

Two tests cover the regression cross-platform — previously the only fallback test was gated #[cfg(target_os = "linux")] because the path differed by OS, which is exactly what hid the bug:

  • test_opencode_install_uses_xdg_config_home — un-gated and renamed; asserts XDG_CONFIG_HOME/opencode/plugins/worktrunk.ts on every OS.
  • test_opencode_install_defaults_to_home_dot_config — new; clears both OPENCODE_CONFIG_DIR and XDG_CONFIG_HOME and asserts $HOME/.config/opencode/plugins/worktrunk.ts.

Both pass locally on Linux. The macOS leg of CI is the meaningful gate — under the prior implementation, both would have failed there.


Closes #2654 — automated triage

`opencode_plugins_dir()` previously fell back to `dirs::config_dir()`,
which on macOS returns `~/Library/Application Support`. OpenCode itself
treats that path as the *managed* settings directory and looks for user
plugins under `~/.config/opencode/` on every OS, so the plugin landed in
the wrong place on macOS — its in-code docstring already claimed it was
written to `~/.config/opencode/plugins/`, but the runtime disagreed.

Mirror OpenCode's documented global-config precedence instead:
`$OPENCODE_CONFIG_DIR` > `$XDG_CONFIG_HOME/opencode` > `~/.config/opencode`.
The Linux behaviour is unchanged; macOS now matches the docs and the
existing CLI help text.

Closes #2654

Co-Authored-By: Claude <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the precedence claim against OpenCode's source — xdg-basedir resolves xdgConfig to $XDG_CONFIG_HOME then ~/.config, so OPENCODE_CONFIG_DIR > XDG_CONFIG_HOME/opencode > ~/.config/opencode matches what OpenCode actually does. Tests pass locally on Linux; the macOS leg in CI is the meaningful gate.

One observation outside the diff: now that XDG_CONFIG_HOME is a documented step in the precedence chain, the help text in src/cli/config.rs (lines 170-171 and 259) still names only OPENCODE_CONFIG_DIR as the override. A user who has XDG_CONFIG_HOME=/custom/path will see the plugin land at /custom/path/opencode/plugins/worktrunk.ts, not ~/.config/opencode/plugins/worktrunk.ts as the help text suggests. Happy to push a small follow-up that mirrors the opencode_plugins_dir doc-comment in the help text — leaving it out here since the help wasn't strictly accurate before either and an in-PR update would also need a separate snapshot pass.

@max-sixty

Copy link
Copy Markdown
Owner

yes please adjust

also: check whether there's a more opencode-native approach to installing; I'm surprised we're building a full emulation of their paths

The install path now follows OpenCode's documented config precedence
(OPENCODE_CONFIG_DIR > XDG_CONFIG_HOME/opencode > ~/.config/opencode),
but the help text still named only OPENCODE_CONFIG_DIR. A user with
XDG_CONFIG_HOME set saw the plugin land somewhere other than the help
text suggested.
@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Pushed the help-text adjustment in 9bd5931 — both wt config plugins opencode --help and the install subcommand help now name the full precedence chain.

On the "more native" question — OpenCode supports two install paths in its plugin docs, plus a dedicated CLI:

  1. TS file in plugins/ (what we do today). First-class loader: config/plugin.ts scans {plugin,plugins}/*.{ts,js} from each config dir.
  2. plugin array in opencode.json — accepts npm package names, file:// URLs, or relative paths.
  3. opencode plugin <module> (alias plug) — installs an npm spec via Bun, reads its manifest, patches it into opencode.json. Source: cli/cmd/plug.ts.

Re "full emulation": after this PR the resolver reads OPENCODE_CONFIG_DIR > XDG_CONFIG_HOME/opencode > ~/.config/opencode, which is exactly what OpenCode's loader does on every platform — three env-var checks, no platform-specific paths. The emulation was the old code: dirs::config_dir() is what returned ~/Library/Application Support on macOS and caused #2654. Today we're at 13 lines of resolver plus an include_str! of a 28-line TS file (dev/opencode-plugin.ts).

Alternatives, with trade-offs:

  • Publish @worktrunk/opencode-plugin to npm and replace handle_opencode_install with a hint pointing users at opencode plugin @worktrunk/opencode-plugin --global. Most native, but adds an npm package to maintain (plugin version pinned separately from wt) and a Bun install on first opencode startup. Heavy for a 28-line plugin that's tightly coupled to wt's CLI surface.
  • Write a file:// entry into ~/.config/opencode/opencode.json's plugin array. Same file write, but registered explicitly. Trades directory resolution for JSONC patching of a config file we don't own.

My read: install path #1 is itself one of OpenCode's two documented options, and the directory math now matches their precedence exactly, so the bug shape from #2654 is gone. Happy to prototype the npm route in a separate PR if you want to evaluate it concretely.

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help-text update in 9bd5931 covers the XDG_CONFIG_HOME gap I flagged earlier. Tests were already green; codecov/patch passes. No new code-level issues.

On the maintainer's "more opencode-native approach" question, I went looking for alternatives:

OpenCode exposes two install paths beyond "drop a file in the plugins dir":

  • The opencode plugin <module> CLI (docs) — <module> is an npm package name (with --global and --force flags); no local-file mode is documented.
  • The "plugin": ["pkg-name"] array in opencode.json (docs) — also npm packages, auto-installed by Bun at startup.

Both require the plugin to be on npm. Today the plugin is a 28-line local TypeScript file embedded via include_str!, so neither fits without a publishing pipeline (npm package version sync, breakage when the binary and the published plugin drift, etc.). For local plugins, OpenCode's documented install method is dropping the file in …/opencode/plugins/, so what we're doing isn't a parallel scheme — we're writing into OpenCode's own loader path.

That said, the precedence chain isn't extra emulation: it's matching what OpenCode itself reads. Trimming any branch breaks the install for the corresponding user:

  • Drop OPENCODE_CONFIG_DIR → users with that env set get the plugin written somewhere OpenCode won't load.
  • Drop XDG_CONFIG_HOME → same outcome for users who customize XDG.

The genuinely native alternative is publish the plugin as @worktrunk/opencode-plugin (or similar) and have wt config plugins opencode install shell out to opencode plugin @worktrunk/opencode-plugin --global (or just edit opencode.json to add it). OpenCode then handles its own paths and updates. The cost is a separate npm release pipeline and version-pinning the plugin against the binary version. Given the plugin is 28 lines and rarely changes, I'd lean toward keeping the embedded-file approach and the path mirror this PR adds — but flagging the trade-off so you can call it.

@max-sixty

Copy link
Copy Markdown
Owner

@tend-agent please review these workflows; it's overly repetitive

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Diagnosed: two workflows fired on your earlier comment and both answered the "more opencode-native approach" question.

  • tend-mention handled the comment directly — pushed 9bd59311 and posted this reply at 19:37 with the full OpenCode-install-paths analysis.
  • tend-review fired independently on the resulting synchronize and posted this review at 19:42 that re-stated the same analysis in the body.

The bundled review skill already says "check whether a bot reply exists after the question's timestamp before answering", but the 19:42 run treated your question as still-open and re-answered it. Existing guidance is also scoped to inline comments ("cross-reference previous bot comments before posting inline comments") — the duplication here was in the review body, which the rule doesn't explicitly cover.

I'll open a follow-up PR adding a cross-workflow dedup rule to .claude/skills/running-tend/SKILL.md: when tend-mention has already replied to a question, tend-review should leave that analysis out of the review body and stick to the diff. The bundled review skill probably wants the same tightening; happy to file an upstream issue if you want.

@tend-agent

Copy link
Copy Markdown

Confirmed the diagnosis from the tend side and filed max-sixty/tend#400 to track the bundled-skill fix. The near-miss rule in plugins/tend-ci-runner/skills/review/SKILL.md is scoped to inline comments and to prior reviews — neither covered the body-level duplication with the sibling tend-mention reply. The repo-local overlay PR @worktrunk-bot is opening is still useful as a near-term guard; the bundled fix follows in tend.

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

The repo-local overlay is already up at #2656; with tend#400 covering the bundled fix, no separate upstream issue from my side is needed. Closing the loop on this thread.

@max-sixty

Copy link
Copy Markdown
Owner

merging this, we can consider whether to make more "native" later

@max-sixty
max-sixty merged commit 9af258d into main May 10, 2026
33 checks passed
@max-sixty
max-sixty deleted the fix/issue-2654 branch May 10, 2026 05:54
@worktrunk-bot worktrunk-bot mentioned this pull request May 10, 2026
3 tasks done
max-sixty added a commit to max-sixty/tend that referenced this pull request May 10, 2026
…rlap (#403)

The dedup rule at `plugins/tend-ci-runner/skills/review/SKILL.md:89` was
scoped to inline comments and review-to-review overlap, missing the case
where `tend-mention` answers a maintainer question and `tend-review`
then re-answers it in the **review body** on the resulting `synchronize`
event. Surfaced on
[worktrunk#2655](max-sixty/worktrunk#2655) per
#400.

Two changes:

- **`running-in-ci` — Recheck Before Posting** is restructured to name
two duplication paths explicitly: (1) new entries arriving during the
session, and (2) a sibling tend workflow having already responded before
the session even started. The rule applies equally to comment bodies,
review bodies, and inline replies.
- **`review` skill** drops the inline-only / review-to-review scoping
and defers to the running-in-ci rule, listing the workflow sources it
covers (previous review on this or earlier commit, `tend-mention`,
`tend-triage`, any tend workflow). The race-condition guidance and the
"use the review body, not `gh pr comment`" guidance are preserved.

The fetch in step 1 of the review skill (lines 60–66) already pulls
`conversation` comments alongside `prev_reviews`, so no new data is
needed — only the consume-step rule was too narrow.

The event-pair-specific subsection ("Dedup check for inline review
comment replies") is left in place — it covers a different concern
(`pull_request_review` ↔ `pull_request_review_comment` race), not
content overlap.

Closes #400

Co-authored-by: Claude <[email protected]>
max-sixty added a commit that referenced this pull request May 10, 2026
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.

OpenCode plugin install path is set to 'managed'-level config path on macOS

3 participants