How to Clean Up Messy Terminal & Claude Code Output (2026)

Copying text from a terminal often brings invisible ANSI color codes, line-number gutters, and control characters. Here is what causes the mess and how to strip it for clean, paste-ready text.

|
TerminalClaude CodeANSI CodesDeveloper ToolsCLI

You run a command, get a perfect result on screen, copy it, and paste it into a document, a bug report, or an AI prompt — and suddenly it is full of strange brackets, the indentation is off, and there are line numbers stuck to every row. The terminal looked clean, so where did the mess come from? The answer is that a lot of what a terminal displays is made of invisible instructions, not text. This guide explains what those hidden characters are and how to strip them so your copied output is clean and paste-ready. If you just want the quick fix, paste your text into the Claude Code Text Formatter and copy the cleaned result.

Why Terminal Output Gets Messy When You Copy It

A terminal does two things at once: it shows you text, and it interprets hidden control instructions that change how that text looks and where the cursor goes. While you are looking at the terminal, those instructions are invisible — they have already done their job. But when you select and copy, you copy everything, including the hidden parts. Paste that into a place that does not understand terminal instructions and the hidden parts become visible garbage.

There are five common culprits. Here is what each looks like and why it appears.

CulpritWhat it looks like when pastedWhere it comes from
ANSI escape codes[0;32m, ^[[1mColors, bold, and cursor moves
Line-number gutters123→, 123|File readers, cat -n, grep -n
Control charactersInvisible / odd spacingESC, vertical tab, null bytes
Box-drawing characters─ │ ┌ └ ┤ ┬Tables, tree views, frames
Carriage returnsDoubled or broken linesWindows CRLF, progress bars

ANSI Escape Codes: The Color Problem

The most common source of garbage is ANSI escape codes. These are sequences that begin with the ESC character (often written as \x1b, \033, or shown as ^[) followed by a bracket and some numbers ending in a letter. Your terminal reads \x1b[32m as "switch the text color to green" and \x1b[0m as "reset formatting." You never see the codes themselves — only the green text.

The trouble starts when the destination does not speak ANSI. A plain text field, a Markdown editor, or a chat box just prints the raw codes. A line that showed as a tidy green Success in your terminal can paste as:

  • [0;32mSuccess[0m

Multiply that across a long log and the output becomes unreadable. Removing ANSI codes is almost always the first cleanup step. On the command line you can strip them with a tool like sed:

  • sed 's/\x1b\[[0-9;]*m//g' input.txt

That works for color codes, but real terminal output also contains cursor-movement and clear-screen sequences that the simple pattern above misses. A dedicated formatter handles the full range of escape sequences in one pass, which is why it is more reliable than a quick regex for anything beyond plain colors.

Line-Number Gutters from Claude Code and CLI Tools

When an AI coding assistant like Claude Code reads a file, or when you run cat -n or grep -n, each line is prefixed with its line number. This is great for reference — you can say "the bug is on line 42" — but it ruins the text the moment you try to paste the code back into an editor, because now every line starts with a number and a separator that is not part of your code.

The gutter usually takes one of three forms:

  • Arrow style: 42→const x = 1 (used by Claude Code file reads)
  • Tab style: 42 const x = 1 (used by cat -n)
  • Pipe style: 42 | const x = 1 (used by many code viewers)

The key when stripping these is to remove only the leading number and its separator, not any numbers inside your actual code, and to keep the real indentation that follows. A careful formatter matches the gutter pattern at the start of each line and leaves everything else untouched, so 42→ return value becomes return value with its four-space indent intact.

Control and Zero-Width Characters: The Invisible Mess

Some of the worst problems are the ones you cannot see at all. Control characters are non-printing bytes such as the ESC character, the vertical tab, the form feed, and null bytes. Zero-width characters like the zero-width space (U+200B) and the byte-order mark (U+FEFF) take up no visible room but are still really there in the text.

These cause subtle, maddening bugs. A password copied from a terminal might fail to authenticate because a zero-width character rode along. A diff might show two identical-looking lines as different. A search for a function name might come up empty because an invisible character is wedged in the middle. Because you cannot see them, you can waste a long time chasing the cause. Stripping all non-printing and zero-width characters — while keeping ordinary tabs and newlines — eliminates this entire class of problem.

Box-Drawing Characters and Carriage Returns

Box-drawing characters

Command-line tools love to draw boxes. Tables, dependency trees, and framed status panels use characters like , , , and to create borders. When you only want the data inside a table — not the frame around it — those characters are noise. Removing the box-drawing range leaves just the content, which is much easier to reuse in a spreadsheet or a document. Keep in mind this is optional: sometimes the box layout is exactly what you want to preserve.

Carriage returns and progress bars

Windows systems end lines with a carriage return plus a line feed (\r\n), while macOS and Linux use just a line feed (\n). Paste Windows output into a Unix-oriented tool and you can get doubled or broken line breaks. Progress bars are worse: they use a lone carriage return to overwrite the same line repeatedly, so a copied progress bar can paste as a pile of half-finished lines. Normalizing line endings to a single standard fixes both.

When Clean Output Actually Matters

You do not need to clean every snippet, but several situations make it essential:

  • Pasting into AI prompts: ANSI codes and gutters waste tokens and can confuse a model. Clean code in, better answers out.
  • Filing bug reports and tickets: Reviewers should read your logs, not decode escape sequences. Clean output looks professional and is searchable.
  • Writing documentation: Code blocks in docs need to be copy-paste-ready for your readers, with no stray line numbers.
  • Commit messages and code review: Pasting terminal output into a description is common; invisible characters there can break formatting downstream.
  • Reusing data from tables: Pulling values out of a CLI table into a spreadsheet is far easier without the border characters.

How to Clean It: Tool vs Command Line

You have two practical options. On the command line, you can chain tools — sed to strip ANSI codes, tr to delete control characters, and awk or cut to remove gutters. This works well in scripts and pipelines where you want repeatable automation.

For a quick one-off — you have text on your clipboard right now and just want it clean — a browser tool is faster and you can see the result instantly. The Claude Code Text Formatter does all of the above with toggles for each cleanup step, runs entirely in your browser, and never uploads your text. Paste, pick what to strip, and copy. If you also need to compare two versions of cleaned output, the Diff Checker pairs well with it.

Key Takeaways

  • Terminals display text and hidden instructions together; copying grabs both, so the hidden parts can become visible garbage.
  • ANSI escape codes (like [0;32m) carry color and formatting and are the most common source of mess.
  • Line-number gutters from Claude Code, cat -n, and grep -n must be stripped before pasting code back — while keeping real indentation.
  • Invisible control and zero-width characters cause silent failures in passwords, diffs, and searches.
  • Box-drawing characters and mixed carriage returns add visual noise and broken line breaks.
  • For one-off cleanup, a browser-based formatter that runs locally is the fastest and safest option.

Frequently Asked Questions

Why does text I copy from the terminal have weird symbols like [0;32m?

Those are ANSI escape codes. Terminals use them to add color and formatting, but they are invisible while displayed. When you copy colored output into a plain-text field that does not understand them, the raw codes show up as garbage like [0;32m or ^[[1m. Stripping the ANSI codes restores clean text.

How do I remove line numbers from copied code?

Code shown in tools like Claude Code, 'cat -n', or 'grep -n' includes a line-number gutter — a number followed by a tab, an arrow, or a pipe before each line. To paste the code back into an editor, you need to strip that gutter. A formatter that removes leading 'number + separator' patterns does this in one step while preserving the code's real indentation.

What are zero-width and control characters?

Control characters are non-printing bytes (like the ESC character or a vertical tab) that instruct the terminal rather than display text. Zero-width characters (such as U+200B) are invisible spacing characters that sometimes hide inside copied text. Both can break diffs, search, and code without you seeing them, so it helps to remove them.

Is it safe to paste sensitive terminal output into an online formatter?

Only if the tool processes everything locally in your browser and never uploads your text. ToolPile's formatter runs entirely client-side — your text never leaves your device and nothing is stored. Always confirm a tool is browser-based before pasting anything sensitive like logs or config output.

Will cleaning the text remove my code's indentation?

A good formatter only strips leading line-number gutters and trailing whitespace. Meaningful indentation — the spaces and tabs that are part of your code structure — is preserved, so your formatting stays intact when you paste it back.

Related Tools

Related Articles