[BUG] Invalid Unicode in Edit tool results causes 400 'invalid JSON' API errors

Resolved 💬 5 comments Opened Dec 5, 2025 by itdove Closed Feb 5, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

## Bug Description
When the Edit tool operates on files containing certain Unicode characters, the tool result stored in the conversation .jsonl file contains invalid Unicode surrogate pairs. This corrupts the conversation history and causes all subsequent API requests to fail with:

400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON."}

## Steps to Reproduce

  1. Use Edit tool on a large file (~24KB) with Unicode characters
  2. Tool result is stored in conversation .jsonl
  3. Next API request fails with "invalid JSON" error
  4. All subsequent requests fail permanently

## Evidence

  • Conversation file contains invalid surrogate pair at line 87, column 32715
  • Tool result content length: 24,279 bytes
  • jq parse error: "Invalid \uXXXX\uXXXX surrogate pair escape"

## Environment

  • Claude Code version: 2.0.59
  • Platform: macOS (Darwin 25.1.0)

## Workaround
Session becomes unusable and must be abandoned, however in another session, I asked Claude to repair the session and it succeeded.

What Should Happen?

## Expected Behavior
Edit tool results should sanitize Unicode to ensure valid JSON encoding

Error Messages/Logs

400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON."}

Steps to Reproduce

## Steps to Reproduce

  1. Use Edit tool on a large file (~24KB) with Unicode characters
  2. Tool result is stored in conversation .jsonl
  3. Next API request fails with "invalid JSON" error
  4. All subsequent requests fail permanently

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.59

Platform

Google Vertex AI

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

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