Syntax highlighting colors offset/misaligned in Windows Terminal (CRLF line ending issue)
Description
Syntax highlighting colors are offset from the text they should highlight in Windows Terminal. The offset accumulates progressively (~1 character per line), making code blocks increasingly unreadable.
Environment
- Claude Code v2.1.19
- Windows Terminal (dark theme)
- Windows 10/11
Analysis
The offset appears related to Windows line endings (\r\n). Each newline adds ~1 character of drift, suggesting the carriage return (\r) is being counted in width calculations but not rendered.
Observed behavior:
- First highlighted line: off by ~4 characters
- Subsequent lines: drift increases (~1 char per line)
- XML tags like
<Patterns>have colors bleeding past tag boundaries - Blue highlighting for tag names spans incorrect character ranges
Technical Investigation
@shcv performed a detailed analysis: https://gist.github.com/shcv/cc30c3b32e928ac48f48de4335a4280b
Root cause: In pretty-v2.1.19.js, control characters like \r may be counted as having display width during tokenization, while the terminal correctly renders them as zero-width. This causes cursor positioning to drift during differential rendering.
Proposed fixes:
- Treat control characters (code ≤ 31) as zero-width in width calculations
- Normalize
\r\nto\nbefore syntax highlighting
Screenshots
<img width="1121" height="220" alt="Image" src="https://github.com/user-attachments/assets/418e30a1-6bed-48b2-b315-1e48b6d2fa8e" />
<img width="1674" height="1170" alt="Image" src="https://github.com/user-attachments/assets/95929f7f-290a-46d1-a85e-b11c702fa8b3" />
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗