[BUG] Sandbox fails in git worktrees: bwrap cannot mkdir .git/hooks when .git is a file
Description
The sandbox fails to execute any bash commands in git worktrees because bubblewrap attempts to create .git/hooks without checking if .git is a file (worktree reference) or a directory.
Error Message
bwrap: Can't mkdir parents for /path/to/worktree/.git/hooks: Not a directory
Environment
- OS: Linux (Fedora 43, kernel 6.17.9)
- Claude Code version: Latest
- Sandbox: bubblewrap (bwrap)
Steps to Reproduce
- Create a git worktree:
``bash``
git worktree add ../my-worktree
- Run Claude Code from the worktree directory:
``bash``
cd ../my-worktree
claude
- Attempt any bash command (even simple ones like
lsortest -d foo)
- Every command fails with the bwrap error above
Root Cause
In git worktrees, .git is a file containing a gitdir: reference to the main repository's .git/worktrees/<name> directory. This is standard git behavior per git-worktree documentation.
The sandbox setup appears to unconditionally try to create/bind-mount .git/hooks without first checking if .git is a directory. When .git is a file, mkdir -p .git/hooks fails.
Expected Behavior
The sandbox should detect when .git is a file (worktree) and either:
- Skip the
.git/hooksprotection for worktrees, or - Resolve the actual git directory from the
gitdir:reference and protect hooks there
Workaround
Currently the only workarounds are:
- Disable sandbox entirely (
/sandbox→ disable) - Add commands to
excludedCommandsin settings - Run from the main repository instead of worktrees
None of these are ideal for users who rely on worktree-based workflows.
Related Issues
- #2841 - Cannot work with git worktrees due to directory restriction (different issue - navigation)
- #8019 - /ide command fails to recognize git worktrees (different issue - IDE detection)
This issue is distinct: the sandbox itself is completely broken in worktrees, not just specific features.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗