claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

RTL (Arabic/Hebrew) text renders reversed in all Claude Code TUI surfaces — assistant messages, tool-result previews, and live input

Open Kimoo193 opened this issue 3 months ago • 5 comments

Environment

  • Claude Code 2.1.245
  • Terminal: Warp
  • OS: Linux Mint 22.3 (kernel 7.0.0-28-generic)

Summary RTL text (tested with Arabic) is not bidi-reordered anywhere in Claude Code's own terminal rendering. Confirmed in three distinct surfaces, all drawn by Claude Code itself:

  1. Assistant message text — when Claude's own response includes Arabic (e.g. quoting a test string back to the user), it renders reversed in the transcript, even though the underlying string is correct (verified by writing the same string to a file and reading it back with an external bidi-aware tool — see comparison below).
  2. Tool-result file preview — inline preview of file content (e.g. from the Write tool) containing Arabic renders reversed, even though the file's actual bytes on disk are correct.
  3. Live input box — typing Arabic directly into the prompt renders it reversed character-by-character in real time, before submission.

Repro

  1. Ask Claude Code to include an Arabic sentence in its reply, or to write one to a file and quote it back. Observe the Arabic renders reversed in the assistant's message.
  2. Have Claude Code write that Arabic sentence to a file via the Write tool; observe the inline tool-result preview also renders it reversed.
  3. Type any Arabic sentence directly into the prompt; observe it renders reversed live as you type, before you even submit.
  4. Comparison (proves the data is fine, only Claude Code's rendering is wrong): read the same file's raw content afterward via a plain external command, outside Claude Code's TUI (e.g. cat file.txt, or piped through fribidi -c UTF-8 for full bidi correctness). The text displays correctly there — confirming the bug is isolated to Claude Code's own rendering paths, not the terminal (Warp) globally and not the underlying data.

Related existing reports: #34134 (closed not-planned), #38656, #45652, #48559, #29545, #29575, #29662, #29710, #75240 — this report's contribution is isolating that it's all three TUI-internal surfaces (not just one), plus a working comparison case proving the file data itself is correct and only Claude Code's own text rendering is at fault.

Suggested direction: apply the Unicode Bidirectional Algorithm to text before rendering in the message/transcript renderer, the tool-result preview renderer, and the input line editor — all three appear to share the same missing step.

Screenshots to follow in a comment.

Kimoo193 avatar Aug 25 '26 10:08 Kimoo193

Same bug in a second environment.

Environment

  • Claude Code 2.1.296
  • Terminal: VS Code integrated terminal (xterm.js, TERM_PROGRAM=vscode)
  • OS: Ubuntu, GNOME on X11

What happens Arabic in assistant replies and in plain print output shows reversed, with the letters not joined. The strings themselves are correct logical-order Unicode. For example, this prints a string whose first character is U+0627 (the first letter of the first word), and the terminal draws it mirrored:

python3 -c "print('استرجاع إلى المراجعة')"

Cause xterm.js has no bidi support (xtermjs/xterm.js#701, open since 2017), so the TUI cannot rely on the terminal to reorder RTL runs. Having Claude Code reorder RTL runs itself on terminals that do no bidi, together with an opt-out for terminals that do (the BDSM proposal in #99046), would cover both this case and the iTerm2 one.

sandiprv9898 avatar Oct 12 '26 11:10 sandiprv9898

Same defect on Windows, with a case this issue does not cover yet: Markdown tables.

Environment

  • Claude Code 2.1.312
  • Windows 10, Windows Terminal, PowerShell tab

What happens

When a table row contains an Arabic word and the first strongly directional character of the row is Arabic (the leading #0 and 33 x 20 are neutral for the bidi algorithm), the whole row is drawn mirrored:

  • the numbers inside a cell swap order: 33 x 20 is shown as 20 x 33. The rendering does not only break the layout, it changes the data;
  • the cells come out in reverse order, so the first column ends up on the right;
  • the | separators no longer line up with the table frame;
  • paired punctuation is flipped: (Masquer) becomes )Masquer(.

Rows of the same table without Arabic render normally, which breaks the grid. In plain paragraphs, a line that contains an Arabic word also gets its tail moved to the front.

Image

In this capture, the source rows were | #0 | 33 x 20 | ... |, | #1 | 81 x 41 | ... | and | #9 | 40 x 18 | ... |: all three come out mirrored, with their sizes reversed. The last row has no Arabic in its first cells and renders normally.

Repro

Ask Claude Code to print this table verbatim:

| Region | Size | Read |
|---|---|---|
| #0 | 33 x 20 | أخف (Masquer) |
| #1 | 81 x 41 | button with an icon |

Row #0 is drawn mirrored, row #1 is not.

Comparison outside Claude Code

In the same Windows Terminal tab, python -c "print('| #0 | 33 x 20 | أخف (Masquer) |')" prints the row correctly. The text is right and the terminal does not flip it: the defect is in Claude Code's rendering, as in the comparison in the opening post.

julienmerconsulting avatar Oct 29 '26 22:10 julienmerconsulting

Until there's a fix in the TUI, a workaround for non-interactive output: pipe it through a bidi filter.

claude -p "..." | npx github:yahyakhalid/termbidi

Disclosure: I wrote termbidi after hitting this issue. It applies UAX #9 reordering per display line, joins Arabic letters, keeps ANSI colors, and leaves text alone in terminals that already reorder (iTerm2 3.7+, Konsole, mintty, VTE), so it doesn't cause the double flip from #99046.

It can't fix the interactive TUI or the input box from outside; a pipe can't touch text that's already been positioned with cursor moves. For that, the reordering has to happen inside the renderer, after line width is decided and before writing. The library exposes toVisual() for that step. It's MIT, so the team can reuse it or just take the approach.

yahyakhalid avatar Oct 31 '26 21:10 yahyakhalid

+1 from a Persian (Farsi) user on macOS, Claude Code 2.1.319.

Persian replies in the terminal CLI still render with broken bidi ordering and left alignment, and the prompt input is LTR-only. This is the same regression as #64730 (RTL paragraphs right-aligned in 2.1.132, left-aligned since 2.1.138), which was auto-closed as inactive and is now locked, so I'm adding it here.

Changing terminals doesn't fix it (Terminal.app, iTerm2 3.6 experimental RTL, WezTerm), because the reordering and alignment come from the Ink renderer. A setting like textDirection: "auto", or at least restoring the 2.1.132 behaviour, would make the CLI usable again for RTL users.

saberm-780 avatar Nov 06 '26 15:11 saberm-780

Working setup for Persian/Arabic in the Claude Code CLI on macOS (WezTerm)

Tested with Claude Code 2.1.327. In an earlier comment I said WezTerm didn't help. It does once these three things are set:

  1. CLAUDE_CODE_ALT_SCREEN_FULL_REPAINT=1 in the env block of ~/.claude/settings.json:

    { "env": { "CLAUDE_CODE_ALT_SCREEN_FULL_REPAINT": "1" } }
    

    This fixes the main problem: RTL text that renders fine at first, then turns up reversed with disconnected letters as the session scrolls. Claude Code's fullscreen renderer scrolls with a scroll region plus scroll-up (ESC[t;br + ESC[nS). WezTerm doesn't apply bidi to the lines that this creates, so text written into them is drawn left to right with every letter isolated. Minimal repro in plain WezTerm, no Claude Code involved:

    printf '\e[2J\e[1;1Hnormal: سلام دنیا\e[3;8r\e[3S\e[r\e[7;1Hafter SU: سلام دنیا\n'
    

    The first line renders correctly and the second comes out reversed with isolated letters. With full repaint on, Claude Code sends no ESC[nS (checked in a script -F recording). Persian then stayed correct after long scrolling output.

  2. A recent WezTerm nightly (tested with 20261112-061903-ce8e6b14). Stable 20240203 doesn't mirror a closing bracket after a number, so (نسخه ۲.۱.۳۲۷) comes out as )…). The nightly draws it correctly. The nightly still has the scroll bug from step 1, so you need both.

  3. A monospaced Persian font and bidi settings in ~/.config/wezterm/wezterm.lua. Vazir Code gives each letter exactly one cell; proportional fonts leave gaps between letters. The "WOL" build contains no Latin glyphs, so English stays in your main font.

    config.font = wezterm.font_with_fallback { 'JetBrains Mono', 'Vazir Code Extra Height WOL', 'Vazirmatn' }
    config.bidi_enabled = true
    config.bidi_direction = 'AutoLeftToRight'
    

What this does not fix:

  • Terminal.app: it reorders RTL lines itself, and that breaks Claude Code's cursor math, so the layout gets corrupted (#95667).
  • The prompt input box: it is still left-aligned.

Related: #6751 (Windows workaround with Git Bash/mintty; locked), #89489, #37183.

saberm-780 avatar Nov 17 '26 22:11 saberm-780