[BUG] Agent with isolation:worktree reports successful writes but files unchanged on disk (WSL2)

Resolved 💬 3 comments Opened Mar 17, 2026 by u4047464554-gith Closed Mar 20, 2026

Description

When launching an Agent with isolation: "worktree", the agent reports successful file edits (via Edit tool, Write tool, or sed), but the files on disk remain unchanged. The agent's transcript shows successful tool results, but independent verification (grep, python open().read(), git diff) confirms the files were never modified.

This happened repeatedly (3 separate attempts with 3 different agents) in a single session before diagnosing the root cause.

Environment

  • Platform: Linux 6.6.87.2-microsoft-standard-WSL2 (Ubuntu under Windows)
  • Claude Code version: 2.1.76
  • Model: claude-opus-4-6 (1M context)

Steps to Reproduce

  1. Launch an Agent with isolation: "worktree" to modify Python files
  2. Agent uses Edit tool to change field names, add code blocks, etc.
  3. Agent reports "All changes applied" with specific line numbers
  4. Agent runs tests — tests pass (but seem to use cached/in-memory state)
  5. Check the worktree files with grep or python3 -c "print(open('file').read())"files are unchanged

Observed Behavior

  • Agent transcript shows successful Edit/Write tool calls with no errors
  • Agent reports test passes (2,480+ tests)
  • Agent summary lists specific line numbers and changes made
  • git diff shows no modifications
  • grep for the expected new content returns nothing
  • Python pathlib.Path.read_text() in a fresh process confirms old content

Expected Behavior

File writes by the worktree agent should persist to the filesystem.

Workaround

Writing via Python script with temp file + os.rename() pattern bypasses the issue:

import pathlib, os
p = pathlib.Path("target_file.py")
text = p.read_text()
text = text.replace("old_content", "new_content")
tmp = p.with_suffix(".py.tmp")
tmp.write_text(text)
os.rename(str(tmp), str(p))

Direct sed -i, Edit tool, and Write tool all fail silently on this WSL2 setup.

Related Issues

  • #29110 — Spawned agents: worktree data loss (agents report success, work lost)
  • #9458 — Sub-agent Write tool operations don't persist to filesystem
  • #12932 — Synchronization problem between worktrees and main repository
  • #27044 — claude --worktree does not create a git worktree

Impact

This is a data loss bug that is particularly dangerous because:

  1. The agent reports success — there is no error signal
  2. Tests may pass using cached/in-memory state, masking the failure
  3. The user discovers the loss only when independently verifying
  4. Multiple retry attempts fail the same way with no feedback

In our case, this caused 3 failed implementation attempts (~15 minutes of agent compute each) before we identified the pattern and switched to the Python temp+rename workaround.

View original on GitHub ↗

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