[BUG] Invalid Unicode in Edit tool results causes 400 'invalid JSON' API errors
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
- Use Edit tool on a large file (~24KB) with Unicode characters
- Tool result is stored in conversation .jsonl
- Next API request fails with "invalid JSON" error
- 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
- Use Edit tool on a large file (~24KB) with Unicode characters
- Tool result is stored in conversation .jsonl
- Next API request fails with "invalid JSON" error
- 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
Found 3 possible duplicate issues:
- https://github.com/anthropics/claude-code/issues/1709
- https://github.com/anthropics/claude-code/issues/5934
- 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
Do you know any specific character that causes problems?