[Bug] Edit Tool Corrupts Base64 Data in Large Strings

Resolved 💬 3 comments Opened Dec 10, 2025 by tobez Closed Feb 10, 2026

Bug Report: Base64 Data Corruption via Edit Tool

Summary

When using the Edit tool to replace content with large base64-encoded data (~5KB), the base64 string gets corrupted during API processing, resulting in incorrect bytes that render differently than the source image.

Environment

  • Claude Code Version: [fill in]
  • Model: Affects all models (tested with Sonnet 4.5)
  • OS: macOS (Darwin 24.6.0)
  • Data size: ~5KB base64 string (~3.7KB PNG source)

Symptoms

  1. Edit operations take 5+ minutes to complete (normal edits take <1 second)
  2. Base64 output differs from source encoding (different bytes)
  3. Decoded image renders incorrectly or not at all
  4. No error messages - operation appears successful

Reproduction Steps

  1. Generate base64 encoding of a PNG file:

``bash
base64 -i assets/logo.png | tr -d '\n'
``

  1. Use Edit tool to replace a CSS background-image with the base64 data:

``
old_string: background-image: url('./assets/logo.png');
new_string: background-image: url('data:image/png;base64,iVBORw0KGgo...[5KB of base64]');
``

  1. Compare the base64 in the edited file with the original:

``bash
# Correct: ...cEhZcwAAIdUA...
# Corrupted: ...cEhZcwAAFiUA...
``

Expected Behavior

The Edit tool should preserve the exact base64 string without corruption.

Actual Behavior

The base64 string is altered during API processing:

  • Original: ...cEhZcwAAIdUAACHVAQSctJ0AAA5eSURB...
  • After Edit: ...cEhZcwAAFiUAABYlAUlSJPAAAA5LSURBVHhe...

The corruption causes the decoded image to fail rendering in browsers.

Workaround

Use purely programmatic tools without sending base64 through the API:

# Generate base64
base64 -i assets/logo.png | tr -d '\n' > /tmp/logo.b64

# Replace in file with sed
sed -i.bak "s|url('data:image/png;base64,[^']*')|url('data:image/png;base64,$(cat /tmp/logo.b64)')|" file.css

Related Issues

Possibly related to:

  • #6780 - Read Tool: Session corruption with large files
  • #6903 - Unicode codepoint corruption during Write
  • #7134 - File encoding corruption

Additional Context

  • PDF generation works fine because it embeds the image directly (not via CSS)
  • The corruption is deterministic (same input always produces same corrupted output)
  • Smaller base64 strings (<1KB) may not trigger the issue
  • The 5+ minute delay suggests the API is struggling to process the large string

Impact

This makes it impossible to use the Edit tool for:

  • Embedding images as data URLs in CSS/HTML
  • Editing files with large base64-encoded content
  • Any scenario requiring exact binary data preservation

---

Recommendation: Either fix the base64 corruption in the Edit tool API processing, or document this limitation and recommend the programmatic workaround for binary data.

View original on GitHub ↗

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