Repository navigation
Description
Found during graph-2026-10-freeze-c planning (Phase 0 of node C); not a graph node.
It lands after freeze-c node C, which edits the same script's branch-start logic and adds a parity test beside it.
Problem
When the issue's local branch feature/<N>-<slug> exists but no worktree has it checked out, the two worktree producers disagree:
templates/scripts/new-feature.sh:159-177(scripts/new-feature.shis a symlink to it) prints advice and exits 1. The advice is eithergit worktree add <path> <branch>orgit branch -D <branch>. The second one deletes the branch's commits.ensureWorktree(src/lib/workflow/worktree-manager.ts:1249-1253) runsgit worktree add <path> <branch>and reuses the branch.
This state is common. sequant run removes a clean worktree at shutdown and keeps the branch (docs/reference/abort-command.md:45). git worktree remove does the same. The next standalone /exec, /fullsolve or /testgen on that issue goes through the script and stops.
Reproduced 2026-10-17 (main @ de03af8, git 2.47.1, bash). The setup:
- a bare origin with
main, and a clone; - a local
feature/77-add-widgetwith one commit (7684edd feat: widget), its worktree removed; ghstubbed to return the titleadd widget.
PATH=<stub>:$PATH bash templates/scripts/new-feature.sh 77 printed:
⚠️ Branch feature/77-add-widget already exists
❌ Branch exists but no worktree found
To create worktree from existing branch:
git worktree add ../worktrees/feature/77-add-widget feature/77-add-widget
Or delete the branch first:
git branch -D feature/77-add-widget
It exited 1. On the same repo, ensureWorktree(77, "add widget", true) created ../worktrees/feature/77-add-widget at 7684edd [feature/77-add-widget] and returned existed: false.
Acceptance Criteria
- AC-1: When the issue's local branch exists and no worktree has it checked out,
scripts/new-feature.sh <N>creates the worktree on that branch and exits 0. The worktree HEAD equals the branch tip from before the run, and the branch is not created, reset or deleted. Evidence:npx vitest run __tests__/new-feature-existing-branch.integration.test.ts -t "local branch without a worktree"reports ≥ 1 passed, 0 failed. It drives the real script withghstubbed, asnew-feature-worktree-root.integration.test.tsdoes. Mutation-verified by restoring theexit 1advice branch. - AC-2: The script's result matches
ensureWorktree's existing-branch rule (worktree-manager.ts:1249-1253: check out the local branch as is) on three fixtures: a local-only branch, a local branch equal toorigin/<branch>, and a local branch behindorigin/<branch>. In each, the worktree HEAD is the local branch tip. Evidence:npx vitest run __tests__/new-feature-existing-branch.integration.test.ts -t "existing-branch parity"reports ≥ 3 passed, 0 failed, mutation-verified by making the script start fromorigin/<branch>when it exists (the behind fixture fails). - AC-3: The other two paths keep today's result. A branch already checked out in a worktree prints its path and exits 0. No local branch takes the creation path. Evidence:
npx vitest run __tests__/new-feature-existing-branch.integration.test.ts -t "worktree already checked out"reports ≥ 1 passed, 0 failed, andnpx vitest run __tests__/new-feature-worktree-root.integration.test.ts __tests__/new-feature-checkout-guard.integration.test.tsreports 0 failed.
Prior fixes / producers
-
Class: the script copies TS worktree logic by hand, and the copies drift. Six fixes so far, each closed by a parity or drift test (
git log --format='%h %ad %s' -- templates/scripts/new-feature.sh):- bd71d84 fix(worktree): new-feature.sh still uses
npm install, so provisioning dirties the lockfile (#816 gap) #826, 51fbfb1 new-feature.sh hardcodes npm ci while the TS path is package-manager aware — pnpm/yarn/bun provisioning fails misleadingly #847, 86eacbc PM_CONFIG.yarn.ciInstall uses Yarn 2+--immutable, which Yarn 1 rejects — no berry detection exists #871 (frozen install); - 8da00f6 fix(hooks): new-feature.sh bypasses the checkout guard — the script the block message recommends mutates the main checkout #910 (main checkout mutation);
- 9e435b1 bug(worktree): new-feature.sh and sequant run derive different branch names for the same issue #1145 (branch name;
src/lib/workflow/__tests__/new-feature-branch-parity.test.ts); - 4797ac8 feat(worktree): configurable worktree root #1199 (worktree root).
Freeze-c node C (fix(worktree): new-feature.sh cuts a new branch from the base when origin/<branch> already exists — #1405's fix never reached the script #1486) is the seventh: the start ref when only
origin/<branch>exists. This issue is the eighth. - bd71d84 fix(worktree): new-feature.sh still uses
-
This path:
git log -S 'Branch exists but no worktree found' -- templates/scripts/new-feature.shreturns only the script's creation and moves (0292c07, ba84547, 90607d2). It has never been fixed.gh issue list --state all --search '"no worktree found"'finds no issue. -
Producers of an issue worktree from an existing local branch: 2.
ensureWorktree'sbranchExistspath (TS, source of truth, unchanged) andnew-feature.sh'sshow-refblock. AC-2 states the outcome for both.
May touch
templates/scripts/new-feature.sh, __tests__/new-feature-existing-branch.integration.test.ts (new), docs/guides/git-workflows.md (### Script Usage, if the behaviour is described there), CHANGELOG.md.
Non-Goals
src/lib/workflow/worktree-manager.ts. The TS side is the source of truth and doesn't change.- Freshness of a reused branch (rebase or recreate when it is behind the base).
ensureWorktreedoes that only for an existing worktree (worktree-manager.ts:997-1093). - Branch-name derivation (bug(worktree): new-feature.sh and sequant run derive different branch names for the same issue #1145) and the start ref for a remote-only branch (freeze-c node C).
- The skill prose that calls the script, and any edit under
plugin/,.claude/skills/ortemplates/skills/(plugin freeze). - A release. Installed
scripts/dev/new-feature.shcopies get the fix with the first post-freeze release.
Activity
admarble commentedon Oct 18, 2026
Complexity: Standard (3 ACs, 3 directories)
AC Quality Check
All three ACs are single-line with
Evidence:clauses. Notes:__tests__/new-feature-existing-branch.integration.test.ts, which does not exist yet, so each fails today (not vacuous). AC-3's second command (new-feature-worktree-rootandnew-feature-checkout-guardtests) passes today by design (regression guard).-tdescribe names. Exec must uselocal branch without a worktree,existing-branch parity(3 cases) andworktree already checked out.show-refblock is now attemplates/scripts/new-feature.sh~L159, and theensureWorktreebranch-reuse is atworktree-manager.ts~L1380-1385 (git worktree add <path> <branch>). Behavior is unchanged.Scope Assessment
Non-Goals: present in the issue (TS side, freshness, branch naming, skills/plugin, release).
Verdict: ✅ SCOPE_OK. Blocker #1486 is CLOSED. No in-flight worktree touches
new-feature.sh.Acceptance Criteria
AC-1: Existing local branch, no worktree → worktree created, exit 0
Verification: Integration Test (real script,
ghstubbed)Scenario: Given local
feature/77-add-widgetwith one commit and no worktree → Whennew-feature.sh 77→ Then exit 0, worktree HEAD == prior branch tip, branch not recreated or reset.Assumptions: The fixture pattern from
new-feature-start-ref.integration.test.ts(bare origin, clone,ghstub) is reusable.AC-2: Parity with
ensureWorktreeon 3 fixturesVerification: Integration Test
Scenario: Given local-only / local == origin / local behind origin → When the script runs → Then worktree HEAD is the local tip in each (never
origin/<branch>).Assumptions: Behind fixture must be a true fast-forward-behind. This is the case where #1486's
-B origin/<branch>logic would wrongly win, so the existing-branch check has to run beforeresolve_branch_start_ref.AC-3: Other two paths unchanged
Verification: Integration Test
Scenario: Given branch checked out in a worktree → exit 0 and print the path. Given no local branch → creation path as before.
Implementation Plan
Phase 1: Script fix
templates/scripts/new-feature.shreplace theelseadvice branch (Branch exists but no worktree found+git branch -Dhint) withgit worktree add "$WORKTREE_DIR" "$BRANCH_NAME". Do not fetch, do not use-b/-B, and do not callresolve_branch_start_ref(matches TS: the local branch is checked out as is).sequantBaseconfig, env copy, install). Use no earlyexit, so the worktree gets the same setup as a fresh one. Keepbranch.<b>.sequantBase: set it only if unset, so a prior recorded base is not overwritten.git worktree list | grep "${BRANCH_NAME}". It is a substring match, sofeature/7-xwould matchfeature/7-xy. Prefergit worktree list --porcelainwith an exactbranch refs/heads/<b>match. This is the same class of fix, so keep it in the same file and cover it with a test, or record it as a follow-up if exec judges it out of scope.Phase 2: Tests and docs
__tests__/new-feature-existing-branch.integration.test.tswith the three describe blocks named above. The file name has.integration., so it gets the integration timeout.exit 1advice and confirm thelocal branch without a worktreetest fails. For AC-2, start fromorigin/<branch>and confirm the behind fixture fails. RecordMutation-verified:markers in the PR body using the test file path.docs/guides/git-workflows.md### Script Usageif it describes this case, and add aCHANGELOG.mdentry.Design Review
new-feature.sh's existing-branch block. The TS side (ensureWorktree) is the source of truth and does not change.git worktree add <dir> <branch>instead of printing advice. Rejected: auto-rebasing or freshening the branch (non-goal), and sharing code with TS (a bash script that also runs in non-Node repos).npm install, so provisioning dirties the lockfile (#816 gap) #826, new-feature.sh hardcodes npm ci while the TS path is package-manager aware — pnpm/yarn/bun provisioning fails misleadingly #847, PM_CONFIG.yarn.ciInstall uses Yarn 2+--immutable, which Yarn 1 rejects — no berry detection exists #871, fix(hooks): new-feature.sh bypasses the checkout guard — the script the block message recommends mutates the main checkout #910, bug(worktree): new-feature.sh and sequant run derive different branch names for the same issue #1145, feat(worktree): configurable worktree root #1199, fix(worktree): new-feature.sh cuts a new branch from the base when origin/<branch> already exists — #1405's fix never reached the script #1486). That is ≥2, so it is a class. The issue records the class and closes each fix with a parity test. AC-2 is that parity test. The class-level fix (a single producer) is out of scope for this issue and is already acknowledged in the issue's "Prior fixes" section. Not a divergence: the prescribed lever (the script) matches the review.ensureWorktreedoesn't either for a new worktree.ensureWorktreeandnew-feature.sh(2). Consumers:/exec,/fullsolve,/testgenstandalone. No other reference to the removed advice text; exec should grep the repo forBranch exists but no worktree foundbefore finishing, including docs and tests.Feature Quality Planning
All standard checks pass. Notable items:
set -ebehavior: thegit worktree addfailure path (e.g. the target dir already exists) should print a clear error rather than die silently.plugin/,.claude/skills/ortemplates/skills/edits (plugin freeze).Open Questions
Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Small bug fix to a single script. The ACs declare Evidence (integration tests) but the new test file is part of the fix itself, so testgen adds little for a
bug-only issue.Label Review
Current: bug
Recommended: bug, planned
Quality Loop: Won't auto-enable (SCOPE_OK, no complexity labels).
admarble commentedon Oct 18, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 3/3 met
Gaps:
Suggestions:
git worktree prune, the porcelain listing still shows its branch. The script then exits 0 and points at a directory that does not exist. The old grep behaved the same way.ensureWorktreeonly prunes on a retry. Worth a follow-up if it shows up in real use.chore(#1491): drop a stray blank line in new-feature.sh