feat: add native OpenCode V2 plugin support - #3
Open
pascalandr wants to merge 5 commits into
Open
Conversation
V2 host uses @opencode-ai/client Promise API (0.0.0-beta-17595+) and a single global daemon instead of per-workspace runtimes. This plugin requires no runtime change: the Bun.serve proxy already binds an ephemeral port and reuses a healthy sibling on OPENCODE_CLAUDE_PROXY_PORT, so it coexists with the global service. Registration stays plugin field in opencode.json. Add optional peer @opencode-ai/client >=0.0.0-beta-17595, document no packages/opencode-plugin (deleted in CodeNomad MIGRATION_V2.md), and note CodeNomad V2 quota now surfaces Claude OAuth usage via api.anthropic.com/api/oauth/usage (e2b784f2).
OpenCode V2 requires the new Plugin.define entrypoint and registration APIs, while this package still implements the V1 hook contract. Remove the unrelated optional client peer and the claims that daemon and proxy behavior make the existing plugin compatible. Document the current V1-only requirement so users are not directed to install a package that V2 cannot load. The existing V1 runtime remains unchanged. Validated with bun run build. The smoke script still fails on Windows at its Unix executable fixture in test/smoke.ts:236, which is unrelated to this documentation and manifest correction.
Add a real V2 server plugin entrypoint while preserving the existing V1 root export. The V2 plugin starts the Claude proxy, contributes the claude-code provider and model catalog through native transforms, registers the official Claude CLI sign-in relay, and rewrites native model requests with live proxy, effort, session, model, and project-directory context. Pin @opencode-ai/plugin to the target 0.0.0-beta-17595 release and use its versioned V1 type export for the legacy entrypoint. V2 stores only a non-secret connection marker because its integration contract requires a credential record; Claude Code continues to own and refresh the actual subscription credentials. Add a mocked V2 context test covering catalog, integration, hook registration, routing, and cleanup. Validate TypeScript build and no-emit checking plus fresh packed-package imports for both root and ./server; the legacy smoke script retains its pre-existing Windows fake executable failure at test/smoke.ts:236.
Depend on the beta dist-tag instead of a numbered prerelease and regenerate the Bun lockfile. Keep the OpenCode V1 type contract through a stable-major npm alias because the current beta no longer exports its V1 compatibility path. Expose the V1 handler from the server entrypoint for loaders that prefer package server exports, while retaining the native V2 id/setup plugin and its catalog, integration, request-hook, and proxy behavior. Document the explicit V2 server-file configuration required while the package root remains V1-compatible. Validated with build, no-emit typecheck, focused V2 tests, packed root/server imports, an isolated current opencode2 loader smoke covering plugin/catalog/integration/provider/proxy state, and a current V1 model-catalog smoke. The full suite still reaches the existing Windows extensionless fixture failure in test/smoke.ts.
Keep the V2 server export limited to the Plugin.define contract so OpenCode does not classify it as a legacy server plugin. Register the provider with its authentication integration and document normal package installation instead of requiring a dist/server.js path. The focused V2 test now prevents the legacy server property from returning.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds native OpenCode V2 compatibility while preserving the OpenCode V1 root entrypoint.
@opencode-ai/pluginthrough the publishedbetadist-tagPlugin.define({ id, setup })V2./serverexportclaude-codeprovider and six Claude models with effort variantsConfiguration
{ "$schema": "https://opencode.ai/config.json", "plugins": ["@openchamber/opencode-claude"], "providers": { "claude-code": { "name": "Claude Code" } } }The package root remains the V1 entrypoint. OpenCode V2 package installation selects
./server; that export intentionally has no legacyserverproperty, preventing the V2 loader from classifying it as a V1 plugin.Verification
bun run buildbunx tsc -p tsconfig.json --noEmitnpm pack --dry-run./serverimportsLimitations
test/smoke.ts:236.betadist-tag require the same build and runtime validation.