claude-code - 💡(How to fix) Fix [BUG] Claude Code Desktop crashes with API Error 500 when conversation history contains flag emojis generated by Claude itself [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46805Fetched 2026-04-12 13:32:36
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

Error Message

Related to (but distinct from): #5440 — JSON Serialization Failure: Unicode Surrogate Pair Error Error API Error: 500 {"type":"error","error":{"type":"api_error","message":"Internal server error"},"request_id":"req_011CZvgGUiqEpxeDRKs351Pm"} 4. Claude Code immediately returns API Error 500 on every subsequent request 5. Error persists across app restarts 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.

Root Cause

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.

Fix Action

Fix / Workaround

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.

RAW_BUFFERClick to expand / collapse

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

  1. Ask Claude Code to write a script that scans devices and outputs contact names
  2. Claude generates output containing a contact named "ChrBan Mobil" with a Swedish flag emoji appended
  3. Paste the output back into Claude Code for follow-up questions or debugging
  4. Claude Code immediately returns API Error 500 on every subsequent request
  5. 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.

extent analysis

TL;DR

Properly encode or sanitize Unicode characters, including surrogate pairs from flag emojis, before serializing conversation history to JSON to prevent API Error 500.

Guidance

  • Identify and update the JSON serialization code to handle Unicode surrogate pairs correctly, ensuring that all characters, including flag emojis, are properly encoded.
  • Consider implementing a sanitization step for conversation history output to remove or escape characters that cannot be safely encoded, preventing malformed requests.
  • Review Claude Code's output generation to ensure it does not produce content that it cannot later process, focusing on internal consistency.
  • Test the updated serialization or sanitization logic with various inputs, including those containing flag emojis, to verify the fix.

Example

// Example of properly encoded JSON with a flag emoji
{
  "conversationHistory": "ChrBan Mobil [SE flag emoji: \\ud83c\\udff5\\ud83c\\udd6a] opl=0"
}

Note: The example above illustrates how a flag emoji might be encoded in JSON, but the actual implementation details may vary depending on the specific requirements and constraints of the Claude Code application.

Notes

The provided workaround of manually stripping emojis is not viable, as it places an unreasonable burden on the user. A more robust solution involves updating the application's serialization or sanitization logic to handle Unicode characters correctly.

Recommendation

Apply a workaround by updating the JSON serialization code to properly handle Unicode surrogate pairs, as this is a more targeted and effective solution than relying on users to manually modify the output.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING