ANSI Spinners, Progress Bars, Decorations — All Gone

Published: (March 28, 2026 at 11:22 PM EDT)
2 min read
Source: Dev.to

Source: Dev.to

What are ANSI animations?

When you run commands like npm install, you’ll notice a spinning dot or a progress bar that seems to update smoothly in place. These are ANSI animations—cursor‑movement escape sequences that redraw the same line many times. The terminal shows a single animated line, but the raw output consists of hundreds of lines with cursor‑movement codes.

How a spinner works

A spinner repeatedly prints a frame, moves the cursor back to the start of the line, and prints the next frame.

Print ⠋ Loading...
Move cursor to start of line (\x1b[G)
Print ⠙ Loading...
Move cursor to start of line
Repeat 200 times

The terminal displays one smooth animation, while the underlying output contains 200 lines of text interleaved with cursor‑movement codes.

Progress‑bar example

A progress bar generates even more escape sequences:

\x1b[2K\x1b[1A\x1b[2K\x1b[G⸨░░░░░░░░░░░░░░░░░░░░⸩ 5%
\x1b[2K\x1b[1A\x1b[2K\x1b[G⸨█░░░░░░░░░░░░░░░░░░⸩ 10%
\x1b[2K\x1b[1A\x1b[2K\x1b[G⸨██░░░░░░░░░░░░░░░░░░⸩ 15%
... (17 more updates)
\x1b[2K\x1b[1A\x1b[2K\x1b[G⸨████████████████████⸩ 100%

Each update adds 30+ bytes of escape codes, resulting in many redundant lines that an AI would have to process.

Why simple ANSI stripping isn’t enough

Stripping ANSI codes removes the visual decorations but leaves the duplicated lines, which still waste token space. To achieve true compression you need to collapse lines that are overwritten by cursor‑movement codes, keeping only the final state of each line.

Resulting in something like:

added 847 packages in 12s
💾 contextzip: 12,847 → 142 chars (99% saved)

This yields up to 99 % savings on animation‑heavy output.

Using ContextZip to compress ANSI output

contextzip can automatically collapse these animations:

cargo install contextzip
eval "$(contextzip init)"

You can also run it via npx:

npx contextzip
  • GitHub repository:
  • npm package:
0 views
Back to Blog

Related posts

Read more »