strip-ansi
Strips ANSI escape codes (color codes, cursor movement, formatting) from strings. Essential utility for processing terminal output that may contain color codes — logging terminal output to files, testing CLI output, measuring string display width, or displaying colored terminal output in non-ANSI contexts. Maintained by the chalk team. ESM-only since v7.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Single dependency (ansi-regex), MIT licensed. Pure string operation — no security concerns.
⚡ Reliability
Best When
You need to remove all ANSI escape codes from a string for logging, testing, or display in non-terminal contexts.
Avoid When
You need to selectively remove or transform specific ANSI codes — use ansi-regex directly for more control.
Use Cases
- • Strip ANSI codes from CLI tool output before writing to log files to prevent garbage color code characters
- • Clean colored terminal output from agent subprocess stdout/stderr for plain text storage or display
- • Process string display width accurately by stripping escape codes before measuring character length
- • Test CLI output assertions by stripping ANSI codes before comparing strings in test suites
- • Convert colored terminal output to plain text for display in web UIs or non-terminal contexts
Not For
- • Parsing specific ANSI code values — strip-ansi removes everything; use ansi-regex directly if you need to parse or preserve specific codes
- • Full ANSI code parsing or interpretation — use a terminal emulator library for parsing complex escape sequences
- • HTML conversion of colored terminal output — use ansi-to-html or chalk for that conversion
Interface
Authentication
Local library — no authentication required. MIT licensed.
Pricing
MIT licensed. Zero cost. Single dependency: ansi-regex.
Agent Metadata
Known Gotchas
- ⚠ v7+ is ESM-only — use import stripAnsi from 'strip-ansi'; CommonJS projects should pin to v6: strip-ansi@6
- ⚠ Also strips OSC (Operating System Command) and other non-color escape sequences — stripping is comprehensive, not just color codes
- ⚠ Does NOT decode or interpret escape codes — can't use this to extract color information; just removes them
- ⚠ String .length after stripping will differ from display width in terminals that use wide Unicode characters — use string-width for accurate display width calculation
- ⚠ Non-string inputs throw TypeError — validate input type before calling in agent pipelines processing mixed-type data
- ⚠ Commonly paired with string-width package which calls strip-ansi internally — avoid double-processing by using string-width directly when measuring display width
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for strip-ansi.
Scores are editorial opinions as of 2026-03-06.