Skip to content

Windows: Arabic RTL text renders as separated/reordered characters in Codex CLI #34871

Done

Description

@mohilaly

Bug

Arabic text in the Codex CLI TUI on Windows is rendered as separated and reordered characters, making it unreadable.

Environment

  • Codex CLI: 0.145.0
  • OS: Windows
  • Shell: PowerShell with UTF-8 enabled (code page 65001)

Expected behavior

Arabic should render with proper right-to-left direction and joined letter shaping.

Actual behavior

Codex CLI displays the Arabic letters separately and in the wrong order.

Additional context

Arabic renders correctly in Claude Code on the same PC, so this appears specific to the Codex CLI TUI. Screenshot attached.

Activity

  1. added
    bug
    CLI
    windows-os
    TUI
    on Jul 23, 2026
  2. CodeinScrubs commented on Jul 27, 2026

    @CodeinScrubs

    This report combines two related but distinct terminal problems:

    1. bidirectional paragraph ordering/base direction; and
    2. Arabic joining/shaping across terminal cells.

    A blanket string reversal can make one screenshot look better while breaking numbers, punctuation, English identifiers, copy/paste, cursor mapping, styles, and other scripts. The source should remain in logical order, and the final TUI rendering stage needs to account for UAX #9, grapheme/style boundaries, and the capabilities of the terminal/font actually in use.

    Useful regression fixtures should include both:

    مرحبا gpt-5
    React یک کتابخانه جاوااسکریپت بسیار محبوب است.
    

    The second case is important because first-strong auto-detection chooses LTR from React, although the strong-character majority is Persian. Conversely, an RTL-first line whose majority is English should retain an LTR base. Pure ASCII/LTR lines should stay on the current identity path.

    Maintainer disclosure: I maintain BidiLens, an MIT-licensed cross-platform bidi toolkit. Its @bidilens/terminal adapter, ANSI-aware utilities, and 918-fixture corpus can provide detection, isolation, and test evidence, but I would not propose dropping a JavaScript package into this Rust TUI. The right Codex fix should be native to the renderer and should explicitly document terminal/shaping limitations.

    A host-native version of the direction policy is under review in NousResearch/hermes-agent#72508. I would be glad to help translate the fixtures and policy into focused Rust tests/implementation for Codex once maintainers confirm the preferred rendering architecture.

  3. lyesmke-png commented on Sep 9, 2026

    @lyesmke-png

    Additional reproducible evidence from a Windows 10/11 real-world investigation (Codex CLI v0.149.1) suggests the Arabic text itself is generated correctly; the failure appears at the live terminal/TUI rendering stage.

    Evidence:

    • codex exec was run non-interactively with a fixed mixed Arabic + English + digits + punctuation string and stdout redirected to a file.
    • The captured UTF-8 text was byte-for-byte in correct logical Unicode order. This rules out model generation/token corruption.
    • On the same machine and same Windows Terminal, Claude Code renders Arabic correctly while Codex TUI output is visually reordered.
    • A practical compatibility wrapper that buffers stdout until a complete LF-terminated line, then emits the whole line at once, significantly improves the behavior. For mixed RTL/LTR lines, wrapping maximal Latin/digit runs in Unicode directional isolates (LRI U+2066 / PDI U+2069) also stabilizes placement.
    • ANSI/VT sequences can be preserved untouched; non-RTL lines can remain byte-identical.

    This points to a Bidi paragraph/chunk-boundary problem: interactive streaming writes partial fragments, while Unicode Bidi resolution works on complete logical paragraphs/lines. If Codex's renderer/TUI applies or exposes partial fragments incrementally, mixed Arabic/LTR content becomes visually scrambled even though the source text is correct.

    Suggested implementation direction:

    1. Buffer RTL-containing assistant output to complete logical lines/paragraphs before terminal rendering, or perform BiDi on a complete logical buffer rather than per streamed chunk.
    2. Apply directional isolation around embedded LTR code/paths/identifiers.
    3. Keep raw stdout/logging in original logical Unicode order; do not pre-reverse text.

    A second CLI (Kimi) on the same machine showed the same class of behavior, while Claude Code did not, which further suggests output/rendering strategy rather than encoding alone.

  4. CodeinScrubs commented on Sep 9, 2026

    @CodeinScrubs

    The unchanged UTF-8 capture is useful evidence for separating stored/generated text from display behavior in that reproduction. I would keep the line-buffering result as a reproduction clue rather than infer the interactive TUI architecture from redirected stdout alone.

    A small regression matrix could compare the same logical text delivered in one chunk, at every character boundary, and at each newline, including terminal resize/wrapping. It should also cover an English-only identity case, Arabic/Persian with a URL and numbers, and copy/selection offsets. Escaping ANSI controls or reordering stored source would be separate regressions.

    One caveat for the wrapper: LRI/PDI can help only when the terminal/rendering path honors them; they do not provide Arabic shaping. If a TUI performs visual reordering itself, cursor/cell/style mapping and avoiding a second reorder by the terminal also need testing. Could you share the minimal wrapper, exact Windows Terminal version, and a short before/after sample with its input bytes? That would make the reported improvement independently reproducible without assuming a universal fix.

  5. qutaiba73 commented on Oct 24, 2026

    @qutaiba73

    Additional reproduction on Codex CLI 0.164.0, observed October 24, 2026 UTC.

    Environment:

    • Windows, using Windows Terminal (terminal version and active shell version not captured).
    • Codex CLI v0.164.0, visible in the supplied screenshot.
    • Selected model: gpt-6.1-sol, high reasoning.

    Observed behavior:

    1. Enter the Arabic greeting مرحبا in the interactive Codex TUI.
    2. Both the submitted greeting and the Arabic assistant response appear visually reversed/reordered. The input is displayed as ابحرم.
    3. Copy the displayed assistant response and paste it into a browser chat: its Arabic word/character order displays correctly there. This confirms that the copied sample preserves readable logical Arabic despite its incorrect terminal presentation; no raw-byte or session-log inspection was performed.

    The user also reports that Claude Code displays Arabic correctly in the same Windows Terminal, while Codex does not. That comparison is user-reported, not a controlled side-by-side test with recorded terminal settings.

    Expected: Arabic input and assistant output remain readable in the interactive TUI, while copied text retains logical Unicode order and mixed code/identifiers remain intact.

    This corroborates the display symptom on 0.164.0. It does not establish whether the root cause is Codex layout, streaming/chunk boundaries, terminal BiDi behavior, or their interaction. Changing model, font, encoding, or applying a line-buffering wrapper has not been tested in this reproduction.

    Please include the current CLI version in investigation of this existing issue and provide a supported fix or tested workaround. Posting this sanitized report on the affected user's explicit request; no account details, private project contents, or logs are included.

  6. eisharplus commented on Oct 25, 2026

    @eisharplus

    Renderer-side Arabic BiDi prototype: tested on 0.163.0 and ported to 0.164.0

    Adding implementation-level evidence to this existing report, at the affected user's request. Please prioritize a maintainer-owned fix in the official CLI so Arabic-speaking users do not have to maintain and rebuild a local fork after updates. This is a reproduction/design report, following the repository's issues-only contribution policy, rather than an external PR or a claim that the prototype is ready to merge unchanged.

    Environment and observations

    • Windows 11 Home, OS build 10.0.26300.
    • Windows PowerShell 5.1.26100.9711 in Windows Terminal; current terminal executable file version 1.24.2610.01001.
    • Prototype first built for Codex CLI 0.163.0; port/build/test: 0.164.0, tag rust-v0.164.0, commit 6aaac694803004a63c6f393d153c96d22521a6b9.
    • Claude Code and Codex were inspected in tabs of the same Windows Terminal process. UI Automation's visible-text FontName reported Cascadia Mono for both. This is the base font reported by the text provider, not proof of identical per-glyph fallback. Changing the terminal or font was not required for the successful local prototype.
    • Arabic produced by ordinary PowerShell output was readable, while Arabic in the unmodified Codex TUI was visually reordered. Read-only console-buffer inspection also found different sample Arabic word-cell ordering between Claude Code and Codex. This is evidence about observed output, not a claim about Claude Code's internal implementation.

    Minimal reproduction

    In the unmodified interactive CLI, enter Arabic and request these literal output lines without tool use:

    مرحبا بالعالم
    افتح file.rs ثم شغل Codex 123
    مرحبا (بكم)
    مَرْحَبًا
    

    Inspect the submitted input and assistant output. Compare with the same strings written by PowerShell in the same terminal. Expected: readable Arabic ordering/joining, intact Latin identifiers and digits, and original logical Unicode order retained in messages and application state.

    Intervention that worked locally

    The intervention was in the Rust display path, not the model prompt, encoding, terminal settings, or font:

    1. Keep the original ratatui buffers and application text in logical order. Immediately before terminal buffer diffing, build temporary visually reordered rows containing Arabic, using unicode-bidi (0.3.18). Pure LTR rows remain on the existing path.
    2. Reorder grapheme-bearing cells with their styles and wide-cell continuations; use unicode-bidi-mirroring (0.4.0) for punctuation where the resolved level requires it. Do not reverse raw strings or reorder OSC 8 destination bytes.
    3. Map logical cursor positions to visual columns and mouse columns back to logical coordinates. Use the visual buffer for cursor-style repair too.
    4. Apply the same display transformation to finalized scrollback lines and remap hyperlink columns into separate contiguous visual ranges. This avoids accidentally extending a mixed-direction link over neighboring unlinked characters.

    Integration points were custom_terminal.rs (Terminal::flush and draw_with_size), custom_terminal/cursor.rs, insert_history.rs (write_history_line), and mouse-event coordinate handling in app.rs, plus a local display module. The 0.164.0 port preserved the new transcript-image painting flow.

    The local compatibility gate is Windows plus the presence of WT_SESSION. The prototype uses an LTR paragraph base to preserve the existing UI layout; this is a scoped compatibility policy, not a proposed universal paragraph-direction policy or complete terminal capability detector.

    Validation actually performed

    • On 0.163.0, the affected user confirmed readable, connected Arabic both in a renderer preview and in the full patched Codex TUI, using the existing terminal and font.
    • On 0.164.0, the complete patched CLI built successfully. A separate small Rust regression harness imported the modified production renderer files directly; for 0.164.0 it also imported the real transcript-image/protocol modules, without replacing their value types with stubs.
    • All 8 regression tests passed: visual ordering with unchanged logical source; composer cursor placement; mixed Arabic/Latin/digits/punctuation/marks/wide glyphs/borders; streaming growth/shrink redraw; style attachment and mouse mapping; finalized history; discontiguous hyperlink ranges; and cursor positions at the start/middle/end of an Arabic run.
    • The renderer tests use the project's real Crossterm-backed VT100Backend and inspect the resulting terminal grid. They are not screenshots or tests of a duplicated reordering implementation. An initial pre-fix renderer test failed on Arabic order and cursor position.
    • A full CLI smoke test on the staged 0.164.0 package successfully executed Get-Location under the read-only sandbox, with the tool's actual exit code 0. This checks package/tool availability, not Arabic typography.

    Scope requiring upstream review

    This demonstrates a workable display-boundary intervention on the affected Windows setup. It does not establish universal terminal compatibility, complete UAX #9 behavior for every wrapped paragraph, visual arrow-key navigation, accessibility behavior, or correct OS-native clipboard round-trips after visual reordering. Internal source preservation was tested; it should not be conflated with all clipboard/selection behavior. The local patch performs ordering and punctuation mirroring, while the terminal/font engine still supplies Arabic joining/shaping.

    Please consider this evidence when implementing an official renderer-level solution, including a tested terminal capability/direction policy, cursor/selection/clipboard handling, and mixed-script regression coverage. The user specifically requests a supported fix in the distributed CLI rather than recurring local patching, terminal replacement, font changes, or a model-language workaround.

  7. yahyakhalid commented on Oct 31, 2026

    @yahyakhalid

    Building on @lyesmke-png's finding that codex exec output is already in correct logical order: that makes it fixable from the outside today.

    codex exec "..." | npx github:yahyakhalid/termbidi --width auto
    

    Disclosure: I maintain termbidi (MIT). It does UAX #9 reordering per display line plus Arabic joining, wraps before reordering so long lines read top to bottom, and keeps English identifiers, numbers and ANSI colors in place. It doesn't help the interactive TUI. As @CodeinScrubs said, that needs the renderer to reorder after layout. The reordering logic is a single function (toVisual()) if it's useful as a reference for that fix.

  8. Mouhand-Kaddo commented on Nov 8, 2026

    @Mouhand-Kaddo

    On codex-cli 0.167.0 on Linux (raw pty capture against a local mock Responses server, so no Windows terminal is involved), the same Arabic text reaches the terminal in two different forms depending on which path draws it. Finalized history lines go through write_spans in insert_history.rs as one logical-order run that keeps spaces and the bidi controls RLM (U+200F), LRI/RLI/PDI (U+2066/2067/2069) and ALM (U+061C). The composer and the streaming reply go through the ratatui buffer, which drops zero-width graphemes (Buffer::set_stringn in ratatui-core 0.1.2, render_line in ratatui-widgets 0.3.2 Paragraph), so every one of those controls disappears there, and the buffer diff sends the row as fragments at absolute cursor positions, so one streamed word can arrive as two writes (سل, then ام in a later frame). This means an LRI/PDI-based workaround can't reach the composer or streaming text, and a renderer-side fix has to cover both paths and carry those marks itself (harakat and ZWNJ do survive both paths). Repro scripts, the annotated byte capture and links pinned to main (c9b4267) are here: https://gist.github.com/Mouhand-Kaddo/e9cda28acfbee723846362d3d05f76b6

  9. ln6ie commented on Nov 15, 2026

    @ln6ie

    Confirmed on a newer Windows setup: Codex CLI 0.169.0, PowerShell 5.1, UTF-8 input/output and active code page 65001. A non-interactive codex exec request in Arabic returned the expected Arabic text, but the interactive Codex TUI still visually reorders the Arabic reply as shown in my screenshot. This confirms that UTF-8 fixed input/output encoding; the remaining failure is RTL/BiDi rendering in the TUI. The reproduction was in a VS Code integrated PowerShell terminal.

  10. etraut-openai commented on Nov 25, 2026

    @etraut-openai
    Contributor

    Thanks for the bug report. This will be addressed in an upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CLITUIbugwindows-os

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions