claude-code - 💡(How to fix) Fix Edit tool results in conversation history include full originalFile, causing context pollution and model confusion [4 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54525Fetched 2026-04-30 06:43:13
View on GitHub
Comments
4
Participants
3
Timeline
8
Reactions
1
Author
Timeline (top)
commented ×4labeled ×4

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.

Root Cause

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.

Fix Action

Fix / Workaround

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.

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.

RAW_BUFFERClick to expand / collapse

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

  1. Start a Claude Code session
  2. Make 3-4 rounds of edits to a file that contains behavioral instructions (e.g., a SKILL.md or similar)
  3. Observe that each Edit tool result in the JSONL contains the full originalFile field
  4. After several edits, the conversation context contains multiple contradictory versions of the same instructions
  5. 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

extent analysis

TL;DR

Omitting the originalFile field from Edit tool results in the conversation JSONL or implementing conversation compression to deduplicate old results may resolve the issue.

Guidance

  • Verify that the originalFile field is not necessary for the model's ongoing reasoning by checking if oldString/newString diff or structuredPatch provides sufficient context.
  • Test the effect of omitting originalFile from stored conversation history on the model's behavior.
  • Consider implementing conversation compression to prioritize deduplicating or summarizing old Edit tool results when the same file has been edited multiple times.
  • Evaluate the trade-offs between omitting originalFile and implementing conversation compression in terms of performance and accuracy.

Example

No code snippet is provided as it is not clearly supported by the issue.

Notes

The suggested solution may have limitations, such as potential impact on the model's ability to understand the context of edits or potential performance implications of conversation compression.

Recommendation

Apply workaround: Omit the originalFile field from Edit tool results or implement conversation compression, as this approach is likely to reduce context pollution and prevent contradictory behavior without requiring significant changes to the underlying model or infrastructure.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Edit tool results in conversation history include full originalFile, causing context pollution and model confusion [4 comments, 3 participants]