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
- Start a Claude Code session in a git repository
- Make multiple Edit-tool changes to tracked
src/ files across a long conversation
- Continue working until context compaction triggers (conversation approaches context limit)
- 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
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 HEADstate. New files created with the Write tool are not affected.Steps to Reproduce
src/files across a long conversationObserved Behavior
echo >> file) also surviveExpected 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:
Or for multi-file atomic changes, write a Node.js script to
/tmp/usingfs.writeFileSync, then chain:Environment