Repository navigation
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before (this is distinct from [FEATURE]: Configurable worktree creation — base ref, branch naming, repo-relative path #33332 and [FEATURE]: configurable path for worktrees #14032 — see "Related Issues" below).
Summary
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>oropencode/<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/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 genericWorkspaceAdapterinterface- HTTP API:
POST /worktree,GET /worktree,DELETE /worktree - Desktop: full workspace management UI
The missing piece is just the CLI integration layer.
Related Issues
- [FEATURE]: Configurable worktree creation — base ref, branch naming, repo-relative path #33332 — Configurable worktree creation (base ref, branch naming, path). That issue is about making the existing worktree system configurable. This issue is about adding a new CLI flag
--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. - [FEATURE]: configurable path for worktrees #14032 — Configurable path for worktrees. Again complementary — the
--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.
Activity
github-actions commentedon Jul 5, 2026
This issue does not fully meet our contributing guidelines.
What needs to be fixed:
[FEATURE]:to match the feature request template (e.g.,[FEATURE]: --worktree / -w CLI flag for git worktree isolation)Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
--worktreeCLI flag behavior including storage location, base ref, and branch naming optionsIf you believe this was flagged incorrectly, please let a maintainer know.
[-]Feature Request: \--worktree\ / \-w\ CLI flag for git worktree isolation[/-][+][FEATURE]: \--worktree\ / \-w\ CLI flag for git worktree isolation[/+]github-actions commentedon Jul 5, 2026
Thanks for updating the issue! It now meets our contributing guidelines. We'll take a look at your feature request.
github-actions commentedon Sep 4, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.