You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Right now, plugins are completely blind to worktree operations (create, remove, reset). Because these operations only emit directly to GlobalBus instead of going through Bus.publish(), they successfully reach SSE clients and the TUI, but entirely bypass plugin subscriptions.
This creates a few major roadblocks for plugin authors:
Leaked external resources: If a plugin spins up a dev server, Docker container, or DB branch for a worktree, it has no signal to tear it down when the worktree is removed (or provision it on create).
Stale cache data: Plugins that maintain local state per worktree (like indexed context or build artifacts) end up holding onto dead data because they don't know when a worktree is deleted or hard-reset.
Proposed events
Three new events emitted via Bus.publish() so they reach both plugins (via Bus.subscribeAll) and existing SSE/TUI consumers (via GlobalBus):
Event
Payload
When
worktree.created
{ info: { name, branch, directory } }
After git worktree add and sandbox registration succeed, before async bootstrap
worktree.removed
{ directory }
After worktree directory cleanup and branch deletion
worktree.reset
{ directory }
After git reset --hard, git clean, and submodule update complete
Reacted by Michael Lyon, Guillem Puche and Mike Wyatt
Use case: session.created provisions a Postgres database and MinIO bucket scoped to the worktree's branch slug; worktree.removed would tear them down.
One specific ask on the payload: the current proposal has worktree.removed: { directory } firing after directory cleanup. Our teardown script calls git -C $directory rev-parse --abbrev-ref HEAD to get the branch name — that fails once the directory is gone. Either include branch in the payload (same as worktree.created) or fire before directory cleanup. Either change makes the hook usable for external resource teardown without requiring the branch name to be encoded in the directory path.
Filed #33332 proposing a worktree.create.before hook that would complement the worktree.created/removed/reset events suggested here.
The before hook closes the loop for cases where the post-hoc events arrive too late — e.g. when a plugin wants to redirect the storage path, change the base ref, or override the auto-generated opencode/<adj-noun> branch name. By the time worktree.created would fire, an Instance is already bound to the directory (packages/opencode/src/worktree/index.ts:375), so post-hoc relocation is racy.
Both hook sets address the same root cause (plugins blind to worktree lifecycle) from opposite ends — happy to consolidate into one issue if maintainers prefer.
Something like docker compose down would be nice, but not sure it would work with the proposed workspace.removed, since it would need the directory to still exist.
Activity
guillempuche commentedon Jun 20, 2026
Use case:
session.createdprovisions a Postgres database and MinIO bucket scoped to the worktree's branch slug;worktree.removedwould tear them down.One specific ask on the payload: the current proposal has
worktree.removed: { directory }firing after directory cleanup. Our teardown script callsgit -C $directory rev-parse --abbrev-ref HEADto get the branch name — that fails once the directory is gone. Either includebranchin the payload (same asworktree.created) or fire before directory cleanup. Either change makes the hook usable for external resource teardown without requiring the branch name to be encoded in the directory path.Reference:
worktree-up.sh·worktree-down.shStephanMeijer commentedon Jun 22, 2026
Filed #33332 proposing a
worktree.create.beforehook that would complement theworktree.created/removed/resetevents suggested here.The
beforehook closes the loop for cases where the post-hoc events arrive too late — e.g. when a plugin wants to redirect the storage path, change the base ref, or override the auto-generatedopencode/<adj-noun>branch name. By the timeworktree.createdwould fire, anInstanceis already bound to the directory (packages/opencode/src/worktree/index.ts:375), so post-hoc relocation is racy.Both hook sets address the same root cause (plugins blind to worktree lifecycle) from opposite ends — happy to consolidate into one issue if maintainers prefer.
mikew commentedon Jun 29, 2026
Something like
docker compose downwould be nice, but not sure it would work with the proposedworkspace.removed, since it would need the directory to still exist.github-actions commentedon Aug 29, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.