/sandbox creates empty stub files in project root when using git worktrees

Status Fixed / completed
Maintainer reply ✓ Yes — claude[bot]
Activity 11 comments · opened Feb 27, 2026 · closed May 18, 2026
💡 Likely answer: A maintainer (claude[bot], contributor) responded on this thread — see the highlighted reply below.

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

  1. Create or use a git worktree: git worktree add ../my-branch my-branch
  2. cd into the worktree directory (where .git is a file, not a directory)
  3. Run /sandbox connect in Claude Code
  4. 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.

View original on GitHub ↗

11 Comments

github-actions[bot] · 6 months ago

Found 2 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/25896
  2. https://github.com/anthropics/claude-code/issues/26722

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

qte77 · 6 months ago

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

Suor · 6 months ago

This is incredibly annoying, disabled sandbox for now.

gnprice · 6 months ago

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 status looks like this:

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.bash_profile
	.bashrc
	.claude/agents
	.claude/commands
	.claude/skills
	.gitconfig
	.gitmodules
	.mcp.json
	.profile
	.ripgreprc
	.zprofile
	.zshrc
	HEAD
	config
	hooks
	objects
	refs

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.

gnprice · 6 months ago

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:

● Bash(git log --oneline HEAD | wc -l)
  ⎿  0
     fatal: ambiguous argument 'HEAD': both revision and filename
     Use '--' to separate paths from revisions, like this:
     'git <command> [<revision>...] -- [<file>...]'

● […]

● Bash(git rev-list --count HEAD)
  ⎿  Error: Exit code 128
     fatal: ambiguous argument 'HEAD': both revision and filename
     Use '--' to separate paths from revisions, like this:
     'git <command> [<revision>...] -- [<file>...]'

     fatal: ambiguous argument 'HEAD': both revision and filename
     Use '--' to separate paths from revisions, like this:
     'git <command> [<revision>...] -- [<file>...]'
gnprice · 6 months ago

I believe this is not a duplicate.

1. https://github.com/anthropics/claude-code/issues/25896

That issue doesn't mention any symptom resembling this one — there's nothing about extra files getting created in the working tree.

2. https://github.com/anthropics/claude-code/issues/26722

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.

gnprice · 6 months ago

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.

kosei-w90607 · 4 months ago

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 (device 1,3, owner nobody:nogroup), rather than as the 0-byte regular files described earlier.

Example:

$ stat -c '%n  %F  %A  (%U/%G)' .bashrc
.bashrc  character special file  crw-rw-rw-  (nobody/nogroup)

Configuration context:

  • sandbox.filesystem.denyRead is empty in both global and project settings.json. These paths are being mounted by the built-in protected-paths layer, not by any user-specified rule.
  • Workaround: adding the paths to project .gitignore. git does not commit character special files, so this is purely for noise suppression in git 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.

gnprice · 4 months ago

@kosei-w90607 That sounds like a different issue to me (though I'm no expert on this codebase, just a fellow user). In particular:

  • you're seeing special files, rather than plain empty files;
  • the list of filenames is different.

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).

claude[bot] contributor · 3 months ago

This issue was fixed as of version 2.1.78.

github-actions[bot] · 1 month ago

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.