@ykaratkou/opencode-worktree
v0.1.0
Published
Git worktree plugin for opencode - creates isolated development environments with automatic terminal spawning
Readme
opencode-worktree
Git worktree plugin for opencode. Creates isolated git worktrees with automatic terminal spawning — so AI agents can work on multiple branches in parallel without interfering with each other.
Note: This is a copy of kdcokenny/opencode-worktree repackaged as a pure npm package, since the original is only installable via
ocx addwhich is no longer available.
Installation
bun install -g github:ykaratkou/opencode-worktreeThen add it to your opencode.json:
{
"plugins": ["@ykaratkou/opencode-worktree"]
}What it does
When an AI agent calls worktree_create:
- Creates a git worktree at
~/.local/share/opencode/worktree/{projectId}/{branch} - Copies/symlinks files from main worktree (configurable)
- Forks the current session (with plan and delegations)
- Opens a new terminal with OpenCode running in the worktree
When the agent calls worktree_delete:
- Runs pre-delete hooks
- Commits all changes with a snapshot message
- Removes the git worktree
- Cleans up the session
Tools provided
worktree_create
branch: string # Branch name (e.g., "feature/dark-mode")
baseBranch?: string # Base branch to create from (defaults to HEAD)worktree_delete
reason: string # Why the worktree is being deletedConfiguration
On first use, a config file is auto-created at .opencode/worktree.jsonc:
{
// Custom base path for worktree storage (supports ~)
// "worktreePath": "~/my-worktrees",
"sync": {
// Files to copy from main worktree
// "copyFiles": [".env", ".env.local"],
// Directories to symlink (saves disk space)
// "symlinkDirs": ["node_modules"],
"copyFiles": [],
"symlinkDirs": [],
"exclude": []
},
"hooks": {
// Commands run after worktree creation
// "postCreate": ["pnpm install"],
// Commands run before worktree deletion
// "preDelete": ["docker compose down"],
"postCreate": [],
"preDelete": []
}
}Terminal support
Automatically detects and uses:
- tmux (highest priority when inside a tmux session)
- cmux (agentic workflow multiplexer)
- macOS: Ghostty, iTerm2, Kitty, Alacritty, Warp, Terminal.app
- Linux: Kitty, WezTerm, Alacritty, Ghostty, Warp, Foot, GNOME Terminal, Konsole, XFCE4, xterm
- Windows: Windows Terminal (
wt.exe), cmd.exe
Requirements
- opencode with Bun runtime
- git
License
MIT
