Repro
From the repo root on main:
$ wt session add main
Creating worktree: main
Error: Failed to create worktree: Preparing worktree (checking out 'main')
fatal: 'main' is already used by worktree at '/home/me/code/wt'
$ wt new main
Error: Failed to create worktree: Preparing worktree (checking out 'main')
fatal: 'main' is already used by worktree at '/home/me/code/wt'
Why it fails
Both commands shell out to git worktree add <path> main. Git refuses because main is already checked out at the repo root (the primary worktree). The error surfaces git's internal message rather than something wt-shaped.
Expected
The default branch is, by definition, already a "worktree" — it's the primary one. The commands should recognize this and reuse the existing primary worktree path instead of trying to create a duplicate:
wt session add main → add a tmux window/session pointing at the repo root.
wt new main → either drop into a shell at the repo root, or print a friendly hint pointing the user at the primary worktree.
Suggested fix
WorktreeManager::list_worktrees() already exposes the primary worktree as the entry with empty task_id (src/worktree_manager.rs:357-364). A small helper — "is this branch checked out at the primary worktree?" — lets both call sites short-circuit:
ensure_worktree_path (src/session_cmd.rs:132-155): if the requested name matches the primary worktree's branch, return repo.root instead of calling create_worktree.
cmd_new (src/main.rs:156-211): same check; reuse repo.root instead of creating.
Generalizes naturally to "any branch already checked out at the primary worktree," not just main/master.
Open question
wt session add main is a clear win — useful, and the current failure is git-shaped rather than wt-shaped.
wt new main is less obvious. wt new semantically creates a worktree, and elsewhere in the codebase the primary worktree is explicitly not a wt worktree (pick_worktree filters out empty task_id at src/main.rs:295-298; cmd_use rejects "main" at src/main.rs:412-414). One option is to replace the git error here with a friendlier wt-level error pointing the user at wt session add main or cd <repo-root>, rather than pretending main is a wt worktree. Open to either direction.
Repro
From the repo root on
main:Why it fails
Both commands shell out to
git worktree add <path> main. Git refuses becausemainis already checked out at the repo root (the primary worktree). The error surfaces git's internal message rather than somethingwt-shaped.Expected
The default branch is, by definition, already a "worktree" — it's the primary one. The commands should recognize this and reuse the existing primary worktree path instead of trying to create a duplicate:
wt session add main→ add a tmux window/session pointing at the repo root.wt new main→ either drop into a shell at the repo root, or print a friendly hint pointing the user at the primary worktree.Suggested fix
WorktreeManager::list_worktrees()already exposes the primary worktree as the entry with emptytask_id(src/worktree_manager.rs:357-364). A small helper — "is this branch checked out at the primary worktree?" — lets both call sites short-circuit:ensure_worktree_path(src/session_cmd.rs:132-155): if the requested name matches the primary worktree's branch, returnrepo.rootinstead of callingcreate_worktree.cmd_new(src/main.rs:156-211): same check; reuserepo.rootinstead of creating.Generalizes naturally to "any branch already checked out at the primary worktree," not just
main/master.Open question
wt session add mainis a clear win — useful, and the current failure is git-shaped rather than wt-shaped.wt new mainis less obvious.wt newsemantically creates a worktree, and elsewhere in the codebase the primary worktree is explicitly not a wt worktree (pick_worktreefilters out emptytask_idatsrc/main.rs:295-298;cmd_userejects"main"atsrc/main.rs:412-414). One option is to replace the git error here with a friendlier wt-level error pointing the user atwt session add mainorcd <repo-root>, rather than pretendingmainis a wt worktree. Open to either direction.