Bash tool output with ANSI escape sequences causes context overflow and unrecoverable API errors

Resolved 💬 4 comments Opened Feb 17, 2026 by mlilback Closed Mar 18, 2026

Description

When a Bash tool call captures large output containing ANSI escape sequences (e.g., colored log output from a subprocess), the raw escape sequences are stored in the context window without stripping. This can quickly consume ~35KB+ of context, trigger repeated API errors, and leave Claude Code completely unresponsive to any commands except /exit.

Steps to Reproduce

  1. Run a command via the Bash tool that produces verbose colored stderr output (e.g., a Rust service with tracing producing DEBUG-level logs with ANSI color codes)
  2. The command output contains hundreds of lines of ANSI-encoded log lines like:

``
[2m2026-02-17T18:25:15.784395Z[0m [34mDEBUG[0m [1;34menoch::job_runner[0m...
``

  1. The Bash tool captures all of this (stdout + stderr) into the context
  2. Context window fills up rapidly due to the verbose escape sequences

Expected Behavior

One or more of:

  • The Bash tool should strip ANSI escape sequences from captured output before storing in context
  • The Bash tool's 30,000 character truncation should be applied more aggressively when escape sequences are detected
  • When context overflow triggers API errors, Claude Code should remain responsive (allow /compact, /clear, or other recovery commands — not just /exit)

Actual Behavior

  • ANSI escape sequences are stored verbatim in the context window
  • ~35KB of colored log output triggers context overflow
  • Repeated API errors occur with no way to recover
  • Claude Code becomes completely unresponsive to all commands except /exit
  • The entire session's work is effectively lost (must start a new session)

Workaround

Redirect output to a file and read it separately:

./run.sh > /tmp/output.txt 2>&1; echo "Exit: $?"

Then use the Read tool to examine the file. This avoids the Bash tool capturing the large output directly.

Environment

  • macOS (Darwin 24.6.0)
  • Claude Code CLI
  • Model: Claude Opus 4.6
  • The subprocess producing the output was enoch (Rust binary using tracing with Bunyan-style colored JSON output)

Impact

This is particularly problematic for long-running sessions where significant work has been done. The context overflow makes the session unrecoverable, forcing a fresh start. The ANSI sequences add significant byte overhead compared to plain text — stripping them before storing in context would substantially reduce the risk.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗