[BUG] Claude Code Desktop crashes with API Error 500 when conversation history contains flag emojis generated by Claude itself
Related to (but distinct from): #5440 — JSON Serialization Failure: Unicode Surrogate Pair Error
Bug Description
Claude Code Desktop becomes completely unusable after the conversation history contains flag emoji characters (e.g. the Swedish flag). The critical aspect of this bug is that the emoji was present in output generated by Claude Code itself — the user did not introduce the emoji manually. Claude generates output it later cannot handle.
Environment
- Platform: Windows (Claude Code Desktop app)
- Trigger: Flag emoji in conversation history
- Source of emoji: Claude-generated code output, not user input
Error
API Error: 500 {"type":"error","error":{"type":"api_error","message":"Internal server error"},"request_id":"req_011CZvgGUiqEpxeDRKs351Pm"}
Steps to reproduce
- Ask Claude Code to write a script that scans devices and outputs contact names
- Claude generates output containing a contact named "ChrBan Mobil" with a Swedish flag emoji appended
- Paste the output back into Claude Code for follow-up questions or debugging
- Claude Code immediately returns API Error 500 on every subsequent request
- Error persists across app restarts
Concrete example from session
Claude-generated output containing: "ChrBan Mobil [SE flag emoji] opl=0"
This output was from a MeshCore BLE scanning script written by Claude Code.
When the output was pasted back to Claude Code, the session became permanently broken.
Root cause (likely)
Flag emojis (e.g. regional indicator symbols like the Swedish flag) are encoded as Unicode surrogate pairs. Claude Code fails to properly serialize these characters into JSON when building the conversation history payload, resulting in a malformed request. This is the same class of issue as #5440 but triggered specifically by flag emoji characters in Claude-generated output — not user-pasted text.
Why this is especially problematic
Claude Code itself generates emoji output in its responses (contact lists, status indicators, UI labels, etc.). If Claude produces output it cannot later process, the user has no way to anticipate or avoid the crash. This is an internal consistency bug: Claude should never generate content that breaks its own session when reflected back in context.
Expected behavior
Claude Code should sanitize or properly encode all Unicode characters — including surrogate pairs from flag emojis — before serializing conversation history to JSON. If a character cannot be safely encoded, it should be escaped or stripped rather than causing a 500 error.
Workaround (unacceptable)
The only current workaround is for users to manually strip emojis from text before pasting it — but since the emoji originates from Claude itself, this places an unreasonable burden on the user to audit Claude's own output. This is not a viable workaround.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗