TUI layout scrambled by terminal bidi reordering (iTerm2 3.7); please opt out via BDSM (CSI 8 l) and reorder RTL runs yourself
Environment: Claude Code 2.1.287, iTerm2 3.7.3 with right-to-left support on (the default), macOS 27.
What happens: markdown tables and prose containing Hebrew render broken. Letters land out of order and spaced apart, table borders shift on Hebrew rows, and English lines that contain Hebrew lose their first letter to a gap ("T he table...").
Why: Claude Code writes RTL text in logical order and positions every cell itself, assuming left-to-right. A bidi-capable terminal then runs the Unicode bidi algorithm over each whole row and moves cells Claude Code already placed. #89489 is the inverse case: a terminal with no reordering, where RTL appears reversed.
Fix: iTerm2 added the standard opt-out on 2026-09-30 (gnachman/iTerm2 91411f5, in the 20261001 nightly): BDSM, CSI 8 l / CSI 8 h (ECMA-48, terminal-wg bidi recommendation). Proposed:
- At startup, query
CSI 8 $ p. If the terminal replies8;1 $ yor8;2 $ y, sendCSI 8 l, and sendCSI 8 hon exit and when suspending. - Only in that case, or on a terminal known to do no bidi (the #89489 case), reorder each line's RTL runs into visual order before writing it. Table borders and column separators stay fixed.
- Otherwise, leave output as it is today. A terminal that reorders on its own but lacks BDSM (iTerm2 3.7.3) would otherwise reverse the text twice.
We verified this as a local patch to Claude Code 2.1.287. On the iTerm2 nightly, the query returned 8;1, and with explicit mode plus pre-reordering, Hebrew tables and mixed lines rendered correctly.