Skip to content

Isolated worktrees for write-capable /opencode:rescue #34

@JohnnyVicious

Description

@JohnnyVicious

Summary

Write-capable /opencode:rescue tasks currently operate directly in the user's current working tree. This can interleave OpenCode edits with the user's own uncommitted changes or with concurrent Claude Code edits.

There is an existing local issue about a worktree cleanup hang when a Claude subagent is itself isolated in a worktree (#16). This issue is separate: it tracks plugin-managed worktree isolation as a feature for safer write-capable OpenCode tasks.

Motivation

A plugin-managed worktree would help with:

  • protecting user WIP from OpenCode edits
  • allowing Claude and OpenCode to work concurrently without racing on the same files
  • reviewing OpenCode's diff before applying it to the main tree
  • discarding unwanted OpenCode changes cheaply

Proposed UX

Examples:

/opencode:rescue --worktree fix the failing parser tests
/opencode:rescue --background --worktree implement the migration script

Potential default: use worktree isolation automatically for background write-capable tasks.

Implementation sketch

  1. Create a temporary branch/worktree under a plugin-owned directory.
  2. Run opencode-companion task --write with cwd set to that worktree.
  3. On completion, store the worktree path, branch name, and diff in job data.
  4. Add follow-up commands or result guidance to apply, merge, or discard the changes.
  5. Ensure background workers do not run in Claude-managed worktrees that can be deleted before OpenCode finishes.

Upstream reference

Derived from openai/codex-plugin-cc#135.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions