[FEATURE] Change default worktree dir to `.git/tmp`
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
When using claude --worktree, the repo is placed in .git/worktrees. When finished with the work there, I merge those changes into the parent repo and close the worktree.
However, if you run git add . in the parent before the worktree is removed, git will add it as a sub repo, with all of the problems that carries with it.
Proposed Solution
Put the worktree folders in .git/tmp. git will ignore the child repo folder when performing operations on the parent.
This is how Git Subrepo operates, for a live example.
Alternative Solutions
Related to https://github.com/anthropics/claude-code/issues/27282. If worktree paths were configurable, I'd configure .git/tmp.
Priority
Low - Nice to have
Feature Category
CLI commands and flags
Use Case Example
claude -w some-featureclaude -w some-other-feature- Do some work in those folders that creates conflicts
- Merge
some-featureback into the parent repo, then delete the worktree - Merge of
some-other-featurefails because of conflicts. Resolve them. - Run
git add .to wrap up merge. some-other-featurerepo folder gets added as a sub repo...
If some-other-feature were in .git/tmp/some-other-feature, it would not be added.
Not a show-stopper, but I've accidentally added the worktree folder more than once.
Additional Context
_No response_
5 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This request isn't a duplicate exactly, but may help address https://github.com/anthropics/claude-code/issues/34458. I haven't tested it, though. Putting the worktree code in
.git/tmpwill shadow it for git, but I don't know what it does for other tooling. I have built a system with similar functionality to git-subrepo and spent considerable time using that and Intellij-based IDEs, which seemed to also ignore code in that folder. Intellij does seem to interact with worktrees in.git/worktrees, picking up those files in searches, duplicate code review, etc.Moving code to an entirely outside directory would resolve all issues, but I do like having everything contained within the same parent.
Anyway, not a duplicate.
Ah, forgot that the worktrees are in the
.claudedir, not.git. Never mind.I must recommend against this for projects in the javascript ecosystem:
Here is the core issue: https://github.com/anthropics/claude-code/issues/41075
reproduction, instructions, and explanation here: https://github.com/NullVoxPopuli/claude-worktrees-forgot-about-javascript/tree/main
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.