claude-code - 💡(How to fix) Fix claude --resume fails with 400 'no low surrogate in string' when session JSONL contains truncated emoji [1 comments, 2 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#56064Fetched 2026-05-05 05:59:08
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

claude --resume fails with a 400 from the API when the session JSONL contains an orphan UTF-16 high surrogate. The corruption appears to be introduced when a string (in my case a <tool_use_error> payload) is truncated for length and the truncation cuts through the middle of a surrogate pair, leaving a lone \ud83d with no following low surrogate.

Once written to the session file, the session is permanently un-resumable until the file is hand-edited.

Error Message

API Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"The request body is not valid JSON: no low surrogate in string: line 1 column 347010 (char 347009)\"},\"request_id\":\"req_011CahqzdVKLuc7m72gTAz6x\"}

Root Cause

Root cause (confirmed)

Fix Action

Workaround

Strip lone high surrogates from the offending line in ~/.claude/projects/<dir>/<session>.jsonl:

import re
pat = re.compile(r'\\\\u[dD][89aAbB][0-9a-fA-F]{2}(?!\\\\u[dD][cCdDeEfF][0-9a-fA-F]{2})')
# apply pat.sub('', line) to the bad line, rewrite file

After this the session resumes normally.

Code Example

API Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"The request body is not valid JSON: no low surrogate in string: line 1 column 347010 (char 347009)\"},\"request_id\":\"req_011CahqzdVKLuc7m72gTAz6x\"}

---

\\\\*[🌤💼🏆📉🎯🚀🔥\ud83d…) errored</tool_use_error>

---

import re
pat = re.compile(r'\\\\u[dD][89aAbB][0-9a-fA-F]{2}(?!\\\\u[dD][cCdDeEfF][0-9a-fA-F]{2})')
# apply pat.sub('', line) to the bad line, rewrite file
RAW_BUFFERClick to expand / collapse

Summary

claude --resume fails with a 400 from the API when the session JSONL contains an orphan UTF-16 high surrogate. The corruption appears to be introduced when a string (in my case a <tool_use_error> payload) is truncated for length and the truncation cuts through the middle of a surrogate pair, leaving a lone \ud83d with no following low surrogate.

Once written to the session file, the session is permanently un-resumable until the file is hand-edited.

Error

API Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"The request body is not valid JSON: no low surrogate in string: line 1 column 347010 (char 347009)\"},\"request_id\":\"req_011CahqzdVKLuc7m72gTAz6x\"}

Root cause (confirmed)

In the offending session file, a single line contained:

\\\\*[🌤💼🏆📉🎯🚀🔥\ud83d…) errored</tool_use_error>

The \ud83d is the high half of a surrogate pair (the leading code unit for an emoji like 🟢/🔥/etc.) with no following \uDCxx-\uDFxx low surrogate. The ellipsis right after it strongly suggests the original string was truncated mid-pair by length, not by codepoint.

When the CLI later sends that line back to the API as part of --resume, the JSON deserializer rejects the orphan surrogate.

Repro hint

Trigger any tool call whose error payload contains emoji and is long enough to hit whatever truncation cap is applied to tool_use_error strings. If the cap lands inside a 4-byte UTF-8 character (i.e. inside a surrogate pair when re-encoded as \uXXXX), the session file becomes unresumable.

Suggested fix

Truncate on codepoint / grapheme boundaries rather than raw UTF-16 code units, or sanitize lone surrogates before writing the JSONL line. Either prevents the corruption at the write side. A defensive sanitize at read/resume time would also let already-corrupted sessions recover.

Workaround

Strip lone high surrogates from the offending line in ~/.claude/projects/<dir>/<session>.jsonl:

import re
pat = re.compile(r'\\\\u[dD][89aAbB][0-9a-fA-F]{2}(?!\\\\u[dD][cCdDeEfF][0-9a-fA-F]{2})')
# apply pat.sub('', line) to the bad line, rewrite file

After this the session resumes normally.

Environment

  • Claude Code CLI, Opus 4.7
  • macOS (Darwin 24.6.0)
  • Session file: ~17 MB JSONL, 6131 lines, single bad line at 6101

extent analysis

TL;DR

Truncating strings on codepoint or grapheme boundaries instead of raw UTF-16 code units can prevent session corruption.

Guidance

  • Identify and adjust the string truncation logic to handle Unicode characters correctly, ensuring that truncation does not split surrogate pairs.
  • Sanitize lone surrogates before writing JSONL lines to prevent corruption.
  • As a temporary workaround, manually remove lone high surrogates from corrupted session files using a regular expression.
  • Verify the fix by testing tool calls with error payloads containing emojis and checking if the session remains resumable.

Example

import re
def sanitize_lone_surrogates(line):
    pat = re.compile(r'\\\\u[dD][89aAbB][0-9a-fA-F]{2}(?!\\\\u[dD][cCdDeEfF][0-9a-fA-F]{2})')
    return pat.sub('', line)

Notes

The provided workaround is specific to the identified issue and may not cover all possible corruption scenarios. A more comprehensive solution would involve modifying the string truncation logic to handle Unicode characters correctly.

Recommendation

Apply workaround: manually remove lone high surrogates from corrupted session files until a permanent fix is implemented to handle string truncation correctly.

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

claude-code - 💡(How to fix) Fix claude --resume fails with 400 'no low surrogate in string' when session JSONL contains truncated emoji [1 comments, 2 participants]