Syntax highlighting misalignment with Cyrillic (non-ASCII) characters in terminal
Description
Syntax highlighting colors are visually shifted/misaligned when the output contains Cyrillic (and likely other multi-byte UTF-8) characters. The ANSI color escape codes appear to be inserted at incorrect character positions, causing colors to "bleed" across token boundaries.
Environment
- Claude Code version: 1.0.34 (claude.exe, Windows)
- Terminal: Windows Terminal
- Font: Cascadia Mono (monospace, good Unicode support)
- OS: Windows 11
Steps to Reproduce
- Run
claudein Windows Terminal - Ask Claude to output any text that mixes Cyrillic text with fenced code blocks (even if the code blocks contain only ASCII)
- Observe that syntax highlighting colors inside code blocks are shifted
Expected Behavior
Syntax highlighting colors should align correctly with their corresponding tokens regardless of whether surrounding text contains non-ASCII characters.
Actual Behavior
Colors are offset from their intended positions. For example, in a JavaScript code block, the keyword color might start in the middle of a variable name instead of at the keyword boundary. The shift appears proportional to the number of multi-byte characters preceding the code block.
Screenshots
Code blocks with Cyrillic text nearby:
The highlighting is visibly broken — colors bleed across token boundaries.
<img width="829" height="509" alt="Image" src="https://github.com/user-attachments/assets/1f56e59f-0c3b-4c0b-8236-420a0aa4ef57" />
Note: Screenshots were taken during the debugging session but cannot be attached programmatically. The issue is easily reproducible with the steps above.
Analysis
After investigating the minified source code in the Claude Agent SDK (cli.js):
- highlight.js is used for syntax highlighting — it generates HTML spans for tokens
- The stringWidth calculation correctly treats Cyrillic as width 1 (narrow) — the bug is NOT there
- Cyrillic characters (U+0400–U+04FF) are classified as ambiguous width in the Unicode East Asian Width tables
- The likely root cause is in the conversion layer between highlight.js HTML output and ANSI terminal escape codes, where byte offsets vs character indices may be confused for multi-byte UTF-8 characters
The issue reproduces in both Windows Terminal and VS Code integrated terminal, confirming it's in Claude Code's rendering layer, not the terminal emulator.
Workaround
None found. The binary is compiled and the JS source is minified/bundled, so local patching is not feasible.
🤖 Generated with Claude Code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗