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.

Evaluated Mar 06, 2026 (0d ago) v7.x
Homepage ↗ Repo ↗ Developer Tools ansi strip terminal chalk escape-codes cli string
⚙ Agent Friendliness
69
/ 100
Can an agent use this?
🔒 Security
99
/ 100
Is it safe for agents?
⚡ Reliability
94
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
92
Error Messages
80
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
95
Secret Handling
100

Single dependency (ansi-regex), MIT licensed. Pure string operation — no security concerns.

⚡ Reliability

Uptime/SLA
100
Version Stability
92
Breaking Changes
88
Error Recovery
95
AF Security 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

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Local library — no authentication required. MIT licensed.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT licensed. Zero cost. Single dependency: ansi-regex.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

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.

$99

Scores are editorial opinions as of 2026-03-06.

5215
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered