[BUG] Sandbox `denyWithinAllow` list omits `.git/` prefix from git-internal file paths
Status Closed — not planned
Reported on v2.1.42
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 12 comments · opened Feb 15, 2026 · closed May 25, 2026
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?
What's Wrong?
The sandbox's denyWithinAllow list constructs incorrect paths for git-internal files. Files that live inside .git/ (such as HEAD, objects, refs, hooks, config) are listed without the .git/ path component, pointing to nonexistent paths at the project root instead.
Actual Behavior
The deny list contains:
/path/to/project/HEAD
/path/to/project/objects
/path/to/project/refs
/path/to/project/hooks
/path/to/project/config
The .git/ segment is missing from every path.
Impact
.git/internals are unprotected. The deny rules target nonexistent paths at the project root, so the sandbox does not actually block writes to.git/HEAD,.git/objects, etc.- False positives. If a project happened to have files named
HEAD,config,objects,refs, orhooksat the root level, they would be incorrectly blocked.
What Should Happen?
Expected Behavior
The deny list should contain:
/path/to/project/.git/HEAD
/path/to/project/.git/objects
/path/to/project/.git/refs
/path/to/project/.git/hooks
/path/to/project/.git/config
Error Messages/Logs
Steps to Reproduce
Steps to Reproduce
- Create a standard (non-bare) git repo
- Enable sandbox in settings:
{
"sandbox": {
"enabled": true,
"autoAllowBashIfSandboxed": true,
"excludedCommands": ["git"]
}
}
- Start a Claude Code session in the repo
- Ask Claude to show the full
denyWithinAllowlist - Observe that git-internal files are listed without the
.git/prefix
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.42 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
Showing cached comments. Read the full discussion on GitHub ↗
11 Comments
Note: fixing the paths alone may not be sufficient
During investigation, I manually added correct
Edit(.git/**)deny rules to my permissions config. This resulted in the sandbox blocking legitimategit addandgit commitoperations with errors like:The root cause: when Claude wraps git commands inside
bash -c "git add ... && git commit ..."(which it frequently does),bashis the top-level command, notgit. TheexcludedCommands: ["git"]rule only applies whengitis the top-level command, so the chained commands run inside the sandbox and hit the.gitdeny rules.This means that if this bug is fixed by simply correcting the paths to include
.git/, the corrected deny rules would break git operations for anyone whose Claude instance chains commands viabash -c— which appears to be the common behavior.Possible approaches:
excludedCommandsapply to child processes, not just the top-level command.denyWithinAllowentries from applying to child processes of excluded commands.denyWithinAllowentirely and rely on the broader.gitdirectory blocking rule that the sandbox already applies separately.I thought I was going crazy today. Glad you guys know about this, and thanks for what you build. 😃
This also prevents use of the sandbox if your project has a subdirectory called for example "config". And it's not overridable with your local config settings, meaning there is no workaround other than to not use the sandbox for any bash command that might need to write to one of the inappropriately denied files/directories.
This is also a security vulnerability in the sandbox so should probably be prioritized rather than being allowed to go stale.
Adding
fs_usageevidence from a real-world case where this bug causes silent data loss.Observed behavior
In an Elixir/Phoenix project, Claude Code's sandbox periodically deletes the project-root
config/directory (a standard framework directory) because thedenyWithinAllowlist targets/path/to/project/configinstead of/path/to/project/.git/config.fs_usagesyscall traceThe sandbox enforcement process (
2.1.87.736478) iterates over the malformed deny list and callsunlinkaton each entry.HEAD,objects,refs,hooksfail with ENOENT (they don't exist at the project root), butconfig/exists as a real project directory and gets deleted.Impact in practice
git checkout HEAD -- config/ineffectiveconfig/directory (Elixir/Phoenix, Ruby on Rails, etc.)chflags -R uchg config/(macOS immutable flag)Related
Closing #40568 as duplicate of this issue.
cc @seanlynch @nf-matt — the
chflags -R uchg config/workaround may help until this is fixed.If you can believe it, I'm about to rename my
configdir tonotfig... 👎Closing for now — inactive for too long. Please open a new issue if this is still relevant.
I opened a new issue here: https://github.com/anthropics/claude-code/issues/66288
I hope you have more luck with this than I did... 😅
Me too. It's hard to imagine nobody should be able to use a directory named
configin their own projects.Disabled sandbox for now as it's a blocker. Going to be investigating using containerization around Claude Code. Tis Bonkers.
You might check out nono -- I've been using it quite successfully for months now, and agent autonomy is fantastic with it. I am able to run in "bypass permissions" mode because nono has everything boxed in the way I want.