Terminal renderer miscalculates line width with ANSI escape codes, causing text corruption on Windows
Bug Report: Terminal renderer miscalculates line width with ANSI escape codes, causing text corruption
Description
Inline code blocks (backticks) and other styled text render incorrectly in the terminal. Text appears shifted, truncated, or wrapped at wrong positions. This appears to be caused by ANSI escape codes being counted as visible characters during line width calculation.
Environment
- Claude Code Version: 2.0.73
- OS: Windows 10/11
- Terminal: Windows Terminal (WT_SESSION present)
- Shell: Git Bash (bash.exe)
- TERM: xterm-256color
Steps to Reproduce
- Run Claude Code in Windows Terminal with Git Bash
- Ask Claude a question that results in a response containing inline code (backticks) with a long path or text
- Example prompt: "Do you see the Schedule.xlsx file in the admin folder?"
- Claude responds with text like:
Yes, I can see **Schedule.xlsx** in the Admin folder at: `D:\Projects\Schedule\Admin\Schedule.xlsx`
Expected Behavior
The path should render correctly on one or two lines with proper wrapping.
Actual Behavior
The text is corrupted:
- Line 1 shows: "Yes, I can see Schedule.xlsx in the Admin folder at:"
- Line 2 shows (with large left indent): "edulars\Admin\Schedule.xlsx"
The beginning of the path ("D:\Projects\Schedule") is missing or pushed off-screen. The continuation line has incorrect indentation.
Bullet lists following styled text also render incorrectly with items appearing fragmented or in wrong positions.
Root Cause Analysis
The terminal renderer appears to count ANSI escape codes (used for inline code styling) as visible characters when calculating line width for wrapping. For example:
- Escape codes like
\x1b[48;5;240m(background color) add ~12 invisible bytes - These are counted in the string length calculation
- This shifts the calculated cursor position
- When text wraps, the continuation appears at incorrect column positions
Evidence
- Issue only affects styled content (inline code, bold, etc.)
- Plain text without markdown formatting renders correctly
- The offset appears proportional to the number of styling codes applied
Workaround
Setting NO_COLOR=1 environment variable before launching Claude Code may disable ANSI styling and avoid the issue (not fully tested).
Additional Context
This issue has been reported by multiple users on Twitter, suggesting it's a widespread problem affecting Windows Terminal users.
Have same issue since today. use windows as well, and Jet Brain Rider ide together with Claude code.
same issue here
Same. Just started happening when I started a new session. Using CC in VS code and tested in Windows CMD just to rule out VS Code. Same results. Missing/partial sentences, lots of extra random whitespaces/lines and line breaks mid-word.
I have the same problem with the Claude Code client for Windows! It's really hard to understand what's written!
Same started happening to me today. I find it's more often happening in Powershell than CMD
same, in windows git bash and macos bash same.
same issue. on v2.0.76