claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Terminal renderer miscalculates line width with ANSI escape codes, causing text corruption on Windows

Open DoctorFrankie opened this issue 1 month ago • 8 comments

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

  1. Run Claude Code in Windows Terminal with Git Bash
  2. Ask Claude a question that results in a response containing inline code (backticks) with a long path or text
  3. Example prompt: "Do you see the Schedule.xlsx file in the admin folder?"
  4. 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.

DoctorFrankie avatar Dec 19 '25 16:12 DoctorFrankie

Have same issue since today. use windows as well, and Jet Brain Rider ide together with Claude code.

weto4ka avatar Dec 19 '25 16:12 weto4ka

same issue here

cjteams avatar Dec 19 '25 16:12 cjteams

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.

Burtrola avatar Dec 19 '25 16:12 Burtrola

I have the same problem with the Claude Code client for Windows! It's really hard to understand what's written!

gigios avatar Dec 19 '25 16:12 gigios

Same started happening to me today. I find it's more often happening in Powershell than CMD

Skeletoneyes avatar Dec 20 '25 02:12 Skeletoneyes

same, in windows git bash and macos bash same.

TNYCL avatar Dec 20 '25 09:12 TNYCL

same issue. on v2.0.76

DanSandoval avatar Dec 24 '25 16:12 DanSandoval