Code blocks in terminal output add leading spaces that break Python copy/paste
Resolved 💬 3 comments Opened Feb 22, 2026 by zcor Closed Feb 26, 2026
Problem
When Claude Code outputs Python code blocks in the terminal, the rendered markdown adds leading whitespace to every line. When the user copies and pastes this into their server terminal (e.g., into a heredoc, nano, or directly), the extra indentation is preserved, causing Python SyntaxError or IndentationError.
This is especially painful when helping users run Python scripts on remote servers where they can't use Claude Code's file-writing tools.
Reproduction
- Ask Claude Code to generate a multi-line Python script
- Try to copy the output from the terminal
- Paste into a remote terminal (e.g.,
cat > /tmp/script.py << 'EOF') - The pasted code has extra leading spaces on every line
- Python fails with indentation/syntax errors
Impact
- Any workflow where the user needs to copy Python code to a remote server
- Heredoc (
<< 'EOF') workflows are completely broken - Users end up having to manually re-type or fix indentation in nano
Suggestion
Consider a "copy-friendly" output mode or a way to copy code blocks without the markdown rendering indentation. A "copy to clipboard" affordance for code blocks would solve this entirely.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗