Strip ANSI escape codes from terminal output
ANSI escape codes drive colour and styling in your terminal — but they become unreadable garbage the moment you copy them into a doc or editor. Strip them in one paste.
What ANSI escape codes look like
ANSI escape codes are sequences that start with the escape character \x1B (ESC), followed by [, then a series of numeric parameters and a final letter. They tell the terminal how to render the text that follows — colour, bold, cursor position, screen clear. The most common forms you'll see when output is captured to a file or a clipboard are \x1B[31m (red), \x1B[1m (bold), and \x1B[0m (reset).
Why they leak into your paste
Anything that captures your terminal stream — script(1), a piped log, a pasted Claude Code output, a Docker build log copied from CI — preserves the escape codes as literal characters. Your editor or markdown surface has no idea they're control codes; it just shows them as text.
How to remove them
- Copy the terminal output you want to clean.
- Paste into the cleaner below. The ANSI codes toggle is on by default; it strips every
\x1B[…msequence. - Click copy. Paste your clean text wherever you need it.
Regex behind the scenes
The pattern is straightforward: /\x1B\[[0-9;]*[A-Za-z]/g. It matches the ESC byte, the bracket, any number of digits and semicolons, then a single letter terminator. This catches CSI, SGR, and most cursor-control sequences. If you have OSC sequences (e.g. \x1B]…\x07) in the mix, drop a note on GitHub.
Privacy
Stripping happens in your browser. Your output never leaves your machine — useful when terminal logs contain tokens, hostnames, or internal data.