[BUG] Desktop app: enabling the worktree checkbox resets the base branch to "main", ignoring the repo's default branch (origin/HEAD → dev)

Status Open
Reported on v2.1.174
Maintainer reply None cached
Activity 1 comment · opened Jul 23, 2026

Bug Description

In the desktop app's Code tab, the new-session bar shows: Local | <project> | <branch> | [ ] worktree. While the worktree checkbox is unchecked, the branch chip correctly shows the repo's current branch (dev). The moment the checkbox is enabled, the chip switches to main — even though this repo's default branch is dev both on the remote and in every local git pointer. The spawned session then creates its worktree from main.

For repos whose default branch is not main (common GitLab flow: dev is the integration branch), every worktree session silently starts from an older branch, and work lands on top of stale code.

Steps to reproduce

  1. Use a repo whose default branch is dev (self-hosted GitLab here):
  • git ls-remote --symref origin HEADref: refs/heads/dev
  • local refs/remotes/origin/HEADrefs/remotes/origin/dev
  • currently checked-out branch: dev
  1. Desktop app → Code tab → select this project. The branch chip shows dev.
  2. Enable the worktree checkbox.
  3. The chip flips to main; a spawned session creates its worktree from main.

Expected behavior

The worktree base should be the repo's default branch resolved from refs/remotes/origin/HEAD (→ dev), consistent with the CLI's own default-branch resolution, which reads origin/HEAD and only falls back to main/master when it is absent.

What I ruled out

  • Server and local git state are correct (origin/HEADdev); verified again after a full quit + relaunch of the app — the chip still flips to main.
  • The worktree.baseRef setting has no effect on this UI path (it governs --worktree / agent isolation).
  • No stale client state: localStorage only persists the checkbox itself (persisted.cc-landing-worktree-enabled); there is no branch value in IndexedDB, ~/.claude.json, or session persistence.
  • The desktop main-process git resolvers do read refs/remotes/origin/HEAD correctly and would return dev; the spawn request already arrives with an explicit sourceBranch. So the literal main appears to originate in the landing/renderer layer, not in main-process git logic.

Workaround

A WorktreeCreate hook that creates the worktree from dev and prints its path — the hook path bypasses the UI-chosen base entirely.

Environment

  • Claude desktop app 1.24012.1, macOS 26.4.1 (arm64)
  • Claude Code CLI 2.1.174
  • Repo: self-hosted GitLab, default branch dev

Related: #54945 (same reset-to-default in the TUI worktree dialog, closed), #79515 (same "Branch to start from" control, different bug).

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗