[BUG] Sandbox fails in git worktrees: bwrap cannot mkdir .git/hooks when .git is a file

Resolved 💬 3 comments Opened Feb 1, 2026 by stellaraccident Closed Feb 4, 2026

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

  1. Create a git worktree:

``bash
git worktree add ../my-worktree
``

  1. Run Claude Code from the worktree directory:

``bash
cd ../my-worktree
claude
``

  1. Attempt any bash command (even simple ones like ls or test -d foo)
  1. 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:

  1. Skip the .git/hooks protection for worktrees, or
  2. 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 excludedCommands in 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.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗