Edit tool changes to git-tracked files silently reverted during context compaction

Resolved 💬 3 comments Opened Mar 15, 2026 by Ascendral Closed Apr 20, 2026

Summary

When a long conversation triggers context compaction (message compression), uncommitted changes made via the Edit tool to git-tracked files are silently reverted to their git HEAD state. New files created with the Write tool are not affected.

Steps to Reproduce

  1. Start a Claude Code session in a git repository
  2. Make multiple Edit-tool changes to tracked src/ files across a long conversation
  3. Continue working until context compaction triggers (conversation approaches context limit)
  4. Check file contents after compaction — Edit-tool changes are gone

Observed Behavior

  • Edit-tool changes to tracked files disappear between tool calls after compaction
  • New files (untracked by git) survive compaction
  • Bash-written changes (e.g., echo >> file) also survive
  • Changes committed to git before compaction are never lost
  • No git hooks, file watchers, or external processes are responsible (verified)

Expected Behavior

Edit-tool changes should persist regardless of context compaction. The file system should not be modified by the compaction process.

Workaround

Commit immediately after every Edit-tool change:

git add <file> && git commit -m "description"

Or for multi-file atomic changes, write a Node.js script to /tmp/ using fs.writeFileSync, then chain:

node /tmp/fix.js && git add <files> && git commit -m "description"

Environment

  • Claude Code v2.1.74
  • Claude Desktop (macOS)
  • macOS 26 (Darwin 25.3.0)
  • Model: claude-opus-4-6
  • Plugins: typescript-lsp (not installed/running), pyright-lsp, others

View original on GitHub ↗

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