Skip to content

[FEATURE]: Expose worktree lifecycle events (created, removed, reset) to plugins #15680

Closed as not planned

Description

@kldzj

Feature hasn't been suggested before.

  • 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

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Mar 2, 2026
  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 2, 2026
  3. assigned and unassigned on Apr 26, 2026
  4. removed
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  5. guillempuche commented on Jun 20, 2026

    @guillempuche

    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.

    Reference: worktree-up.sh · worktree-down.sh

  6. StephanMeijer commented on Jun 22, 2026

    @StephanMeijer

    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.

  7. mikew commented on Jun 29, 2026

    @mikew

    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.

  8. github-actions commented on Aug 29, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions