Codex Smart Bidi
A standalone VS Code extension that improves Persian, Arabic, and English text direction in Codex conversations.
If a paragraph contains even one Persian or Arabic letter, it is displayed right to left (RTL), including when its first word is English. Paragraphs without Persian or Arabic letters are displayed left to right (LTR). Detection checks the entire paragraph rather than relying on dir="auto", which can incorrectly select LTR when mixed text starts with an English word.
Examples
Use these examples as ordinary conversation text. Code blocks always remain LTR; code formatting in this guide only shows the exact sample text.
| Sample conversation text |
Direction |
Why |
API: لطفاً خطای ورود کاربر را بررسی کن. |
RTL |
The first word is English, but the paragraph contains Persian letters. |
Version 2.4 آمادهٔ انتشار است. |
RTL |
A version number and an English opening do not override the Persian text. |
README.md: أضف خطوات تشغيل المشروع. |
RTL |
The filename comes first, but Arabic letters make the paragraph RTL. |
The API returns HTTP 401 when the token expires. |
LTR |
There are no Persian or Arabic letters. |
Release 2.4 — ۲۰۲۶/۱۱/۲۷ |
LTR |
Persian digits alone do not change the text direction. |
For independent plain-text lines in one read-only message:
Build: پروژه با موفقیت ساخته شد.
All 24 tests passed.
Next: فایل تنظیمات را بررسی کن.
The first and third lines are RTL. The middle line stays LTR. Separate paragraphs are also evaluated independently: an English paragraph does not become RTL because the previous paragraph contains Persian.
The Persian and Arabic text above consists of sample content for direction detection. All extension descriptions, instructions, commands, settings, and notifications are in English.
Installation
- If Codex RTL Helper or Codex RTL Full is installed, first run that extension's Restore or Disable command to restore the Codex files. Then disable the extension and its automatic patching. Disabling an extension alone does not remove changes it previously made to Codex files. If restoration fails, reinstall Codex after disabling the previous RTL extensions.
- Install Codex Smart Bidi by Edris Ahani from the VS Code Extensions view. For manual installation, open the Command Palette with
Ctrl+Shift+P, run Extensions: Install from VSIX..., and select dist/codex-smart-bidi-0.1.3.vsix.
- Run
Codex Smart Bidi: Apply / Reapply, then Developer: Reload Window to load the updated Codex view.
After the Marketplace release is available, you can also install from a terminal:
code --install-extension EdrisAhani.codex-smart-bidi
To install a downloaded VSIX instead:
code --install-extension .\dist\codex-smart-bidi-0.1.3.vsix
Usage
Automatic activation is enabled by default. The extension applies its patch when VS Code starts and after Codex extension updates. Reload the window after a patch is applied so the Codex view uses the updated files.
A clickable Codex Smart Bidi item appears on the right side of the bottom Status Bar:
- Check icon +
Bidi: On: automatic patching is enabled. Click to disable it and restore the Codex files.
- Circle-slash icon +
Bidi: Off: automatic patching is disabled. Click to enable it and apply the patch.
(Reload) suffix: files have changed, and the Codex view needs a window reload. Choose Reload Window in the notification or run Developer: Reload Window from the Command Palette.
- Spinning icon: a change is in progress. The status bar click action is temporarily unavailable.
- Warning icon +
Bidi: Error: the last operation failed. Hover over the item for the error; resolve the cause and click to retry. A failed enable/disable operation is not reported as a successful state change.
The On/Off label describes the configured state; (Reload) means that the current Codex view may still be using the previous state. Your preference is saved across VS Code restarts. If the item is hidden, make sure View: Toggle Status Bar Visibility is enabled and Codex Smart Bidi is checked in the Status Bar's right-click menu.
The same actions are available in the Command Palette:
| Command |
Action |
Codex Smart Bidi: Toggle On / Off |
Switch between enabled and disabled, just like clicking the Status Bar item. |
Codex Smart Bidi: Apply / Reapply |
Enable automatic patching and apply or repair the local patch. Reload the window afterwards. |
Codex Smart Bidi: Restore Codex Files |
Remove this extension's patch and turn off automatic patching. Reload the window afterwards. |
Codex Smart Bidi: Show Status |
Show the Codex version, enabled state, patch state, conflicts, and backup location in the Output panel. |
You can also change codexSmartBidi.enabled in VS Code Settings. It defaults to true. Turning it off removes this extension's patch; reload the window to finish disabling it.
Direction rules and limitations
- Paragraphs, headings, table cells, and list items are evaluated independently.
- In read-only plain text, lines separated by a newline or
<br> are evaluated independently. A visual line wrap caused by the window width is part of the same paragraph.
- Links, bold text, and inline code retain their formatting. A paragraph containing inline formatting is evaluated as a whole; line breaks within that formatted paragraph are not evaluated separately. Use separate paragraphs when independent directions are needed.
- In rich text editors, each paragraph has its own direction. The editor's text and internal structure are preserved. A native textarea uses one direction for the entire input; this extension does not assign a separate direction to each textarea line.
- Code blocks and inline code remain LTR. The extension does not reverse the overall application layout, menus, or buttons.
- Detection uses Unicode letter properties. Persian digits, Arabic punctuation, or standalone combining marks do not trigger RTL. This extension targets Persian and Arabic; Hebrew alone does not trigger RTL.
- Streamed responses and input changes are tracked through a MutationObserver and input events. During IME composition, processing waits until composition finishes.
How it works
Development compatibility reference: openai.chatgpt 26.1120.50957 on Windows. This unofficial extension adds two local JavaScript/CSS assets to webview/assets and inserts a marked block into webview/index.html. It leaves the original application bundles, language settings, and Content Security Policy unchanged. Its external script loads from the webview's allowed local resource path.
Before applying the patch, the extension saves an HTML backup in its global storage directory, using a SHA-256 hash as the filename. Restoration removes only this extension's marked block and its two assets, preserving unrelated changes made later.
Run Codex Smart Bidi: Restore Codex Files and reload the window before uninstalling. Uninstalling the VS Code extension alone does not remove the local patch.
Future Codex versions may change the HTML structure or selectors and require a compatibility update.
Privacy
Direction detection runs locally on the DOM inside the Codex webview. Conversation text is not saved to disk or sent to an external service by this extension. The extension makes no network requests. Backups contain the webview HTML file, not conversation content.
Development and verification
Node.js 20+ and PowerShell are sufficient. No dependency installation is required.
npm test
npm run package
Tests cover Unicode detection, repeatable patching and restoration, preservation of unrelated changes, rejection of conflicting patches, status bar toggling and settings persistence, failure handling, browser payload syntax, and real DOM behavior in headless Chrome or Edge. The browser test is skipped if neither browser is found in the default Windows installation paths. Set SMART_BIDI_BROWSER to use a different browser executable.
Press F5 in this project to launch an Extension Development Host.
Headless browser and simulated extension-host checks do not replace final verification in VS Code. After installation, check the Status Bar toggle, reload after changing the state, and check the examples above, a message with several paragraphs, a streamed response, and Persian/English editor input in Codex.
References: VS Code Webview API, VS Code extension manifest, VS Code Status Bar guidelines.