[BUG] API 400 "invalid high surrogate" when context contains box-drawing or emoji Unicode chars from hooks/skills
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?
Claude Code throws API Error 400 "invalid high surrogate in string" when the accumulated context contains non-ASCII Unicode characters (box-drawing U+2500-257F, emojis U+26xx/U+1Fxxx, circled numbers U+2460+, etc.) from hook outputs or skill files.
The error is in JSON serialization of the API request body, not in the files themselves -- these are valid Unicode codepoints.
What Should Happen?
Valid Unicode characters (box-drawing, emojis, etc.) in hook outputs, skill files, and read file contents should be properly JSON-serialized without causing "invalid high surrogate" errors. All Write/Edit tool calls should succeed regardless of Unicode content in the accumulated context.
Error Messages/Logs
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON: invalid high surrogate in string: line 1 column 80287 (char 80286)"}}
Steps to Reproduce
- Create a PostToolUse hook (.claude/hooks/) with box-drawing chars in its output:
e.g. print("+=====+======+") using U+2550 (═) instead of ASCII =
- The hook runs on every tool call, accumulating output in context
- After several tool calls, any Write/Edit tool call fails with:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error",
"message":"The request body is not valid JSON: invalid high surrogate in string: line 1 column XXXXX"}}
- Reading a PNG image file also triggers it (base64 image data in context)
The error position varies (e.g. column 80287, 151370) depending on how much context has accumulated.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.86 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗