GeezerVison is showing github.com — Create worktrees from the apps · Issue #752 · opencode-mobile/opencode-mobile
Create worktrees from the apps #752DescriptionCreate 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/worktree body { projectID, from?, branch?, name?, directory? } → { directory }. from is a known checkout of the project (default: main checkout). name is the folder name (default: random slug; an existing folder gets -2…-10).
branch is only the start ref: the git strategy runs git worktree add --detach -- <dir> <branch ?? HEAD>. The new checkout has no branch, and no v2 endpoint creates one (/api/vcs has 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 current HEAD of 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
WorktreeError WorktreeNotGitError / 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
Activitychanged the title [-]Create and remove worktrees (v2)[/-] [+]Create worktrees from the apps[/+] on Oct 22, 2026ivanfenenko commented on Oct 22, 2026 CollaboratorAuthor More actions Real-app evidence: create worktrees (iOS + Android, opencode v1 + v2)
Real apps against the scenario harness: real opencode serve v1 1.19.1 and v2 dev 4d5965762e, throwaway git project acme-invoices, harness data only. The v2 runs started right after a server restart (cold /api/vcs). Each worktree was checked with git afterwards.
| Check |
iOS v1 |
iOS v2 |
Android v1 |
Android v2 |
| Hold New session → Run in lists checkouts, then New worktree… last (also for a single-checkout project) |
✅ |
✅ |
✅ |
✅ |
Form: prefilled name; v1 branch opencode/<name> and base read-only; v2 "No branch (detached)" with a base picker from /api/vcs/branch |
✅ |
✅ |
✅ |
✅ |
| Create and start → real worktree and a session in it |
✅ opencode/gentle-meadow |
✅ tidy-lynx (base opencode/lucky-panda) |
✅ opencode/lucky-panda |
✅ zesty-falcon (base opencode/gentle-meadow) |
| Home rows, dock and Run in list the new checkout without a manual refresh |
✅ |
✅ |
✅ |
✅ |
| Move to worktree → New worktree… → Create and move (server session location = new dir) |
disabled: "Needs an opencode v2 server" ✅ |
✅ brave-pebble → zesty-comet |
disabled: "Needs an opencode v2 server" ✅ |
✅ zesty-falcon → tidy-panda |
| Non-git project: New worktree… disabled "Needs a git repository" |
✅ (/ project) |
unit tests |
unit tests |
unit tests |
| Invalid name → inline error, Create disabled, value kept |
unit tests |
unit tests |
✅ |
unit tests |
Git after the runs (full output): v1 checkouts are on branches opencode/gentle-meadow and opencode/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 …/move then …/view.
Android
| Run in (v1) |
Form (v1) |
Invalid name |
Session in new worktree |
Home after |
Run in after |
 |
 |
 |
 |
 |
 |
| v1: Move disabled |
Form (v2) |
Base picker |
Base picked |
Started (v2) |
Move sheet |
Move form |
Moved |
 |
 |
 |
 |
 |
 |
 |
 |
iOS
| Run in (v1) |
Form (v1)* |
Started (v1) |
Non-git disabled |
v1: Move disabled |
 |
 |
 |
 |
 |
| Run in (v2) |
Form (v2) |
Base picker |
Started (v2) |
Move sheet |
Move form |
Moved |
 |
 |
 |
 |
 |
 |
 |
* 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. ivanfenenko commented on Oct 25, 2026 CollaboratorAuthor More actions 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:
- Removing a worktree from Home (confirm, force when dirty)
- v2: creating a named branch for a new worktree, which is blocked until the server supports it (new worktrees are detached today)
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|