Back to feed
Dev.to
Dev.to
6/29/2026
"Claude Code '400: no low surrogate in string' on every turn: repairing a permanently broken session transcript"

"Claude Code '400: no low surrogate in string' on every turn: repairing a permanently broken session transcript"

Short summary

Claude Code sessions can be permanently broken by UTF-16 surrogate bytes orphaned in transcript files when truncation cuts between surrogate pair halves, causing '400: no low surrogate in string' errors on every API call. The fix strips lone surrogates from the affected JSONL line using Python string filtering; a byte-level pre-filter (scanning for \ud escapes or raw UTF-8 surrogate encoding ED A0–BF) enables fast automatic repair at session start.

  • UTF-16 surrogate corruption occurs when large emoji-heavy content is truncated mid-pair, orphaning one half of a character encoding
  • The fix walks the affected transcript line, filters out orphaned surrogates (U+D800–U+DFFF), and re-serializes the JSON
  • A cheap byte-level pre-filter (1.1s vs 3.4s) makes automatic repair feasible at session start for content-heavy projects

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more