/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.
11 Comments
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Confirming this also affects the EnterWorktree tool in Claude Code v2.1.52 (Feb 2026). Same root cause as #17374 — .git is a file in worktrees, so bwrap writes stubs to the project root. The .gitignore workaround hides the cosmetic issue but doesn't fix the write-blocking that makes worktree git operations fail.
🤖 Generated with Claude noreply@anthropic.com
This is incredibly annoying, disabled sandbox for now.
This behavior is extremely annoying. It's new in a recent release: I'm seeing it now with Claude Code v2.1.52 (also v2.1.63, after upgrading), and I wasn't seeing it a week or two ago.
Whenever I have a Claude Code session open,
git statuslooks like this:If Claude makes any changes that create new files, this makes it tricky to accurately commit the intended changes, as I have to pick them out from the noise of all these unintended new files.
A further symptom is that many Bash commands that Claude itself tries to run don't behave correctly, because of the existence of that file named
HEAD:I believe this is not a duplicate.
That issue doesn't mention any symptom resembling this one — there's nothing about extra files getting created in the working tree.
That issue was closed 2 weeks ago. This behavior is new and I'm seeing it today.
The symptoms do look pretty similar. It's possible that issue was related.
One difference is that that issue specifically discusses WSL. I'm seeing this behavior on Linux.
Ah, here's another previous version of this issue that the bot didn't find:
That points to an issue thread in a different repo which appears to be on point:
This issue appears to be a symptom of that sandbox-runtime issue.
Thank you for filing this. I would like to add a data point.
The same phenomenon occurs in a regular (non-worktree) git clone on WSL2 Ubuntu (bubblewrap 0.9.0) with Claude Code as of 2026-04-20. The affected paths match the list in #26722 (
.bash_profile,.bashrc,.profile,.zprofile,.zshrc,.gitconfig,.gitmodules,.ripgreprc,.mcp.json,.vscode,.idea,.claude/agents), but on my side they appear as character special files pointing at/dev/null(device1,3, ownernobody:nogroup), rather than as the 0-byte regular files described earlier.Example:
Configuration context:
sandbox.filesystem.denyReadis empty in both global and projectsettings.json. These paths are being mounted by the built-in protected-paths layer, not by any user-specified rule..gitignore. git does not commit character special files, so this is purely for noise suppression ingit status.If helpful, it might be worth broadening the title/description of this issue so that users hitting the same problem outside of worktrees can find it via search. #26722 and #32177 were closed as duplicates, so I am leaving this as a comment here rather than opening a new issue.
@kosei-w90607 That sounds like a different issue to me (though I'm no expert on this codebase, just a fellow user). In particular:
I'm also not seeing this issue now, with v2.1.123. So this issue may have been fixed.
#26722 was closed by the person who reported it, not anyone who manages this repo. I think the best chance of getting any maintainer attention on your issue (which sounds like the same issue as #26722) is if your issue has its own thread, separate from this one. Since the author of #26722 closed that thread, you can open a new one yourself (unless someone else has opened a new issue for it since then).
This issue was fixed as of version 2.1.78.
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.