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

[BUG] Background color bleed in terminal from chalk usage

Open tajquitgenius opened this issue 7 months ago • 4 comments

claude code wrote this issue report lol

Claude Code Issue Report: Background Color Bleed in Terminal

Issue Summary

Claude Code's startup tips use chalk background colors that bleed into subsequent terminal output, causing persistent red/white backgrounds that interfere with the UI.

Environment

  • OS: macOS (Darwin 24.5.0)
  • Terminal: Terminal.app
  • Claude Code: Latest version (accessed via claude command)

Problem Description

When Claude Code starts, it displays helpful tips using chalk with background colors:

console.log(chalk.bgRed.white.bold(`> Try "refactor <filepath>"`));

The background color escape sequences (\x1b[4Xm) are not properly terminated with reset sequences (\x1b[0m), causing the background color to "bleed" into subsequent terminal output.

Visual Impact

Users see:

  • Red or white backgrounds persisting after the tip messages
  • Text becoming difficult to read due to color conflicts
  • Terminal UI appearing "broken" or glitched

Reproduction Steps

  1. Launch Claude Code from terminal: claude
  2. Observe the startup tips with colored backgrounds
  3. Notice background colors persist in the interface
  4. Background bleed affects readability of subsequent output

Root Cause Analysis

The issue occurs because:

  1. Background color codes (\x1b[4Xm) are applied
  2. No reset sequence (\x1b[0m) follows immediately
  3. Terminal continues to apply background color to subsequent text
  4. Bleed persists until manually cleared or reset

Proposed Solutions

Option 1: Use Foreground Colors Only (Recommended)

Replace background colors with bright foreground variants:

// Instead of:
chalk.bgRed.white.bold(`> Try "refactor <filepath>"`)

// Use:
chalk.redBright.bold(`> Try "refactor <filepath>"`)
// or
chalk.red.bold(`> Try "refactor <filepath>"`)

Option 2: Add Proper Reset Sequences

Ensure every background color usage ends with a reset:

chalk.bgRed.white.bold(`> Try "refactor <filepath>"`) + chalk.reset()

Option 3: Environment Awareness

Respect the NO_COLOR environment variable:

const useColors = !process.env.NO_COLOR;
const tip = useColors 
  ? chalk.redBright.bold(`> Try "refactor <filepath>"`)
  : `> Try "refactor <filepath>"`;
console.log(tip);

Current Workarounds

Users currently work around this by:

  • Setting NO_COLOR=1 environment variable
  • Manually clearing terminal with Ctrl+L or clear
  • Resetting terminal formatting before launching Claude

Expected Behavior

Tips should display with colors that:

  • Don't bleed into subsequent output
  • Are properly contained to their intended text
  • Reset cleanly when complete

Files Likely Affected

Based on typical project structure, likely locations:

  • src/ui/banner.ts - Startup tips and banners
  • src/cli/ - CLI output formatting
  • Any file using chalk.bg* methods

Search Patterns

To find affected code:

# Search for background color usage
grep -r "bgRed\|bgWhite\|bgBlue\|bgGreen" src/
grep -r "\.bg[A-Z]" src/

# Look for chalk usage without reset
grep -r "chalk\.bg" src/ | grep -v "reset"

Impact

  • Severity: Medium (cosmetic but affects usability)
  • Users Affected: ?
  • Frequency: Every startup

Additional Context

This issue was discovered while building an orchestration tool that spawns multiple interactive Claude Code instances. The background color bleed makes it difficult to read or interact.

Image

tajquitgenius avatar May 26 '25 23:05 tajquitgenius

Thanks for the report! Are you able to reproduce this issue?

reverie avatar May 27 '25 15:05 reverie

Yeah, it happens every time.

macOS (lines 290-302): Uses AppleScript to launch Terminal.app
  applescript = f"""
  tell application "Terminal"
      activate
      do script "{script_path.absolute()} {self.workspace_path.absolute()}"
      set custom title of front window to "{self.terminal_title}"
  end tell
  """
  subprocess.run(["osascript", "-e", applescript], check=True, capture_output=True, text=True)

After the terminal is launched, we automatically copy some instructions to clipboard and then run claude

     # Try to copy instructions to clipboard automatically
     echo ""
     echo "Preparing agent instructions..."

     # Check if pbcopy is available (macOS)
     if command -v pbcopy &> /dev/null && [ -f "PASTE_ME_INTO_CLAUDE.txt" ]; then
         cat PASTE_ME_INTO_CLAUDE.txt | pbcopy
         echo ""
         echo "[OK] Instructions copied to clipboard!"
         echo "[!] Just paste (Cmd+V) when Claude Code starts"
         echo ""
         echo "Starting Claude Code in 3 seconds..."
         sleep 3
     else
         # Show manual copy instructions
         echo ""
         echo "================================================================"
         echo "    📋 COPY THIS INTO CLAUDE CODE:                           "
         echo "================================================================"
         echo ""
         cat PASTE_ME_INTO_CLAUDE.txt | head -20
         echo ""
         echo "... [Full content in PASTE_ME_INTO_CLAUDE.txt]"
         echo ""
         echo "👆 Open PASTE_ME_INTO_CLAUDE.txt for full instructions"
         echo "📋 Copy the contents and paste into Claude Code"
         echo ""
         echo "Press Enter when ready to start Claude Code..."
         read -n 1
     fi

     # Start Claude Code
     echo ""
     echo "Starting Claude Code..."
     claude

tajquitgenius avatar May 27 '25 18:05 tajquitgenius

I have the same issue with multiple CLI tools that use colored background. My guess it that Claude Code just needs to always reset the terminal colors after showing any terminal output.

JanTvrdik avatar Jun 11 '25 10:06 JanTvrdik

Seeing a similar issue every time I run claude code.

Image Image Image

teehemkay avatar Jun 14 '25 13:06 teehemkay

Seeing this too - combination of red and white sometimes randomly disappears

17Amir17 avatar Jul 03 '25 11:07 17Amir17

same

acarkaan avatar Jul 09 '25 00:07 acarkaan

same

mitalauskas avatar Jul 18 '25 00:07 mitalauskas

same

vincentfarefood avatar Jul 18 '25 21:07 vincentfarefood

Issue appears consistently inside a GNU Screen (https://www.gnu.org/software/screen/) session.

justinpincar avatar Jul 25 '25 00:07 justinpincar

same with pterm (go)

Image

bennypowers avatar Jul 28 '25 15:07 bennypowers

Image

Same issue happens in Claude Code terminal on Windows:

Description: When Claude executes code blocks (e.g., running Laravel tests with php artisan test), the terminal output changes color but the background color remains stuck in that color even after the command completes.

Example:

Claude runs: php artisan test --filter "some test" Terminal output shows in green background when tests complete successfully After test completion, terminal background remains green instead of returning to default

Expected Behavior: Terminal background should reset to default color after command execution completes. Current Behavior: Background color persists, making subsequent terminal output difficult to read.

mathiaswillburger avatar Aug 03 '25 20:08 mathiaswillburger

I can also reproduce in gnu screen

heeen avatar Aug 06 '25 09:08 heeen

Also a problem for me. Makes claude nearly unusable.

taedryn avatar Aug 08 '25 17:08 taedryn

As a workaround, ask claude to run "tput sgr0" and it will reset it. Obviously the app should do this or something similar directly, but for anyone experiencing this, that will fix it.

jcherniak avatar Aug 11 '25 06:08 jcherniak

I use an ugly workaround for now. I created a PostToolUse:Bash hook that runs the following script

#!/usr/bin/env bash

tput sgr0 >&2
echo "COLORS HAVE BEEN FIXED" >&2
exit 1 # ensures that stderr is shown to user only

JanTvrdik avatar Aug 12 '25 15:08 JanTvrdik

+1. Makes it nearly unusable in my macOS terminal app :/

maho-jared avatar Aug 21 '25 11:08 maho-jared

Same here

alexanderfilipzik avatar Aug 27 '25 07:08 alexanderfilipzik

+1

erashdan avatar Sep 13 '25 21:09 erashdan

Same running testing tools from Composer or NPM (like phpstan or unit tests):

Image Image

jakubmikita avatar Sep 14 '25 08:09 jakubmikita

Yes, getting it on my side as well. This bug should be very easy to fix. And is affecting readability a lot.

waldoalvarez00 avatar Sep 19 '25 11:09 waldoalvarez00

Same issue when running tests.

daugaard47 avatar Sep 23 '25 01:09 daugaard47

Same here running tests.

Did someone get the solution?

otavio-araujo avatar Sep 27 '25 00:09 otavio-araujo

Image I think I'm seeing this too.

geoff-plitt-thoughtful avatar Oct 03 '25 20:10 geoff-plitt-thoughtful

This is consistently reproducible with gnu-screen on macos. I've tried everything to match up terminal emulation and background color erase between the two---to no avail. /opt/homebrew/bin/claude is minified, which would be time consuming to debug and patch.

The only work around I've found is to not use claude in a screen session or to disable colors when using screen with:

FORCE_COLOR=0 claude

gharibian avatar Oct 04 '25 23:10 gharibian

At least Claude >2.0 seems to reset the color once a new prompt is submitted.

mathiaswillburger avatar Oct 07 '25 19:10 mathiaswillburger

At least Claude >2.0 seems to reset the color once a new prompt is submitted.

90% better than what it was. I think they definitely took this into account for version 2.

daugaard47 avatar Oct 07 '25 19:10 daugaard47

At least Claude >2.0 seems to reset the color once a new prompt is submitted.

I noticed. It is a whole lot better than "forever bleeding until a patch is done" that did a "reset" of the background. The bleeding remained even after closing CC. I was doing a reset manually with color 07 command. And sometimes copy pasting the code from console to text editor to read, since the white/gray over green background was killing my eyes. Fortunately, I completed that project already.

waldoalvarez00 avatar Oct 09 '25 00:10 waldoalvarez00

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 07 '25 10:12 github-actions[bot]