[BUG] Sandbox silently reverts Edit tool writes on macOS
Bug Description
When Claude Code's built-in sandbox is enabled in project settings, the Edit tool reports success but the file changes are silently reverted within milliseconds. The tool output says the edit was applied, but by the time the next tool call runs (e.g. git add), the file is back to its original content.
This makes the Edit tool unusable when sandbox is enabled.
Steps to Reproduce
- Enable sandbox in project settings (
.claude/settings.local.json):
``json``
{
"sandbox": {
"enabled": true,
"autoAllowBashIfSandboxed": true
}
}
- Ask Claude to edit a file in the project directory using the Edit tool
- The Edit tool reports success
- Immediately run
git difforcatthe file — the edit is gone - System reminder appears: "Note: file was modified, either by the user or by a linter" showing the original (pre-edit) content
Workaround
Using python3 via Bash with dangerouslyDisableSandbox: true to write files bypasses the issue. The writes persist and can be committed.
Alternatively, disabling sandbox (/sandbox off or removing the config) resolves the issue.
Observations
fs_usagemonitoring confirmed that the only process touching the files was Claude Code itself (same PID)- The revert happens between the Edit tool completing and the next tool call executing
git add+git commitin a single Bash call withdangerouslyDisableSandbox: trueworks — confirming the sandbox restore mechanism is the cause- The issue is intermittent: in the same session, most Edit tool writes persisted normally. Only certain files were repeatedly reverted — specifically files that had been read multiple times during the session. Other files edited in the same session with the same tool were fine.
- Files that were reverted could be successfully written using Bash with
dangerouslyDisableSandbox: truein the same session, ruling out file permissions or other OS-level issues.
Environment
- Platform: macOS (darwin, Darwin 25.3.0, arm64)
- Claude Code version: 2.1.75+
- Sandbox mode: enabled via project settings
- Permission mode: acceptEdits
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗