[BUG] /context dumps the rendered ASCII widget into conversation context (~1.6k tokens per call)

Resolved 💬 2 comments Opened May 2, 2026 by vinaychandranp Closed May 4, 2026

Summary

When the user runs /context, the entire rendered TUI widget — including the ~400 box-drawing glyphs (, , , ) used for the visual fill bar — is captured as the slash command's output and injected verbatim into the conversation as a tool/command result the model sees on the next turn.

Each /context call adds roughly 1.6k tokens of pure visualization noise to the message history. Three checks ≈ 5k tokens. The tool whose entire purpose is to help users monitor context usage is itself one of the most expensive context-consuming operations in the harness.

This is the same class of bug as #44808 (/release-notes injecting full changelog).

Repro

claude --system-prompt "x" --strict-mcp-config --tools "" --disallowedTools "LSP"

Then in the TUI:

> hello
> /context     # Messages: 145 tokens
> /context     # Messages: 1.6k tokens   (+1.5k just from the previous widget)
> /context     # Messages: 3.2k tokens   (+1.6k more)

Each invocation adds ~1.6k tokens to Messages, perfectly correlated with the size of the rendered widget echoed into history.

Why it's so expensive

The grid uses Unicode glyphs outside common BPE vocab. Each / is a 3-byte UTF-8 codepoint that tokenizes to ~3 tokens. ~400 cells × ~3 tokens + chrome ≈ 1.5k tokens per render — for information that fits in a 25-token sentence.

Suggested fix

Split the renderer from the tool-result payload. Render the pretty grid for the user's terminal; send the model a structured-data summary instead, e.g.:

Context: 166/1,000,000 tokens (0.0%). System prompt: 21, System tools: 0, Messages: 145, Free: 999,834. Autocompact buffer: 33,000.

Same information, ~25 tokens vs ~1,600. ~64× cheaper, and arguably more useful to the model since it doesn't have to mentally OCR ASCII art back into numbers.

The same pattern likely applies to any other slash command whose output is a TUI visualization (/cost, /status, etc.) — worth auditing.

Environment

  • Claude Code v2.1.126 (native installer, macOS arm64)
  • Opus 4.7 (1M context)

Related

  • #44808 — /release-notes injects full changelog (same bug class)
  • #48269 — /context category breakdown double-counts Messages (the counter itself is also lying, separately)

View original on GitHub ↗

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