Sandbox filesystem restrictions break git worktree workflows
Problem
Claude Code's sandbox scopes filesystem writes to the current working directory. Git worktrees (both bare repo layouts and normal clone worktrees) require writes to shared git internals outside the current working directory, causing all git write operations (add, commit, push) to fail with:
fatal: Unable to create '.../index.lock': Read-only file system
Reproduction
- Set up a bare repo with worktrees:
``bash``
git clone --bare repo.git .bare
echo "gitdir: ./.bare" > .git
git worktree add main main
cd main
- Enable sandbox in Claude Code settings (
"sandbox": { "enabled": true }) - Ask Claude to make a commit — fails because
.bare/is outside the cwd
This also affects normal clones with worktrees: git worktree add ../feature-branch creates a worktree whose git metadata lives at <original-repo>/.git/worktrees/, which is outside the worktree's cwd.
What doesn't work
excludedCommands: ["git"]— bypasses command-level sandboxing but the filesystem write restriction still blocks git's internal file writessandbox.filesystem.write.additionalAllow— not a real config key (no effect)
Impact
This blocks a compelling multi-agent workflow: spawning Claude Code agents in separate worktrees to work on features in parallel. Each agent's sandbox prevents it from committing in its own worktree.
Suggested solutions (any of these would help)
- Make
excludedCommandsfully bypass the filesystem sandbox — if a command is excluded, don't restrict its filesystem writes - Auto-detect git internals — resolve the repo's git directory (via
git rev-parse --git-common-dir) and automatically allow writes there - Support
additionalAllowin sandbox config — let users explicitly add paths to the filesystem write allowlist:
``json``
"sandbox": {
"filesystem": {
"write": {
"additionalAllow": ["/path/to/.bare"]
}
}
}
Option 2 would provide the best DX — zero config, works for all worktree layouts.
Environment
- Claude Code with sandbox enabled
- Git bare repo with worktrees (also reproducible with normal clone +
git worktree add) - Linux (Arch)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗