[BUG] Excessive trailing spaces in markdown output (~190 chars per line, doubles output size)

Status Fixed / completed
Reported on v2.0.73
Maintainer reply None cached
Activity 6 comments · opened Jan 14, 2026 · closed Feb 7, 2026

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?

Claude Code adds excessive trailing spaces to every line of markdown output, inflating line width to ~190 characters even when actual content is only 50-60 characters. This approximately doubles the output size and breaks copy/paste workflows.

This happens with plain ASCII English text - not related to Unicode, emoji, or Cyrillic characters.

Example output (plain English):

The grep function works correctly and ignores the -r flag.                                                                                                                                   
                                                                                                                                                                                              
What was done:                                                                                                                                                                                
- Automatically removes -r, -R, --recursive flags                                                                                                                                             
- Passes other arguments to rg                                                                                                                                                                

Notice the massive amount of trailing spaces after each line (not visible here, but present when copied).

Hex dump proof (plain ASCII text):

$ wc -L /tmp/claude_test_english.txt
190 /tmp/claude_test_english.txt

$ xxd /tmp/claude_test_english.txt | head -15
00000000: 5468 6520 6772 6570 2066 756e 6374 696f  The grep functio
00000010: 6e20 776f 726b 7320 636f 7272 6563 746c  n works correctl
00000020: 7920 616e 6420 6967 6e6f 7265 7320 7468  y and ignores th
00000030: 6520 2d72 2066 6c61 672e 2020 2020 2020  e -r flag.      
00000040: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000050: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000060: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000070: 2020 2020 2020 2020 2020 2020 2020 2020                  
...
000000b0: 2020 2020 2020 2020 2020 2020 200a 2020               .  

After "flag." (offset 0x36), there are ~150 bytes of 0x20 (spaces) before 0x0a (newline).

What Should Happen?

  • Output lines should only contain actual text content
  • No trailing whitespace padding
  • Lines should end immediately after content
  • For example: The grep function works correctly and ignores the -r flag.\n (no spaces before newline)

Error Messages/Logs

No error messages - this is a rendering/formatting issue.

Steps to Reproduce

  1. Start Claude Code in terminal (any terminal: Ghostty, iTerm2, Terminal.app, Windows Terminal, etc.)
  2. Ask any question that generates multi-line markdown output
  3. Copy the output to a file
  4. Check with wc -L filename - lines are ~190 chars with massive trailing spaces
  5. Or check with xxd filename to see hex dump

Simple test case:

claude  # start Claude Code
# Ask: "Explain what grep does in 2-3 sentences"
# Copy output to /tmp/test.txt
wc -L /tmp/test.txt  # Will show ~190 characters per line

Claude Model

Sonnet (default)

Is this a regression?

Possibly - similar issue #14755 was fixed in 2.0.73, but this appears to be a different variant (trailing vs leading whitespace)

Last Working Version

Unknown - may have never worked correctly

Claude Code Version

2.1.7 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Ghostty + ZSH (but likely affects all terminals)

Additional Information

Related issues:

  • #14755 - Similar markdown renderer bug (closed, but this is different - trailing not leading)
  • #10969 - Extra spaces when copying (related but different symptom)
  • #15289 - Leading whitespace issue (this is trailing whitespace)
  • #16624 - Word wrap broken (may be related to same rendering code)

Environment:

  • COLUMNS=0 initially (fixed by setting export COLUMNS=80)
  • Fix didn't resolve the issue - trailing spaces persist
  • Terminal width: 80 cols (tput cols)

Impact:

  • Doubles file size when saving Claude output
  • Breaks markdown formatting when pasting
  • Makes output harder to read in narrow terminals
  • Wastes bandwidth and storage
  • Every conversation creates unnecessarily large log files

Technical details:

  • Appears to be padding lines to a fixed width (~190 chars)
  • Happens regardless of terminal width setting
  • Affects ALL text output, not just code blocks
  • Plain ASCII text affected (not a Unicode/emoji issue)

---

Reported by: Dmitry Voroshilov (Ворошилов Дмитрий)

View original on GitHub ↗

6 Comments

DmitruNS · 7 months ago

Updated the issue description with plain ASCII English example to demonstrate that the problem is NOT related to Unicode, emoji, or Cyrillic characters.

The hex dump clearly shows that even simple English text like The grep function works correctly gets padded with ~150 trailing spaces (0x20 bytes) before the newline (0x0a).

This is a core rendering issue affecting all text output, regardless of character set.

sakalys · 7 months ago

I am facing the exact same issue and it's driving me nuts. Can't copy-paste anything that is multiline

DmitruNS · 7 months ago

🚨 CRITICAL: Financial Impact - Wasted Money on Whitespace

While you're "thinking about this issue", users are literally paying for whitespace.

Real Financial Losses

I've been using Claude Code extensively for production work, and here are the actual costs of this bug:

Token waste calculation:

  • Typical Claude Code session: ~1000 output lines
  • Each line: ~190 chars (50-60 content + ~130-140 trailing spaces)
  • ~70% of tokens are whitespace that I'm paying for

Example from my production sessions:

Session 1 (last week):
- Total tokens used: 45,000
- Estimated whitespace tokens: ~31,500 (70%)
- Cost at $15/1M tokens (Sonnet): $0.675 total
- Wasted on whitespace: $0.47 (~70%)

Session 2 (today):
- Total tokens used: 43,437
- Estimated whitespace tokens: ~30,400
- Cost: $0.65 total
- Wasted: $0.46

Monthly estimate:

  • Average sessions/day: 5-10
  • Average tokens/session: ~40,000
  • Monthly tokens: ~6-12M tokens
  • Monthly cost wasted on spaces: $63-126
  • Yearly: $756-1,512 literally thrown away on whitespace

Copy-Paste Amplification

The bug compounds itself:

  1. Claude outputs text with trailing spaces → I pay for those tokens
  2. I copy output to report/document → spaces preserved
  3. I paste into new Claude session → I PAY AGAIN for the same whitespace
  4. Claude responds with more trailing spaces → cycle repeats

This is effectively a money leak that gets worse over time.

Production Impact

This isn't a "nice to have" - it's breaking production workflows:

API quotas exhausted faster (70% waste)
Increased latency (processing unnecessary tokens)
Storage waste (session logs 2x larger)
Copy-paste workflows broken (whitespace breaks markdown/code)
Financial loss accumulating daily (~$2-4/day wasted)

Comparison with Other AI Tools

| Tool | Trailing Spaces | Token Efficiency |
|------|----------------|------------------|
| ChatGPT Web | None | 100% |
| GitHub Copilot | None | 100% |
| Claude Web UI | None | 100% |
| Claude Code CLI | ~140 per line | ~30% ❌ |

Every other AI tool has solved this. Why hasn't Claude Code?

Business Impact for Anthropic

This bug is costing you customers:

  • Power users notice excessive token consumption
  • Financial loss → churn risk
  • Negative word-of-mouth ("Claude Code wastes tokens")
  • Trust erosion (looks like intentional inflation)

Even though it's likely a bug, the optics are terrible:

"Why does Claude Code use 3x more tokens than Claude Web for the same output?"

What I Need from Anthropic

  1. Acknowledge this is a P0 bug (affects billing)
  2. Provide ETA for fix (not "we're looking into it")
  3. Consider token credit for affected users (goodwill gesture)
  4. Hotfix release (this is a rendering bug, not a model issue - should be quick)

Technical Root Cause (from my analysis)

This appears to be terminal width padding gone wrong:

// Current (broken) behavior:
const paddedLine = content.padEnd(190, ' ') + '\n'

// Expected behavior:
const correctLine = content.trimEnd() + '\n'

The fix is literally a .trimEnd() call before output.

Workaround (for other affected users)

Until this is fixed, I'm using:

# Clean trailing spaces from clipboard
alias clean-claude='xclip -o | sed "s/[[:space:]]*$//" | xclip -selection clipboard'

But users shouldn't need workarounds for a billing issue.

Request for Escalation

@anthropics/claude-code-team - Can someone from the team please:

  • Confirm you've reproduced this
  • Provide ETA for fix
  • Explain why this hasn't been prioritized despite affecting billing

This is not just a UX issue - it's a financial issue affecting every Claude Code user.

---

TL;DR: I'm paying $60-120/month for whitespace. Please fix this ASAP or provide token credits for affected users.

DmitruNS · 7 months ago

UPDATE: Real Financial Impact is MUCH Worse

I need to correct my initial estimates - the actual losses are significantly higher for power users.

My Actual Usage (Production Environment)

Daily usage:

  • ~6,000,000 tokens/day
  • 180M tokens/month
  • Subscription: $200/month

With 70% token waste on whitespace:

  • Actual productive work: 54M tokens (~$60 value)
  • Wasted on trailing spaces: 126M tokens (~$140)

Real Financial Loss

| Period | Total Cost | Wasted on Whitespace | % Wasted |
|--------|-----------|---------------------|----------|
| Monthly | $200 | $140 | 70% |
| Yearly | $2,400 | $1,680 | 70% |

I'm paying $140/month ($1,680/year) for invisible characters.

That's equivalent to:

  • 8.4 months of subscription thrown away per year
  • Buying Claude Pro subscription and throwing it in the trash every month
  • Paying for a second Claude subscription just for whitespace

Enterprise Impact Projection

If my usage is typical for a power user:

Small dev team (5 developers):

  • Monthly waste: $700
  • Yearly waste: $8,400

Medium team (20 developers):

  • Monthly waste: $2,800
  • Yearly waste: $33,600

Large enterprise (100+ developers):

  • Monthly waste: $14,000+
  • Yearly waste: $168,000+

This bug is costing Anthropic customers hundreds of thousands of dollars.

Why This is Critical Priority

  1. Financial impact is massive - not a "small optimization"
  2. Every power user is affected - higher usage = higher losses
  3. Compounds over time - copy-paste recycles the whitespace
  4. Competitive disadvantage - ChatGPT/Copilot don't have this issue
  5. Trust erosion - looks like intentional token inflation

Specific Request

Given the magnitude of financial impact:

  1. Immediate hotfix (this is a .trimEnd() call, not a model retrain)
  2. Token credits for affected users (at minimum 30% credit for past 3 months)
  3. Public acknowledgment of the bug and compensation plan
  4. ETA for fix (measured in days, not weeks)

Supporting Evidence

Another user (@sakalys) confirmed: "I am facing the exact same issue and it's driving me nuts"

This is NOT an isolated case. This is affecting every Claude Code CLI user and costing real money.

---

@anthropics/claude-code-team - Can someone please respond?

Silent treatment on a billing bug is not acceptable.

DmitruNS · 6 months ago

✅ RESOLVED in v2.1.36

Thank you for fixing this! The trailing spaces issue has been resolved.

Verification (v2.1.36 released 2026-02-07):

Before (v2.1.7):

  • Line length: ~190 chars (140+ trailing spaces)
  • Token waste: ~70% of output

Now (v2.1.36):

$ wc -L test_output.txt
80 test_output.txt  # ✅ No padding to 190!

$ hexdump -C test_output.txt | grep -E "0a"
# ✅ Content immediately followed by 0x0a (newline)
# ✅ No 0x20 (space) padding before newline

Financial Impact Resolution:

The fix saves users ~,680/year in wasted tokens on trailing whitespace. This was a critical billing issue affecting all CLI users.

Greatly appreciated! 🙏

Closing as resolved.

github-actions[bot] · 6 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.