Repository navigation
Closed
Labels
Description
Create a git worktree from the phone, then start a session in it or move the current session into it, on opencode v1 and v2 servers.
Why
Home groups worktrees under one project (#780), Session Chat can move a session to another worktree (#785), but the apps cannot create one. Starting an isolated task from the phone without touching the main checkout is a natural mobile flow. The web app creates worktrees when starting a session (packages/app/src/workspaces/create.ts).
Scope
- Session Chat ⋯ → Move to worktree → "New worktree…": the last row of the Move sheet (Worktrees setting and a collapsible project picker #785). It creates a worktree from the session's current checkout, then moves the session into it.
- Hold New session → Run in → "New worktree…": the last row of the Run in list. It creates a worktree, then starts the new session there. Run in is offered for every git project while Worktrees is on (not only multi-worktree projects), so the row is reachable from a single-checkout project.
- Create form (design-system components, component-first): a name prefilled with a short random slug; a new branch name; a base to create from, defaulting to the source checkout's branch. Fields a protocol cannot honour stay visible but read-only with an explanation (below).
- Never hide controls by state: disabled with an explanation for non-git projects, the global project, or when Settings → Home → Worktrees is off. On v1 the Move sheet's "New worktree…" stays visible but disabled ("Needs an opencode v2 server"), like the Move entry itself.
- Refresh: the worktree inventory, Home grouping, scope picker and Session Chat header pick up the new worktree via
worktree.updated(v2) and a refetch after the create call (v1 and v2). - Errors (name taken, git failure, not a git project) show inline in the form; the form keeps its values.
Upstream API
v2 (opencode packages/protocol/src/groups/worktree.ts, packages/core/src/worktree.ts):
POST /api/worktreebody{ projectID, from?, branch?, name?, directory? }→{ directory }.fromis a known checkout of the project (default: main checkout).nameis the folder name (default: random slug; an existing folder gets-2…-10).branchis only the start ref: the git strategy runsgit worktree add --detach -- <dir> <branch ?? HEAD>. The new checkout has no branch, and no v2 endpoint creates one (/api/vcshas init, get, base, status, branch list, diff only). So on v2 the form creates a detached checkout and shows the folder name; the branch field says so.GET /api/vcs/branch?directory=(local and remote branches) for the base picker;GET /api/vcs?directory=for the current branch (answers empty right after a server restart).- Errors: 400
WorktreeError {data:{message}},ProjectNotFoundError. - Event:
worktree.updated {projectID}. DELETE /api/worktree {projectID, directory, force}(removal, not in this pass).
v1 (v1.19.3 packages/opencode/src/server/routes/instance/httpapi/groups/experimental.ts, src/worktree/index.ts):
POST /experimental/worktree?directory=<project>body{ name?, startCommand? }→{ name, branch, directory }.- Always creates branch
opencode/<slug(name)>from the currentHEADof the project's checkout (git worktree add --no-checkout -b), then populates it in the background (worktree.ready/worktree.failed). No base or branch choice: the form shows both read-only. A taken name gets a random suffix instead of an error. - Errors: 400
WorktreeErrorWorktreeNotGitError/WorktreeCreateFailedError/WorktreeNameGenerationFailedError. - v1 has no session move endpoint.
Acceptance criteria
- Run in → "New worktree…" creates a worktree and starts a session in it (v1 and v2)
- Move to worktree → "New worktree…" creates a worktree from the session's checkout and moves the session into it (v2); disabled with an explanation on v1
- Create form: prefilled name, branch and base fields with per-protocol read-only explanations, inline errors that keep the values
- Disabled with an explanation for non-git projects, the global project, and Worktrees off
- Home grouping, scope picker and Session Chat header show the new worktree without a manual refresh
- iOS and Android
Remaining
- iOS
- Android
- Real-app evidence on v1 and v2 (both platforms)
- Remove a worktree from Home (confirm, force when dirty) — not part of the creation PR
- v2: create a named branch for a new worktree once the server can (today it is always detached)
PR: #788 (creation, both platforms). Evidence: comment below.
App files
- Android:
data/remote/WorktreesApi.kt,domain/worktree/*,ui/main/SessionListHomeChrome.kt,ui/main/MainScreen.kt,ui/sessionchat/region/SessionChatWorktreeMove.kt - iOS:
Data/Remote/WorktreesAPIClient.swift,Domain/Worktree/*,UI/Main/SessionListHomeChrome.swift,UI/Main/ProjectListHomeView.swift,UI/SessionChat/SessionChatMoveToWorktree.swift
Activity
[-]Create and remove worktrees (v2)[/-][+]Create worktrees from the apps[/+]ivanfenenko commentedon Oct 22, 2026
Real-app evidence: create worktrees (iOS + Android, opencode v1 + v2)
Real apps against the scenario harness: real
opencode servev1 1.19.1 and v2dev4d5965762e, throwaway git projectacme-invoices, harness data only. The v2 runs started right after a server restart (cold/api/vcs). Each worktree was checked with git afterwards.opencode/<name>and base read-only; v2 "No branch (detached)" with a base picker from/api/vcs/branchopencode/gentle-meadowtidy-lynx(baseopencode/lucky-panda)opencode/lucky-pandazesty-falcon(baseopencode/gentle-meadow)brave-pebble→zesty-cometzesty-falcon→tidy-panda/project)Git after the runs (full output): v1 checkouts are on branches
opencode/gentle-meadowandopencode/lucky-panda; the six v2 checkouts are(detached HEAD), as the v2 API does.Found and fixed during the run (iOS): moving a chat opened by New session (e.g. right after Run in → New worktree) created a second, empty session in the destination, because the view model was rebuilt with the optimistic placeholder id. Fixed in this PR; the rerun shows only
POST …/movethen…/view.Android
iOS
* Taken before the read-only notes were shortened (they were cut off at one line on iPhone); the later shots show the final copy.
Not checked on device: Worktrees setting off, a server error shown inline (e.g. a bad base ref), tablet/split layouts, dark mode. These are covered by unit tests or unchanged.
#752 Create worktrees from the apps (#788)
ivanfenenko commentedon Oct 25, 2026
Shipped in #788 (merged as 4dde2cd): worktrees can be created from the apps on iOS and Android, v1 and v2.
Out of scope for this issue and left unticked: