OpenCode plugin for fast, safe git worktree workflows.
bun add open-trees
Add the plugin to your OpenCode config (usually ~/.config/opencode/opencode.json):
{
"plugin": ["open-trees"]
}
Or run the helper CLI:
bunx open-trees add
For local development, build the plugin and point OpenCode at the local package:
bun install
bun run build
{
"plugin": ["/absolute/path/to/open-trees"]
}
Worktree tools are gated behind worktree mode so they do not clutter the default tool list. Enable it when you want to work with worktrees, then disable it when you are done.
worktree_mode { "action": "on" }
worktree_mode { "action": "off" }
worktree_mode also prints a help sheet with examples and defaults.
worktree_mode — enable/disable worktree mode and show help.worktree_overview — list, status, or dashboard worktrees.worktree_make — create/open/fork worktrees and sessions.worktree_cleanup — remove or prune worktrees safely.Enable worktree mode:
worktree_mode { "action": "on" }
List worktrees:
worktree_overview
Status for all worktrees:
worktree_overview { "view": "status" }
Show the worktree/session dashboard:
worktree_overview { "view": "dashboard" }
Create a worktree (branch derived from name):
worktree_make { "action": "create", "name": "feature audit" }
Start a new session (creates or reuses a worktree):
worktree_make { "action": "start", "name": "feature audit", "openSessions": true }
Open a session in an existing worktree:
worktree_make { "action": "open", "pathOrBranch": "feature/audit", "openSessions": true }
Fork the current session into a worktree:
worktree_make { "action": "fork", "name": "feature audit", "openSessions": true }
Create a swarm of worktrees/sessions:
worktree_make { "action": "swarm", "tasks": ["refactor-auth", "docs-refresh"], "openSessions": true }
Remove a worktree:
worktree_cleanup { "action": "remove", "pathOrBranch": "feature/audit" }
Prune stale worktree entries:
worktree_cleanup { "action": "prune", "dryRun": true }
path is omitted):<repo>/.worktrees/<branch>path inputs are resolved under .worktrees/ to prevent traversal.name when branch is omitted (lowercased, spaces to -).worktree_cleanup refuses to delete dirty worktrees unless force: true.worktree_make actions (start, open, fork) create or reuse a worktree, then create a session in that directory.
Each action records a mapping entry at:
~/.config/opencode/open-trees/state.json (or ${XDG_CONFIG_HOME}/opencode/open-trees/state.json)The session title defaults to wt:<branch>, and the output includes the session ID plus next steps.
Swarm safety notes:
worktree_make with action: "swarm" refuses to reuse existing branches or paths unless force: true.Optional command file examples:
# .opencode/command/worktree-start.md
worktree_make { "action": "start", "name": "$1", "openSessions": true }
# .opencode/command/worktree-open.md
worktree_make { "action": "open", "pathOrBranch": "$1", "openSessions": true }
Slash commands (drop these files into .opencode/command):
/worktree-on
/worktree-overview
/worktree-make <name>
/worktree-clean <pathOrBranch>
E2E tests exercise the CLI against a temporary OpenCode config file.
bun run lint
bun run typecheck
bun run build
bun run test
bun run test:e2e
bun pm scan
npm audit --omit=dev
Open Trees follows Semantic Versioning and tracks notable changes in CHANGELOG.md.
See CONTRIBUTING.md for setup, testing, and release guidelines.
$ claude mcp add open-trees \
-- python -m otcore.mcp_server <graph>