kdcokenny/opencode-worktree

Zero-friction git worktrees for OpenCode. Auto-spawns terminals, syncs files, cleans up on exit.

What it solves

It eliminates the friction of manually setting up isolated development environments. Instead of manually creating a git worktree, opening a terminal, navigating to the directory, and starting an AI coding tool, this plugin automates the entire lifecycle for AI-driven development.

How it works

The plugin provides two primary tools for an AI agent to call:

  1. worktree_create: Automatically creates a git worktree in a dedicated local directory, spawns a new terminal window (supporting a wide range of macOS, Linux, and Windows terminals), and launches OpenCode within that session.
  2. worktree_delete: Automatically commits any pending changes and removes the git worktree to clean up the environment.

It supports configuration via .opencode/worktree.jsonc to handle file synchronization (copying .env files or symlinking node_modules) and lifecycle hooks (running pnpm install after creation or docker compose down before deletion).

Who it’s for

CLI-first developers and AI agents that need to seamlessly create and manage isolated development sessions without manual context switching or cleanup.

Highlights

  • Automatic Terminal Spawning: Detects and opens compatible terminals (including Ghostty, iTerm2, Kitty, and Windows Terminal) or integrates with multiplexers like tmux and cmux.
  • Zero-Friction Isolation: Allows AI agents to experiment in isolated branches without affecting the main workspace.
  • Customizable Lifecycle: Supports pre-delete and post-create hooks for environment setup and teardown.
  • Integrated File Sync: Automatically handles the transfer of necessary configuration files and directories between the main project and the worktree.

Related

  • Project
  • Project
  • Project
  • Project
  • Project