You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenCode already has a mature worktree system — a full Worktree module, Desktop workspace UI, TUI slash commands via plugins, HTTP API endpoints, and .worktreeinclude support. However, it lacks a --worktree CLI flag that would let users start an isolated worktree session directly from the command line, similar to Claude Code's -w / --worktree flag.
Motivation
A --worktree CLI flag would enable:
One-shot isolated sessions: opencode --worktree fix-auth-bug — creates a worktree, opens a session inside it
PR workflow: opencode --worktree "#1234" — creates a worktree from a PR branch
CI/scripting: Non-interactive worktree creation for automation
Quick context switching: Spin up parallel isolated environments from the terminal without opening the Desktop app
Proposed Behavior
Based on the existing spec (commit 55b19fe on a fork) and Claude Code's model:
opencode --worktree <name> # create with custom name
opencode --worktree "#1234" # PR mode — create from PR
opencode --worktree # auto-generate random name
Suggested defaults:
Storage location: .opencode/worktrees/<name>/ (repo-local) or keep existing ~/.local/share/opencode/worktree/<project-id>/ (global)
Branch naming: worktree-<name> or opencode/<name> (configurable?)
Base ref: origin/HEAD (remote default) with optional config
Session ID auto-bound to worktree name (mutually exclusive with --session)
Related Precedent
The Desktop app already supports workspace (worktree) creation via right-click -> Enable Workspaces
Community plugins exist for CLI-like workflows (DanHenton/opencode-worktree, sven1103/opencode-worktree-workflow, stephengolub/opencode-workspaces) — but none can add a true CLI flag due to plugin API limitations
A detailed spec was drafted at obukhovaa/opencode commit 55b19fe but never merged
This issue is specifically about the CLI integration layer — the yargs flag parsing, session-to-worktree binding, and PR mode. The config knobs in #33332 and #14032 are prerequisites for a polished implementation but not the same request.
Feature hasn't been suggested before.
Summary
OpenCode already has a mature worktree system — a full
Worktreemodule, Desktop workspace UI, TUI slash commands via plugins, HTTP API endpoints, and.worktreeincludesupport. However, it lacks a--worktreeCLI flag that would let users start an isolated worktree session directly from the command line, similar to Claude Code's-w/--worktreeflag.Motivation
A
--worktreeCLI flag would enable:opencode --worktree fix-auth-bug— creates a worktree, opens a session inside itopencode --worktree "#1234"— creates a worktree from a PR branchProposed Behavior
Based on the existing spec (commit
55b19feon a fork) and Claude Code's model:Suggested defaults:
.opencode/worktrees/<name>/(repo-local) or keep existing~/.local/share/opencode/worktree/<project-id>/(global)worktree-<name>oropencode/<name>(configurable?)origin/HEAD(remote default) with optional config--session)Related Precedent
obukhovaa/opencodecommit55b19febut never merged.worktreeincludesupport was added in PR feat(worktree): add .worktreeinclude support for copying gitignored files to new worktrees #25379 (May 2026)Plugin Limitation
Plugins cannot register CLI flags — the yargs CLI is hardcoded. This must be implemented as a core PR in
packages/opencode/src/cli/cmd/.Existing Infrastructure
The plumbing already exists:
packages/opencode/src/worktree/index.ts—Worktree.create(),Worktree.remove(),Worktree.list(),Worktree.reset()packages/opencode/src/control-plane/adapters/worktree.ts—WorktreeAdapterimplements the genericWorkspaceAdapterinterfacePOST /worktree,GET /worktree,DELETE /worktreeThe missing piece is just the CLI integration layer.
Related Issues
--worktreeto trigger worktree creation from the command line. They are complementary — if [FEATURE]: Configurable worktree creation — base ref, branch naming, repo-relative path #33332 is implemented,--worktreeshould respect those config settings.--worktreeflag could respect whatever storage path is configured.This issue is specifically about the CLI integration layer — the yargs flag parsing, session-to-worktree binding, and PR mode. The config knobs in #33332 and #14032 are prerequisites for a polished implementation but not the same request.