[BUG] Sandbox silently reverts Edit tool writes on macOS

Resolved 💬 2 comments Opened Mar 18, 2026 by knutwannheden Closed Apr 15, 2026

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

  1. Enable sandbox in project settings (.claude/settings.local.json):

``json
{
"sandbox": {
"enabled": true,
"autoAllowBashIfSandboxed": true
}
}
``

  1. Ask Claude to edit a file in the project directory using the Edit tool
  2. The Edit tool reports success
  3. Immediately run git diff or cat the file — the edit is gone
  4. 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_usage monitoring 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 commit in a single Bash call with dangerouslyDisableSandbox: true works — 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: true in 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

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗