[BUG] Code blocks with RTL text (Hebrew/Arabic) render LTR — bidi layout is broken

Resolved 💬 3 comments Opened Jun 2, 2026 by KirJaff-commits Closed Jul 6, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When a fenced code block contains right-to-left text (Hebrew, Arabic, …), the
block is rendered with LTR direction and left alignment. Neutral characters
(digits, ".", ":", "(", ")", "-") are placed by LTR bidi rules, so list numbers
and punctuation end up on the wrong side and the text is hard to read / easy to
misread.

Repro:

  1. Put Hebrew text inside a ``` fenced code block.
  2. Observe lines are left-aligned and neutral chars are positioned per LTR bidi.

Expected:
RTL content should render right-aligned with correct bidi ordering, while real
(LTR) code stays unaffected.

Suggested fix:
Set dir="auto" on the <pre>/<code> elements (or per line). The Unicode bidi
algorithm then picks direction from the first strong character — non-invasive
for LTR code.

Context / why it matters:
We deliberately use fenced code blocks to paste Hebrew messages, because the
chat's normal rendering mangles mixed Hebrew+English. But the code block itself
is LTR-aligned, so the workaround still looks wrong.

<img width="921" height="610" alt="Image" src="https://github.com/user-attachments/assets/090bd4de-f891-4a5f-9528-1a5deb90adb4" />

What Should Happen?

Expected:
RTL content should render right-aligned with correct bidi ordering, while real
(LTR) code stays unaffected.

Suggested fix:
Set dir="auto" on the <pre>/<code> elements (or per line). The Unicode bidi
algorithm then picks direction from the first strong character — non-invasive
for LTR code.

Context / why it matters:
We deliberately use fenced code blocks to paste Hebrew messages, because the
chat's normal rendering mangles mixed Hebrew+English. But the code block itself
is LTR-aligned, so the workaround still looks wrong.

Error Messages/Logs

Steps to Reproduce

<img width="921" height="610" alt="Image" src="https://github.com/user-attachments/assets/237b7482-3392-47cb-995d-3cd9949a9800" />

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.1.160 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

<img width="921" height="610" alt="Image" src="https://github.com/user-attachments/assets/23fa2645-1d9c-43e1-895b-83a3d983eb07" />

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗