Edit tool results in conversation history include full originalFile, causing context pollution and model confusion
Summary
When Claude Code performs multiple Edit operations on the same file during a session, each toolUseResult in the conversation JSONL includes the full originalFile content alongside oldString, newString, and structuredPatch. Over the course of a long editing session, this creates multiple contradictory copies of the file's content in the conversation context.
Problem
This is particularly harmful when the edited files contain instructions or behavioral directives (e.g., skill files, CLAUDE.md, config files with comments). The model absorbs all versions simultaneously as ground truth and tries to satisfy contradictory instructions — leading to confabulation, self-contradiction, and degraded reasoning.
The model typically cannot self-diagnose this because the contradictions are embedded in tool results (perceived as facts) rather than in explicit instructions (which the model is better at evaluating critically). It takes several rounds of targeted interrogation before the model can identify the conflicting context.
Reproduction
- Start a Claude Code session
- Make 3-4 rounds of edits to a file that contains behavioral instructions (e.g., a SKILL.md or similar)
- Observe that each Edit tool result in the JSONL contains the full
originalFilefield - After several edits, the conversation context contains multiple contradictory versions of the same instructions
- The model begins exhibiting confused or contradictory behavior
Suggestion
The originalFile field in Edit tool results seems unnecessary for the model's ongoing reasoning — the oldString/newString diff (or structuredPatch) is sufficient context. Omitting originalFile from the stored conversation history would significantly reduce context pollution and prevent ghost copies of instruction-laden files from accumulating.
Alternatively, conversation compression could prioritize deduplicating or summarizing old Edit tool results when the same file has been edited multiple times.
Environment
- Claude Code CLI on Windows 11 (Git Bash)
- Observed during development of a channel plugin with multiple SKILL.md files
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗