claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

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

Open itdove opened this issue 2 months ago • 3 comments

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

itdove avatar Dec 05 '25 19:12 itdove

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/1709
  2. https://github.com/anthropics/claude-code/issues/5934
  3. https://github.com/anthropics/claude-code/issues/8108

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Dec 05 '25 19:12 github-actions[bot]

Do you know any specific character that causes problems?

XeroOl avatar Dec 06 '25 19:12 XeroOl