Repository navigation
feat(plugin): route OpenCode 2 worktrees through wt switch and wt remove - #4489
Conversation
The OpenCode plugin now registers a `worktrunk` worktree strategy through `ctx.worktree.transform`, the OpenCode 2 counterpart of the Claude Code plugin's WorktreeCreate/WorktreeRemove hooks: - create: `wt switch [--create] <name> [--base <ref>] --no-cd --format=json` in the source checkout, where <name> is the basename of OpenCode's suggested directory and the returned path comes from `worktree-path`. An existing branch is reopened; a starting ref for one is refused. - remove: `wt remove --foreground [--force] <dir>`, a no-op once the checkout is gone. - list: `git worktree list --porcelain -z`, first record as root, skipping bare and prunable entries. Closes #4488
worktrunk-bot
left a comment
There was a problem hiding this comment.
Holding this for maintainer review because it adds a deletion path. The OpenCode plugin now runs wt remove --foreground [--force] <dir> whenever OpenCode removes a worktree. It does this for every OpenCode 2 user who has the plugin installed, with no opt-in. OpenCode's built-in git strategy only runs git worktree remove. wt remove also deletes the branch once it is integrated, and runs any approved pre-remove hooks. So removing a workspace in OpenCode now deletes more than it did before.
The force flag passes straight through to wt remove --force, which discards untracked files. A name that matches an existing branch reopens that branch's worktree. That worktree is then registered as OpenCode-managed and can be removed from OpenCode's UI. That matches the Claude Code WorktreeCreate hook and OpenCode's own list adoption, but it widens the same surface.
it runs with force? |
i.e. the standard one doesnt use force? |
|
Only when OpenCode passes OpenCode sets
So force is not where the deletion surface widens. What |
Under OpenCode 2, the plugin that
wt config plugins opencode installwrites now registers aworktrunkworktree strategy. Worktrees that OpenCode creates and removes then go throughwt switch --createandwt remove, the same way the Claude Code plugin'sWorktreeCreate/WorktreeRemovehooks already route them. This was requested in #4488. I ran the strategy locally against a scratch repo with this branch'swtand a fake OpenCode context. I haven't run it inside a real OpenCode 2 session, which CI can't drive.How each callback maps (
dev/opencode-plugin.ts):wt switch [--create] <name> [--base <ref>] --no-cd --format=jsonin the source checkout and returns.path. OpenCode'sbranchinput is a starting ref, not a branch name, so<name>is the basename of the directory OpenCode suggests (the name the user typed, or a generated slug). The path comes fromworktree-path, since OpenCode accepts a different directory than the one it suggested. An existing branch is reopened, as in fix(plugin): reopen an existing worktree from the WorktreeCreate hook #4487. Passing a starting ref for an existing branch is refused rather than ignored.wt remove --foreground [--force] <dir>. It does nothing if the checkout is already gone.git worktree list --porcelain -zand reports the first record asroot. Bare and prunable entries are skipped.Things a maintainer may want to weigh:
worktree.directorysetting stops applying. This matches the Claude Code plugin. The docs page says so.Worktree.OperationError(operationErrorusesinstanceof). A standalone plugin file can't import that class: the CLI's runtime shim for@opencode/plugindoesn't exportWorktree. A dirty removal fails with worktrunk's own message instead (Cannot remove worktree: … has uncommitted changes), and nothing is deleted.gitstrategy uses the source checkout's HEAD instead.Local check
A Node harness imported the plugin, called
setupwith a stubctx.worktree.transform, and ran each callback against a fresh repo withtarget/debug/wton PATH:ocrepo.brave-tiger(theworktree-pathdefault), andlistreturned root + that worktreebranch: "brave-tiger"→ a second worktree based on itforce→ removed. A repeat remove → no-oplist→ root onlytest_docs_are_in_syncand the 14opencodeintegration tests pass.Closes #4488