Skip to content

chore(context): strip ANSI codes from tool results sent to the LLM#236

Merged
LeeCheneler merged 1 commit intomainfrom
chore/234-strip-ansi-from-llm-tool-results
Mar 29, 2026
Merged

chore(context): strip ANSI codes from tool results sent to the LLM#236
LeeCheneler merged 1 commit intomainfrom
chore/234-strip-ansi-from-llm-tool-results

Conversation

@LeeCheneler
Copy link
Copy Markdown
Owner

Summary

This PR adds a utility function to strip ANSI escape codes from tool results before they are sent to the LLM, ensuring that the LLM receives clean text without formatting codes.

GitHub Issue

Closes #234

What Changed

  • Created a new utility function in with corresponding tests in .
  • Updated to use on tool message content before adding to the conversation.
  • Removed the duplicate function from and imported the new utility.
  • Updated to use the new utility.
  • Added a test in to verify that ANSI escape codes are stripped from tool results.

Notes for Reviewers

  • The function uses a regular expression to remove ANSI escape codes (BIOS ignores this line due to the need for control characters in the regex).
  • This change ensures that tool outputs with color/formatting codes (like those from or Biome official CLI. Use it to check the health of your project or run it to check single files.

Usage: biome COMMAND ...

Available options:
-h, --help Prints help information
-V, --version Prints version information

Available commands:
version Shows the Biome version information and quit.
rage Prints information for debugging.
start Starts the Biome daemon server process.
stop Stops the Biome daemon server process.
check Runs formatter, linter and import sorting to the requested files.
lint Run various checks on a set of files.
format Run the formatter on a set of files.
ci Command to use in CI environments. Runs formatter, linter and import sorting to
the requested files.
init Bootstraps a new biome project. Creates a configuration file with some defaults.
lsp-proxy Acts as a server for the Language Server Protocol over stdin/stdout.
migrate Updates the configuration when there are breaking changes.
search EXPERIMENTAL: Searches for Grit patterns across a project.
explain Shows documentation of various aspects of the CLI.
clean Cleans the logs emitted by the daemon.) do not interfere with the LLM's processing.

… LLM

Tool results with heavy ANSI coloring (e.g. biome/tsc pre-commit output)
can inflate token usage by 5-6x, enough to exceed the context window in
a single message. Strip ANSI from tool result content before adding to
API-bound messages while preserving colored output in the terminal.

Closes #234
@github-actions github-actions Bot added the chore Maintenance, refactoring, or non-user-facing work label Mar 29, 2026
@LeeCheneler LeeCheneler merged commit 1feb1ea into main Mar 29, 2026
4 checks passed
@LeeCheneler LeeCheneler deleted the chore/234-strip-ansi-from-llm-tool-results branch March 29, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, refactoring, or non-user-facing work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: strip ANSI escape codes from tool results sent to the LLM

1 participant