Bash sandbox (bwrap) fails when .git/hooks is a symlink on Linux
On Linux, any bash command fails with a misleading error when the repo's .git/hooks is a symlink to a real directory rather than a plain directory. This is a common setup for sharing hooks via version control.
Error
bwrap: Can't create file at /path/to/repo/.git/hooks: No such file or directory
Steps to Reproduce
mkdir testrepo && cd testrepo && git init
mkdir tracked-hooks
rm -rf .git/hooks
ln -s ../tracked-hooks .git/hooks
# Now run any bash command in Claude Code on Linux (default sandbox mode)
Expected Behavior
The bash command runs successfully inside the sandbox.
Actual Behavior
bwrap fails to construct the sandbox and the command errors out with the message above.
Root Cause
bwrap walks the current directory tree to set up bind-mount points in a tmpfs overlay. When it hits .git/hooks as a symlink, it cannot create a real directory at that path in the tmpfs, causing the entire sandbox setup to fail. The path resolves correctly in userspace (os.path.exists returns True) — the issue is specific to bwrap's virtual filesystem construction.
Workaround
Use dangerouslyDisableSandbox: true on affected bash commands.
Platform
Linux only. macOS uses a different sandbox mechanism that is not affected.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗