[BUG] Sandbox denies writes to shared .git inside a linked git worktree — git commit/add/push fail with EPERM, despite documented worktree allowance (v2.1.160)
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Inside a linked git worktree, the command sandbox denies writes to the repository's shared .git directory (objects, refs, the per-worktree git-dir). This makes git add, git commit, and git push fail with Operation not permitted (EPERM). The sandboxing docs state that worktree sessions should allow writes to the shared .git directory and deny only hooks/ and config. Observed behavior denies far more than that.
What Should Happen?
Per the docs: "when the working directory is a linked git worktree, the sandbox also allows writes to the main repository's shared .git directory so commands such as git commit can update refs and the index. Writes to hooks/ and config inside that directory remain denied." So git commit/add/push should succeed; only .git/hooks/ and .git/config should be denied.
Error Messages/Logs
The Bash tool I use runs every command inside a filesystem sandbox with a write-allowlist. Your repo's working tree is writable, but the entire .git/ directory is write-denied — every level of it:
DENIED: /Users/you/notes/.git/__t (the git dir itself)
DENIED: /Users/you/notes/.git/objects/__t (commit/blob storage)
DENIED: /Users/you/notes/.git/refs/__t (branch pointers)
DENIED: /Users/you/notes/.git/hooks/__t (hook scripts)
DENIED: /Users/you/notes/.git/config.__t (config)
DENIED: /Users/you/notes/.git/worktrees/blog-posts/__t (this worktree's index/HEAD)
WRITABLE: <working tree> (control — passes)
DENIED : /Users/you/notes/__sbtest ← main repo root, NOT a .git path
DENIED : /Users/you/notes/testdir/__sbtest ← ordinary folder, NOT a .git path
DENIED : /Users/you/notes/.git/objects/__sbtest
WRITABLE: ./__sbtest ← inside the worktree
Steps to Reproduce
- Start a new session like so "claude"
- Prompt to use a worktree
- Create a sample file.md
- At the same time, navigate to to a new terminal session
- Star a new session like so "claude"
- Create a new file, myfile.md
- Ask claude to create a new branch (non worktree)
- Ask claude to commit and push the file
- Return to the first session, where you're in a work tree
- Prompt claude to commit and push
git add file.md && git commit -m "edit"
fatal: Unable to create '/Users/you/myrepo/.git/worktrees/feature-x/index.lock': Operation not permitted
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.160
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
- Claude Code: 2.1.160
- OS: macOS (Darwin 25.5.0)
- Sandbox: enabled. Relevant managed settings:
sandbox.filesystem.allowWrite = ["./", "./tmp"]sandbox.allowUnsandboxedCommands = 0permissions.disableBypassPermissionsMode = disable- Working directory is a linked git worktree created under
.claude/worktrees/<name>.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗