Skip to content

#752 Create worktrees from the apps - #788

Merged
ivanfenenko merged 9 commits into
mainfrom
feature/752-create-worktrees
Oct 22, 2026
Merged

ivanfenenko merged 9 commits into
mainfrom
feature/752-create-worktrees

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Create a git worktree from the phone on opencode v1 and v2, on iOS and Android:

  • Hold New session → Run in → "New worktree…" (last row) creates a worktree, then starts the session there. Run in now opens for every project while Worktrees is on, not only multi-worktree ones, so a single-checkout project can reach it.
  • Session Chat ⋯ → Move to worktree → "New worktree…" (last row) creates a worktree from the session's checkout, then moves the session into it (v2). On v1 the Move entry stays visible but disabled ("Needs an opencode v2 server"). The Move entry is now enabled for a single-checkout project when a worktree can be created.
  • Form (design-system components): a name prefilled with a random slug, a branch and a base.
    • v1 (POST /experimental/worktree) always creates branch opencode/<name> from the current checkout, so both fields are read-only with a note.
    • v2 (POST /api/worktree) only takes a start ref: the checkout is detached ("No branch (detached)"), and the base comes from /api/vcs/branch.
    • Errors and validation show inline and keep the values. The apps always show the name, branch and directory the server returns.
  • Never hidden: the row is disabled with a reason for non-git projects, the global project, Worktrees off, or a v1 server without the route.
  • Refresh: Home rows, the dock, Run in and the Session Chat header pick up the new checkout (v2 refetch plus worktree.updated; v1 reload of the project's list).
  • iOS fix found during the real-app run: moving a chat opened by New session created a second, empty session in the destination, because the view model was rebuilt with the optimistic placeholder id. It now rebinds with the created session's id.
  • Shorter read-only notes, so they fit one subtitle line on iPhone.

Checks

  • Android: ./gradlew :app:testDebugUnitTest :app:assembleDebug: 2635 tests, 0 failures (1 skipped), build OK.
  • iOS: full OpenCode MobileTests target, UI tests skipped: 2582 tests in 251 suites passed.
  • New unit tests on both platforms:
    • v1 and v2 request mapping and responses, error-message extraction, v1 404.
    • Repository routing.
    • Form state, validation and base selection.
    • Create → start and create → move flows; a failed create starts nothing.
    • Availability order for both rows and the Move entry.
    • Hold on a single-checkout project.
    • iOS move rebinding.
  • Real-app evidence against real opencode v1 1.19.1 and v2 dev (cold restarts), checked with git worktree list (table below, also on Create worktrees from the apps #752).

Issue

#752. Worktree removal and naming a branch on v2 remain open on the issue.

Risks / Follow-ups

  • v2 cannot name a branch: the server runs git worktree add --detach, and no v2 endpoint creates a branch. The form says so. This is recorded on Create worktrees from the apps #752.
  • Hold behaviour change (Worktrees setting and a collapsible project picker #785): with Worktrees on, a hold on New session always opens Run in, also for a non-git project, where "New worktree…" is disabled with a reason.
  • Small platform difference: a v2 project without a project ID shows "Needs a git repository with a commit" on iOS and "Needs a git repository" on Android. Android adds HomeProject.hasVcs for the no-commit case.
  • Not checked on device: Worktrees off, an inline server error, tablet/split layouts and dark mode (unit tests cover the first two).

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.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith with what you need.

ivanfenenko and others added 9 commits October 22, 2026 16:35
…ository

v2 POST /api/worktree (projectID, from, name, optional branch) and
GET /api/vcs/branch; v1 POST /experimental/worktree?directory= with the
name. The repository routes by protocol, keeps the server's words for
errors, and treats a v1 404 as a server that cannot create worktrees.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
WorktreeCreateModel holds one immutable form state (prefilled name,
validation, read-only branch, v2 base list, submit and error) shared by
the Run in and Move sheets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hold on New session opens Run in whenever Worktrees is on, so a
single-checkout project reaches New worktree…. Run in creates, refreshes
the project's checkouts and starts a session there; Move creates from the
session's checkout and moves the session. Move to worktree… is enabled
for a single checkout when a worktree can be created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
v2 POST /api/worktree (projectID, from, name, optional branch) and
GET /api/vcs/branch for base refs; v1 POST /experimental/worktree with
the server's answered name and branch. A v1 404 marks the server as
unable to create until the connection changes. Errors use the server's
message, else the plain body, else the HTTP status.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
WorktreeCreateForm holds one immutable form state (name, v1 branch,
v2 base list, submit, error) with explicit actions, shared by Run in
and Move. NewWorktreeAvailability orders the disabled reasons for both
rows. HomeProject keeps hasVcs so a git folder without a commit says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Hold on New session (or a hold pick) opens Run in whenever Worktrees is
on, also for one checkout, with "New worktree…" after the checkouts.
The form replaces the list in the same sheet; a create lists the new
checkout on Home and starts a session there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Move sheet ends with "New worktree…": create a checkout from the
session's one, then move there. Move to worktree… is enabled for a
single-checkout project while a worktree can be created. Home relists
the project's worktrees after the create.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The read-only branch and base notes, the Move row subtitle and the
unsupported-server reason were cut off on iPhone list rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Session Chat opened by New session (or Run in → New worktree) keeps the
optimistic placeholder as its route id. On session.moved the view model was
rebuilt with that placeholder, which created a second, empty session in the
destination worktree. Rebind with the id the server gave the created session.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ivanfenenko ivanfenenko mentioned this pull request Oct 22, 2026
9 of 11 tasks
@ivanfenenko
ivanfenenko merged commit 4dde2cd into main Oct 22, 2026
@ivanfenenko
ivanfenenko deleted the feature/752-create-worktrees branch October 22, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant