Support ANSI color codes in bash command output

Status Fixed / completed
Maintainer reply None cached
Activity 5 comments · opened Jan 17, 2026 · closed Jan 17, 2026

Summary

Bash commands that produce colored output (like git log, ls --color, grep --color) have their ANSI escape codes stripped or escaped before being displayed in the terminal. The user's terminal (e.g., Ghostty, iTerm2) is fully capable of rendering these codes, but Claude Code's output pipeline prevents them from reaching the terminal.

Current Behavior

  1. Command runs and produces ANSI codes (verified by capturing with script -q /dev/null)
  2. Claude Code captures stdout as text
  3. ANSI codes are escaped/stripped during processing
  4. Output appears as plain uncolored text

Example - running git log --oneline --color=always shows plain text instead of the colored branch names, commit hashes, etc.

Desired Behavior

ANSI escape codes should be passed through to the terminal unescaped, allowing the user's terminal emulator to render colors as intended.

Possible Solutions

  • A config option like terminal.preserveAnsiCodes: true
  • A --raw-output flag for bash commands
  • Detecting when stdout is a TTY and passing codes through in that case

Environment

  • Terminal: Ghostty (but applies to any terminal with ANSI support)
  • OS: macOS

View original on GitHub ↗

5 Comments

github-actions[bot] · 9 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/16790
  2. https://github.com/anthropics/claude-code/issues/13441
  3. https://github.com/anthropics/claude-code/issues/881

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

DanielAtProfound · 9 months ago

Related Issues

  • #13441 - ANSI codes corrupted during line-wrapping (different: about corruption, not stripping)
  • #16668 - ANSI codes in model responses (different: about Claude's text output, not bash)
  • #18269 - ANSI codes in skills/hooks (potential overlap - same underlying desire for colored tool output)

There seems to be a common theme across these issues: users want ANSI codes preserved and rendered in various output contexts. #18269 in particular may have significant overlap with this request, as both are about tool/script output having colors stripped before reaching the terminal.

DanielAtProfound · 9 months ago

Update: #16790 is very similar - also about ANSI escape sequences being stripped from Bash tool output. That issue focuses on true color (24-bit SGR codes), while this one covers ANSI codes more broadly, but the underlying problem is the same: escape sequences are stripped before tool output reaches the terminal.

#16790 may be the canonical issue for this. Happy to close this as duplicate if that's preferred.

DanielAtProfound · 9 months ago

Closing this - I mistakenly blamed Claude for git's behavior:

Testing Colors

These tests were conducted on Ghostty v1.2.3 on macOS Tahoe 26.2

Claude Slash Commands

To prove this works with a minimal example, I created a new command file .claude/commands/claude-color-test.md with the attached content claude-color-test.md:

````bash
Run this shell command to test terminal colors:

NOCOLOR="\033[0m"; RED="\033[31m"; echo "$RED something red $NOCOLOR and reset";

````

Run claude and use the slash command skill with /claude-color-test... after a permission prompt:

<img width="2018" height="264" alt="Image" src="https://github.com/user-attachments/assets/0b8f96a8-5b3e-4716-8957-04617f1b3230" />

Using the Bash Bang ! Command

I also used a simple example to test colors in Claude Code with the ! bash command and it worked there as well:

This is the command I paste after hitting !

NOCOLOR="\033[0m"; RED="\033[31m"; echo "$RED something red! $NOCOLOR back to normal.";

Running with the ! bash command this worked:

<img width="1492" height="198" alt="Image" src="https://github.com/user-attachments/assets/da96f590-d18a-49d2-ad7e-f0159a8e64b1" />

----

So -- yep, I was wrong, it works great!

Leaving this in case it may help someone in the future.

github-actions[bot] · 8 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.