by kdcokenny
Zero-friction git worktrees for OpenCode. Auto-spawns terminals, syncs files, cleans up on exit.
# Add to your Claude Code skills
git clone https://github.com/kdcokenny/opencode-worktreeGit worktrees that spawn their own terminal. Zero-friction isolation for AI-driven development.
An OpenCode plugin that creates isolated git worktrees—where each worktree automatically opens its own terminal with OpenCode running inside. No manual setup, no context switching, no cleanup work.
You already know you can create git worktrees manually. Or use OpenCode Desktop's UI. So why this plugin?
Manual worktrees require setup: create the worktree, open a terminal, navigate to it, start OpenCode. OpenCode Desktop gives you worktrees, but locks you into the GUI workflow. Each approach has friction.
This plugin eliminates that friction. When the AI calls worktree_create, your terminal spawns automatically, OpenCode is already running, and files are synchronized. When it calls worktree_delete, changes commit automatically and the worktree cleans itself up. It's the difference between having a tool and having a workflow.
Works great standalone, but pairs especially well with cmux for agentic workflows. cmux provides native workspace management and programmatic control that fits naturally into automated development workflows. tmux is also supported if you prefer a traditional multiplexer setup.
| Approach | Best For | Tradeoffs | |----------|----------|-----------| | Manual git worktree | One-off experiments, full control | Manual setup, no auto-cleanup, context switching | | OpenCode Desktop UI | Visual workflow, integrated experience | Tied to desktop app, less automation | | This plugin | AI-driven workflows, automation, CLI-first users | Adds plugin dependency to your project |
No comments yet. Be the first to share your thoughts!
If you prefer manual control or work exclusively in OpenCode Desktop, you may not need this. But if you want AI agents to seamlessly create and manage isolated development sessions—complete with automatic terminal spawning and state cleanup—this is what you're looking for.
flowchart LR
A[Create Worktree] --> B{Terminal Spawns}
B --> C[OpenCode Running]
C --> D[Work in Isolation]
D --> E[Delete Worktree]
E --> F{Auto-commit & Cleanup}
F --> G[Session Ends]
worktree_create("feature/dark-mode")~/.local/share/opencode/worktree/<project-id>/feature/dark-modeworktree_delete("reason")Worktrees are stored in ~/.local/share/opencode/worktree/<project-id>/<branch>/ outside your repository.
ocx add kdco/worktree --from https://registry.kdco.dev
If you don't have OCX installed, install it from the OCX repository.
Optional: Install kdco-workspace for the full experience—it bundles worktrees with background agents, planning tools, and notifications:
ocx add kdco/workspace --from https://registry.kdco.dev
The plugin adds two tools:
| Tool | Purpose |
|------|---------|
| worktree_create(branch, baseBranch?) | Create a new git worktree for isolated development. A new terminal spawns with OpenCode ready. |
| worktree_delete(reason) | Delete the current worktree. Changes commit automatically before removal. |
worktree_create:
branch: "feature/dark-mode"
baseBranch: "main" # optional, defaults to HEAD
When called, this:
~/.local/share/opencode/worktree/<project-id>/feature/dark-mode.opencode/worktree.jsonc configpnpm install)worktree_delete:
reason: "Feature complete, merging to main"
When called, this:
docker compose down)--forceThe plugin detects your terminal automatically:
| Platform | Terminals Supported |
|----------|---------------------|
| macOS | Ghostty, iTerm2, Kitty, WezTerm, Alacritty, Warp, Terminal.app |
| Linux | Kitty, WezTerm, Alacritty, Ghostty, Foot, GNOME Terminal, Konsole, XFCE4 Terminal, xterm |
| Windows | Windows Terminal (wt.exe), cmd.exe fallback |
| cmux | Uses native cmux workflow when CMUX_WORKSPACE_ID is present or socket control is explicitly enabled (CMUX_SOCKET_PATH + CMUX_SOCKET_MODE=allowAll); each worktree launch opens a new cmux workspace and falls back safely when unavailable |
| tmux | Creates new tmux window (supported on all platforms) |
| WSL | Windows Terminal via wt.exe interop |
CMUX_WORKSPACE_ID or explicit socket control (CMUX_SOCKET_PATH with CMUX_SOCKET_MODE=allowAll). Worktree launches always create a new cmux workspace (no current-workspace reuse), then fall back safely when cmux context is unavailable.TERM_PROGRAM, KITTY_WINDOW_ID, GHOSTTY_RESOURCES_DIR, etc.Auto-creates .opencode/worktree.jsonc on first use:
{
"$schema": "https://registry.kdco.dev/schemas/worktree.json",
"sync": {
// Files to copy from main worktree
"copyFiles": [],
// Directories to symlink
"symlinkDirs": [],
// Patterns to exclude
"exclude": []
},
"hooks": {
// Run after creation
"postCreate": [],
// Run before deletion
"preDelete": []
}
}
Node.js project:
{
"sync": {
"copyFiles": [".env", ".env.local"],
"symlinkDirs": ["node_modules"]
},
"hooks": {
"postCreate": ["pnpm install"]
}
}
Docker-based project:
{
"sync": {
"copyFiles": [".env"]
},
"hooks": {
"postCreate": ["docker compose up -d"],
"preDelete": ["docker compose down"]
}
}
Manual worktrees require manual setup: git worktree add, opening a terminal, navigating to it, starting OpenCode. Each step is friction. This plugin gives you a single command that handles everything end-to-end, complete with automatic file synchronization and lifecycle hooks.
Worktrees created with this plugin work fine in OpenCode Desktop, but you lose the automatic terminal spawning. The plugin's value is in CLI-first workflows and AI automation—if you prefer Desktop exclusively, you may not need this.
Changes remain in ~/.local/share/opencode/worktree/<project-id>/<branch>. The branch exists in git. You can manually check out or delete it later. The plugin doesn't force cleanup—it's just the convenient default path.
Yes. Each gets its own terminal and OpenCode session. They're fully independent.
No. It uses standard git worktrees. git worktree list shows them. Branches merge normally.
Isolation. You can close the worktree session without affecting your main workflow. If the AI breaks something, your original terminal remains untouched.
allow_remote_control config (falls back to window)Copy src/ to .opencode/plugin/. You lose OCX's dependency management and automatic updates.
Requirements:
jsonc-parserFrom the KDCO Registry. Combine with:
Inspired by opencode-worktree-session by Felix Anhalt.
This facade is maintained from the main OCX monorepo.
If you want to update opencode-worktree itself, start here:
https://github.com/kdcokenny/ocx/blob/main/workers/kdco-registry/files/plugins/worktree.ts
https://github.com/kdcokenny/ocx/tree/main/workers/kdco-registry/files/plugins/worktree
Open issues here: https://github.com/kdcokenny/ocx/issues/new
Open pull requests here: https://github.com/kdcokenny/ocx/compare
Please do not open issues or PRs in this facade repository.
This project is not built by the OpenCode team and is not affiliated with OpenCode in any way.
MIT