claude-code - 💡(How to fix) Fix Sandbox auto-adds config/ to denyWithinAllow, breaking git checkout across refs [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56331Fetched 2026-05-06 06:30:58
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1renamed ×1unsubscribed ×1

Claude Code's sandbox auto-includes config/ (the Rails-conventional config directory) in its denyWithinAllow list when the working directory is a Rails project. There is no corresponding user setting — .claude/settings.json, .claude/settings.local.json, and ~/.claude/settings.json contain no rule that would produce this entry.

This is the same shape of bug as #40133 (.claude/skills auto-added) and #51303 (.vscode/ hardcoded deny), but for a directory that is part of normal application source code, not editor/Claude metadata.

Error Message

warning: unable to unlink 'config/<file>': Operation not permitted error: unable to unlink old 'config/application.rb': Operation not permitted error: unable to unlink old 'config/database.yml': Operation not permitted error: unable to unlink old 'config/routes.rb': Operation not permitted ...

Root Cause

The working tree is left in a hybrid state: target ref's commit pointer, but the previous ref's config/* files still on disk. Returning to the original ref then fails because the tree is dirty:

Code Example

warning: unable to unlink 'config/<file>': Operation not permitted
error: unable to unlink old 'config/application.rb': Operation not permitted
error: unable to unlink old 'config/database.yml': Operation not permitted
error: unable to unlink old 'config/routes.rb': Operation not permitted
...

---

error: Your local changes to the following files would be overwritten by checkout:
    config/application.rb
    config/database.yml
    ...
RAW_BUFFERClick to expand / collapse

Summary

Claude Code's sandbox auto-includes config/ (the Rails-conventional config directory) in its denyWithinAllow list when the working directory is a Rails project. There is no corresponding user setting — .claude/settings.json, .claude/settings.local.json, and ~/.claude/settings.json contain no rule that would produce this entry.

This is the same shape of bug as #40133 (.claude/skills auto-added) and #51303 (.vscode/ hardcoded deny), but for a directory that is part of normal application source code, not editor/Claude metadata.

Repro

  1. In project with config/, start a Claude Code session with the sandbox enabled.
  2. Inspect the Bash tool's sandbox block in the system prompt — config/ appears in denyWithinAllow despite no user config asking for it.
  3. Have Claude run git checkout <other-ref> where <other-ref> differs in any file under config/.

Expected

git checkout succeeds; the working tree matches the target ref.

Actual

git checkout partially succeeds — HEAD moves to the target ref, but the sandbox blocks the unlink/replace of files inside config/:

warning: unable to unlink 'config/<file>': Operation not permitted
error: unable to unlink old 'config/application.rb': Operation not permitted
error: unable to unlink old 'config/database.yml': Operation not permitted
error: unable to unlink old 'config/routes.rb': Operation not permitted
...

The working tree is left in a hybrid state: target ref's commit pointer, but the previous ref's config/* files still on disk. Returning to the original ref then fails because the tree is dirty:

error: Your local changes to the following files would be overwritten by checkout:
    config/application.rb
    config/database.yml
    ...

Impact

This silently corrupts any workflow that uses git checkout to switch refs — e.g. baseline-vs-HEAD performance benchmarking, bisecting, or comparing behavior across branches. Measurements taken after the partial checkout are invalid because they run against a hybrid tree, but neither Claude nor the user gets a clear error at the point the corruption happens.

Environment

  • Platform: macOS (sandbox-exec, not bwrap)

Asks

  1. Document where the denyWithinAllow list comes from — currently undocumented (the published settings docs cover allowWrite/denyWrite/denyRead/ allowRead only).
  2. Either don't auto-add config/ (standard for Rails projects), or make git checkout (and similar tree-mutating git operations) bypass the sandbox by default.
  3. At minimum, fail loudly when a git command can't fully apply a tree change because of sandbox restrictions, instead of leaving the working tree silently corrupted.

Related

  • #40133 — .claude/skills auto-added to denyWithinAllow
  • #51303 — Sandbox blocks git checkout/worktree add on repos tracking .vscode/ (closed as duplicate of #46000)
  • #46000 — Sandbox filesystem rules can't scope to git root

extent analysis

TL;DR

The issue can be mitigated by documenting the denyWithinAllow list and potentially exempting config/ from it or making git checkout bypass the sandbox by default.

Guidance

  • Investigate the source of the denyWithinAllow list to understand why config/ is being auto-added, as this is currently undocumented.
  • Consider adding an exemption for config/ in Rails projects or making git checkout and similar operations bypass the sandbox by default to prevent working tree corruption.
  • Implement a loud failure mechanism when a git command cannot fully apply a tree change due to sandbox restrictions to prevent silent corruption.

Example

No specific code example is provided as the issue seems to be related to configuration and sandbox behavior rather than code implementation.

Notes

The exact solution may depend on the specifics of the Claude Code sandbox implementation and its interaction with Rails projects. The provided guidance aims to address the immediate issue of working tree corruption during git checkout operations.

Recommendation

Apply a workaround by exempting config/ from the denyWithinAllow list or making git checkout bypass the sandbox by default, as this directly addresses the issue of silent working tree corruption during ref switches.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Sandbox auto-adds config/ to denyWithinAllow, breaking git checkout across refs [1 comments, 2 participants]