[BUG] CLI hardwraps output with real \n characters based on terminal window width

Resolved 💬 2 comments Opened Jun 3, 2026 by TamVentura Closed Jun 6, 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?

## Description

The Claude Code CLI inserts actual \n characters into its text output at the terminal window width boundary
(hardwrap). This means that when a user selects and copies any output that wraps visually — commands, config snippets,
JSON — the copied text contains real newlines at the wrap positions, breaking the content when pasted.

## Actual behavior

The CLI detects the terminal width via Win32 console API and inserts \n at that column. Setting $env:COLUMNS to a
large value has no effect, confirming the width is read from the actual console buffer, not the environment variable.

When the terminal window is wide enough that no wrapping occurs, copy works correctly. When the window is narrower
than the output line, copy includes the inserted newlines.

## Environment

  • OS: Windows 11 Pro
  • Terminals affected: Windows Terminal, VS Code integrated terminal (ConPTY)
  • Workaround: keeping the terminal window wide enough to prevent wrapping
  • Tested: setting $env:COLUMNS = 3220 before launching ($env:COLUMNS = 3220; claude) has no effect — the CLI reads

the actual console window width via Win32 API, ignoring the environment variable

I used claude code to generate the description for this bug and you can see here some newlines that shouldn't be here. I only tested on windows terminal and VS code integrated terminal, don't know if this happens on other terminals as well

What Should Happen?

The CLI should output long lines without inserting \n characters and let the terminal handle visual wrapping
(soft-wrap). This way, copying a visually-wrapped line produces the original single-line string.

Error Messages/Logs

Steps to Reproduce

  1. Open a terminal window at a moderate width (e.g. 120 columns)
  2. Ask Claude Code to output a long command or JSON config
  3. Select the output and copy it
  4. Paste into a text editor — observe real newlines at the wrap positions
  5. Widen the terminal window so the same output fits on one line
  6. Repeat steps 3-4 — copy is now correct

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.161 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

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