/sandbox creates empty stub files in project root when using git worktrees
Description
When using /sandbox in a repository that is a git worktree (where .git is a file pointer rather than a directory), a set of empty stub files are created in the project root and show up as untracked files in git status.
Affected files
The following empty (0-byte), read-only files are created in the project root:
Shell dotfiles (sandbox home dir mapping):
`.bash_profile, .bashrc, .gitconfig, .gitmodules, .idea, .mcp.json, .profile, .ripgreprc, .zprofile, .zshrc`
Git internals (normally live inside .git/ directory):HEAD, config, hooks, objects, refs
Root cause hypothesis
In a normal repo, .git is a directory that already contains HEAD, config, hooks, objects, refs — so any sandbox stubs landing inside .git/ would be invisible to git status. In a worktree, .git is a file (e.g. gitdir: /path/to/worktrees/branch), so the sandbox writes the stubs to the project root instead, where git picks them up as untracked.
Reproduction steps
- Create or use a git worktree:
git worktree add ../my-branch my-branch cdinto the worktree directory (where.gitis a file, not a directory)- Run
/sandbox connectin Claude Code - Run
git status— observe empty stub files listed as untracked
Expected behavior
No untracked files should be created in the project directory as a side effect of connecting to a sandbox.
Workaround
Add the affected filenames to .gitignore.
This issue has 11 comments on GitHub. Read the full discussion on GitHub ↗