claude-code - 💡(How to fix) Fix Sandbox blocks git reset --hard on tracked files: 'Operation not permitted' for legitimate workspace sync [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#52851Fetched 2026-04-25 06:19:11
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1

The Claude Code sandbox write policy blocks git reset --hard origin/<branch> when the working tree contains tracked files (e.g. README.md). This prevents automation frameworks from syncing the local workspace after a GitHub PR merge, which is a legitimate and common post-merge operation.

Error Message

error: unable to unlink old 'README.md': Operation not permitted
fatal: Could not reset index file to revision 'origin/master'.

Root Cause

The Claude Code sandbox write policy blocks git reset --hard origin/<branch> when the working tree contains tracked files (e.g. README.md). This prevents automation frameworks from syncing the local workspace after a GitHub PR merge, which is a legitimate and common post-merge operation.

Fix Action

Workaround

Invoke the command with dangerouslyDisableSandbox: true. This requires manual intervention and cannot be automated within a normal sandboxed agent loop.

Code Example

error: unable to unlink old 'README.md': Operation not permitted
fatal: Could not reset index file to revision 'origin/master'.

---

git fetch origin master && git reset --hard origin/master
RAW_BUFFERClick to expand / collapse

Description

The Claude Code sandbox write policy blocks git reset --hard origin/<branch> when the working tree contains tracked files (e.g. README.md). This prevents automation frameworks from syncing the local workspace after a GitHub PR merge, which is a legitimate and common post-merge operation.

Error

error: unable to unlink old 'README.md': Operation not permitted
fatal: Could not reset index file to revision 'origin/master'.

Steps to Reproduce

  1. In a Claude Code session (default sandbox enabled), run via the Bash tool:
    git fetch origin master && git reset --hard origin/master
  2. The sandbox blocks the file unlink step with "Operation not permitted".

Expected Behavior

git reset --hard to a remote branch should be permitted in the project's working directory, which is already in the sandbox write allowlist. The operation only modifies tracked files that are explicitly inside the allowed write path.

Actual Behavior

The sandbox blocks unlinking existing tracked files (README.md, etc.) even though the project root is in the write allowlist. This appears to be a more granular restriction on file unlinking/replacement rather than path-level write permission.

Workaround

Invoke the command with dangerouslyDisableSandbox: true. This requires manual intervention and cannot be automated within a normal sandboxed agent loop.

Impact

Post-merge workspace synchronization in agentic orchestration frameworks requires either:

  • Manual sandbox bypass (operationally fragile), or
  • Graceful degradation with a diverged workspace state

A more targeted sandbox policy that permits git reset --hard within the project's allowed write root would eliminate this class of interruption.

Environment

  • Claude Code CLI (macOS, Darwin 25.x)
  • Observed during automated PR merge + workspace sync in agentic run sessions

extent analysis

TL;DR

The issue can be resolved by implementing a more targeted sandbox policy that permits git reset --hard within the project's allowed write root.

Guidance

  • Review the current sandbox policy to understand the specific restrictions on file unlinking and replacement.
  • Consider modifying the sandbox policy to allow git reset --hard operations within the project's allowed write root.
  • Evaluate the use of dangerouslyDisableSandbox: true as a temporary workaround, but be aware of potential security implications.
  • Investigate alternative Git commands or workflows that may achieve the desired result without triggering the sandbox restriction.

Example

No code snippet is provided as the issue is related to sandbox policy configuration rather than code implementation.

Notes

The solution may require collaboration with the Claude Code team or administrators to modify the sandbox policy. Additionally, careful consideration should be given to the security implications of allowing git reset --hard operations within the sandbox.

Recommendation

Apply a targeted sandbox policy modification to permit git reset --hard within the project's allowed write root, as this approach balances security concerns with the need for automated workspace synchronization.

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