Summary
The shared worktree helper (plugins/source-control/scripts/worktree-create.sh, added in #399) resolves the fresh base ref by probing refs/remotes/origin/HEAD only. In a repo cloned with a non-origin default remote (e.g. git clone -o upstream), upstream/HEAD may be correctly cached but origin/HEAD is absent, so --base-ref fresh falls back to local HEAD (with a warning) and a worktree created from a feature branch carries unpushed/local commits into a supposedly-fresh worktree.
Not a regression (context)
This is a pre-existing, shared limitation, not something #399 introduced: Claude Code's own native fresh resolution is also origin-centric (per https://code.claude.com/docs/en/worktrees it keeps origin/HEAD current). #399 preserved that same origin-centric behavior for the interactive path and added a loud stderr warning on the HEAD fallback, so the failure is visible rather than silent. This issue tracks closing the gap properly.
Proposed fix
Before falling back to HEAD, resolve the repo's effective default remote generically:
- the current branch's configured remote (
git config branch.<name>.remote), then
origin if it exists, then
- the sole remote if there is exactly one.
Probe refs/remotes/<remote>/HEAD for that remote. Keep the HEAD fallback + warning only when no remote default can be resolved.
Acceptance
Source
Raised by a Codex review thread on #898 (PR for #399, Phase A).
Summary
The shared worktree helper (
plugins/source-control/scripts/worktree-create.sh, added in #399) resolves thefreshbase ref by probingrefs/remotes/origin/HEADonly. In a repo cloned with a non-origindefault remote (e.g.git clone -o upstream),upstream/HEADmay be correctly cached butorigin/HEADis absent, so--base-ref freshfalls back to localHEAD(with a warning) and a worktree created from a feature branch carries unpushed/local commits into a supposedly-fresh worktree.Not a regression (context)
This is a pre-existing, shared limitation, not something #399 introduced: Claude Code's own native
freshresolution is also origin-centric (per https://code.claude.com/docs/en/worktrees it keepsorigin/HEADcurrent). #399 preserved that same origin-centric behavior for the interactive path and added a loud stderr warning on the HEAD fallback, so the failure is visible rather than silent. This issue tracks closing the gap properly.Proposed fix
Before falling back to
HEAD, resolve the repo's effective default remote generically:git config branch.<name>.remote), thenoriginif it exists, thenProbe
refs/remotes/<remote>/HEADfor that remote. Keep theHEADfallback + warning only when no remote default can be resolved.Acceptance
--base-ref freshin a-o upstreamclone bases the worktree onupstream's default branch, not localHEAD.origin.HEADfallback + warning remains for the genuinely-remoteless case.Source
Raised by a Codex review thread on #898 (PR for #399, Phase A).