Code block rendering adds leading spaces to lines after the first

Resolved 💬 3 comments Opened Jan 23, 2026 by hamr0 Closed Jan 27, 2026

Description

When Claude Code renders multi-line markdown code blocks in the terminal, it adds leading spaces to lines after the first line. These spaces are actual characters in the terminal buffer, not visual padding.

Steps to Reproduce

  1. Ask Claude Code to output a multi-line code block
  2. Copy the code block content
  3. Run xclip -selection clipboard -o | cat -A to inspect

Expected Behavior

All lines in a code block should have consistent indentation (no leading spaces added by rendering).

Actual Behavior

line1$        ← no leading spaces, has newline
  line2%      ← TWO leading spaces, no newline

The first line has no leading spaces, but subsequent lines have 2 leading spaces added.

Impact

  • Copy/paste of code blocks requires manual cleanup
  • Heredocs fail because delimiters (like EOF) have leading spaces
  • Shell commands may fail due to unexpected indentation

Environment

  • OS: Linux (Ubuntu)
  • Terminal: Kitty
  • Claude Code: Latest version

Workaround

Strip leading whitespace after copying:

xclip -selection clipboard -o | sed 's/^[[:space:]]*//' | xclip -selection clipboard

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗