spawn_task should auto-add .claude/worktrees/ to .git/info/exclude in version-controlled repos
When spawn_task (or the broader Claude Code worktree mechanism) creates a worktree at .claude/worktrees/<name> inside a directory that is under git version control, the worktree directory shows up as an untracked submodule-shaped entry in git status and git add -A warnings. This appears to surprise every user the first time they hit it, and the natural fix — adding .claude/worktrees/ (or .claude/) to the committed .gitignore — is the wrong fix:
git worktree addrefuses to operate inside an ignored path. Committing the rule breaks the worktree mechanism for everyone who clones the repo, not just the user who added the rule.- The trap is recursive: a Claude Code session running
git add -Asees the warning, "fixes" it by editing.gitignore, the user merges, and the next clone of the repo can no longer usespawn_task. - I've had this happen across at least four sessions. I assumed it would have been auto-resolved by now in an update. It hasn't been.
The right local fix is .git/info/exclude — same syntax as .gitignore, but lives inside .git/ and is never committed. Each clone has its own ignore list.
Suggested fix
When spawn_task (or whatever orchestrates git worktree add) creates a worktree inside a git-tracked repo, it should detect that and append .claude/worktrees/ to .git/info/exclude (idempotently — only if the line isn't already there). That way:
- The worktree directory stops showing as untracked locally.
- No committed file is touched.
git worktree addcontinues to work because the ignore is local-only.- Users (and Claude sessions) stop reaching for the wrong
.gitignorefix.
Repro
cdinto any git-tracked repo.- Trigger a
spawn_taskchip (creates a worktree at.claude/worktrees/<name>). - Run
git statusorgit add -A— observe the embedded-submodule warning. - The natural "add to .gitignore" fix breaks
git worktree addgoing forward for the repo.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗