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

[BUG] Random colored text fragments in terminal output

Open i-dedova opened this issue 10 months ago • 1 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Environment

  • OS: Windows 11
  • Claude Code version: 2.1.3
  • VS Code version: 1.108.0
  • PowerShell versions tested:
    • Windows PowerShell 5.1.26100.7462
    • PowerShell 7.5.4
  • Terminal apps tested:
    • VS Code integrated terminal
    • Windows Terminal
    • Standalone PowerShell windows

Description

When running a Claude Code session, terminal output displays random colored text fragments. Certain words or parts of words appear in blue/purple colors while the surrounding text remains white. This happens throughout Claude's responses in a seemingly random pattern.

The colored fragments appear to be regular words from Claude's responses, not error messages or special output. The coloring makes responses visually distracting and harder to read.

Additional Context

  • Issue persists across all terminal applications (not specific to VS Code)
  • Happens with both PowerShell 5.1, PowerShell 7 and Windows PowerShell, Command Line.
Image
  • Problem occurs only when Claude Code is actively running
  • Disabling all Claude Code hooks and statusline configuration does not resolve the issue
  • The colored fragments are actual words from responses, not ANSI escape codes or error messages

What Should Happen?

All terminal text output should display in consistent, uniform color (typically white/default terminal color for normal text).

Error Messages/Logs


Steps to Reproduce

  1. Start a Claude Code session: claude
  2. Have a conversation with Claude (any topic)
  3. Observe Claude's text responses in the terminal

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.3

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

No response

i-dedova avatar Jan 10 '26 13:01 i-dedova

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2780
  2. https://github.com/anthropics/claude-code/issues/14720
  3. https://github.com/anthropics/claude-code/issues/17050

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Jan 10 '26 13:01 github-actions[bot]

Same here in 2.1.5 Opus on Windows 11 via standard Command Prompt.

Image

jasonftl avatar Jan 12 '26 08:01 jasonftl

me too.

I reported https://github.com/anthropics/claude-code/issues/20459 but I closed it because this one is older. I linked mine though so you can see details about my computer and versions.

also here is my screen shot

Image

and another:

Image

TomzBench avatar Jan 23 '26 21:01 TomzBench

Same on v2.1.23 I am using the native installer on Windows. Not the node based installer. I have a coworker that still uses WSL who does not see this behavior.

sbrockway avatar Jan 29 '26 18:01 sbrockway

This is how it looks in my Windows Terminal. Very annoying.

Image

Alexbits avatar Jan 29 '26 20:01 Alexbits

Root Cause Found & One-Line Fix

Full analysis posted at https://github.com/anthropics/claude-code/issues/14720#issuecomment-3857905322

TL;DR: The bug is in the IP5 function in cli.js. When word-wrapping consumes spaces at line breaks, the style-position tracker $ falls behind by 1 per wrap. This accumulates, shifting all ANSI highlighting rightward over long paragraphs.

The fix: search cli.js for z&&_.length>0 (exactly one match, in the IP5 function). Remove the z&&:

// Before (whitespace correction only runs in trim mode):
if(z&&_.length>0){let W=/\s/.test(_[0]);if($<Y.length&&/\s/.test(Y[$])&&!W)while($<Y.length&&/\s/.test(Y[$]))$++}

// After (whitespace correction runs in all wrap modes):
if(_.length>0){let W=/\s/.test(_[0]);if($<Y.length&&/\s/.test(Y[$])&&!W)while($<Y.length&&/\s/.test(Y[$]))$++}

Tested on 2.1.33, completely eliminates the prose highlighting drift. Code blocks are unaffected (they use a different rendering path). If you ask Claude Code to fix itself using this information, it can locate and patch the function automatically.

WargameGPT avatar Feb 06 '26 04:02 WargameGPT

I am seeing the incorrect coloring on my Claude (started happening within the last two weeks) and so is a coworker that just installed claude fresh.

Caleb-KS avatar Feb 06 '26 19:02 Caleb-KS

@WargameGPT bless you for that advice! It works brilliantly! I went a bit further and wired the patching to SessionStart Hook to check for Claude updates and implement the patching to the new version automatically. Here's the summary of what we did with Claude for Windows. Hope it might be helpful for others.

Fix: ANSI Highlight Drift (Random Color Fragments in Terminal Output)

Symptoms: Random colored text fragments appear in normal Claude responses. Colors shift rightward after line breaks, getting worse with longer outputs. Not error messages — just broken ANSI highlight re-application after word-wrap.

Root cause: The bundled Bun binary has a function bh0 (in Ink's rendering pipeline) with TWO re-sync blocks gated by parameter D (default false). Both blocks are dead code, causing the style-map index to drift after word-wrap line breaks.

Fix approach: Patch X&& (3 bytes) to (3 spaces) in both gate conditions. Each pattern appears twice (Bun double-embed = 4 total patches). Auto-update overwrites the fix, so a SessionStart hook re-patches automatically.

The Two Patterns

Pattern 1 (start-of-line): if(D&&_.length>0){let F=/\s/.test(_[0])

  • Anchor: .length>0){let with 4 pre-bytes matching X&&Y
  • Skips whitespace in original text when wrapped line starts with non-space

Pattern 2 (end-of-line): if(D&&M<I.length-1){let F=I[M+1]

  • Anchor: .length-1){let with 6 pre-bytes matching X&&Y<Z
  • Peeks at next line's first char, skips whitespace until finding it

Implementation

Solved with ~/.claude/hooks/modules/binary-patcher.js (JS SessionStart hook). The patcher:

  1. Finds latest version file by semver in ~/.local/share/claude/versions/
  2. Reads binary into Buffer, searches for both pattern anchors
  3. Replaces X&& (3 bytes) with spaces in each match
  4. Writes patched buffer to version file
  5. Attempts to copy to claude.exe (rename strategy). If locked (common — current session holds it), spawns a detached background watcher that polls every 5s until the exe is released, then copies automatically
  6. Caches mtime/size in state file (exePending flag tracks incomplete exe patches, confirmNext flag triggers success message on next session)

User-facing messages

Messages flow via SessionStart additionalContext → Claude relays in first response.

Scenario Message
Fresh patch, exe copied "Restart Claude Code for the fix to take effect."
Fresh patch, exe locked "Close all sessions. Background process will update."
Next session after watcher "Fix applied successfully. Colors should render correctly."
Exe pending retry success "Fix applied successfully."
Exe pending retry failed "Fix is queued. Background process will update."

i-dedova avatar Feb 07 '26 15:02 i-dedova

I actually like this. It's kind of like Bionic reading.

AdamCassidy avatar Feb 07 '26 19:02 AdamCassidy

Same issue, although @WargameGPT fix didn't work for me as I didn't use NMP to install and I can't seem to find my cli.js file for Claude?

Bird22 avatar Feb 10 '26 18:02 Bird22

Regarding to https://gist.github.com/frostbtn/f85b574ce132c8853945df852e1e0d31 the bug was introduced with Claude Code 2.1.14 that implies that version 2.1.12 from ~ a month ago is the last officially usable version for Windows.

Workaround

claude install 2.1.12

@bcherny, @ashwin-ant and @fvolcic please take a look at this coloring bug, it renders the app unusable on Windows and there is now a sufficient amount of tickets regarding this issue with deep analysis and sound solution suggestions.

countzero avatar Feb 12 '26 10:02 countzero

This hook worked for me. I am using CC native ARM64 binary. I know the pattern is the same in the other architectures' binaries, but I don't know if there are any differences to take into account. You could start with these and ask Claude to check them and implement them according to your current installation.

OneDrive Folder with Hook

If anyone can get the attention of anthropic devs to implement a fix of the root cause (as identified by @WargameGPT - https://github.com/anthropics/claude-code/issues/17314#issuecomment-3857915285) that would be super.

ghost avatar Feb 17 '26 20:02 ghost

If you installed CC via irm https://claude.ai/install.ps1 | iex (because the docs say installation via npm is deprecated), cli.js does not exist so we can't use the fix above. I tried to revert to 2.1.14, but the problem persisted there. In case my methodology was flawed, here's where I found the old version:

https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/2.1.14/win32-x64/claude.exe

(You're probably not willing to download an exe from a random https://storage.googleapis.com URL, so take a look at the contents of https://claude.ai/install.ps1 and observe that this is the URL they're using.)

I put this where I installed the old version, $HOME\.local\bin\claude.exe, ran claude, and still see the error, even though the version is clearly 2.1.14.

Image

slepkin avatar Feb 17 '26 23:02 slepkin

If you installed CC via irm https://claude.ai/install.ps1 | iex (because the docs say installation via npm is deprecated), cli.js does not exist so we can't use the fix above.

I am not using the npm version of CC. Mine is Windows native install using irm https://claude.ai/install.ps1 | iex.

The fix that I referenced (hook) works. There is no cli.js file as an independent file; it is packaged within the claude.exe binary. The hook patches the binary file that is downloaded to {userprofile}\.local\share\claude\versions and then overwrites the claude.exe in {userprofile}\.local\bin (the actual claude code binary) when the file is no longer in use.

ghost avatar Feb 17 '26 23:02 ghost

Root Cause Found & One-Line Fix

Full analysis posted at #14720 (comment)

TL;DR: The bug is in the IP5 function in cli.js. When word-wrapping consumes spaces at line breaks, the style-position tracker $ falls behind by 1 per wrap. This accumulates, shifting all ANSI highlighting rightward over long paragraphs.

It sure would be nice to get Anthropic to take care of this. We have internal users starting to complain the output is hard to read. This seems like a silly simple fix to implement, test and release.

It's a quality-of-life issue for many, especially those with visual impairments.

calilafollett-rm avatar Feb 18 '26 12:02 calilafollett-rm

Fixed in 2.1.47

VagnerVit avatar Feb 19 '26 09:02 VagnerVit

Image

Still not fixed for me on claude --version - 2.1.47 (Claude Code)

jasonftl avatar Feb 19 '26 16:02 jasonftl

Fixed in 2.1.47

I hope this is true. Unfortunately, 2.1.47 breaks Bun on ARM64 Windows, so I'm stuck on 2.1.45 until that regression is fixed.

ghost avatar Feb 19 '26 20:02 ghost

seems it's fixed for me in 2.1.50

Caleb-KS avatar Feb 21 '26 01:02 Caleb-KS

Fixed for me in 2.1.50. Thank you.

countzero avatar Feb 21 '26 09:02 countzero