[BUG] /context command injects output twice into conversation context (raw ANSI + rendered markdown), consuming thousands of tokens per invocation

Open 💬 1 comment Opened Jun 17, 2026 by nlopes-r7

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Every time /context is run, its output appears in the conversation as two separate blocks:

  1. <local-command-stdout> — the raw terminal output, packed with ANSI color escape sequences (e.g. [38;2;153;153;153m) on every line
  2. A rendered markdown version of the same data (tables, headers) — outside the stdout block

Both blocks are fed into the model's context window, effectively duplicating the content. Each /context invocation costs thousands of tokens, most of which is noise.

Impact: In a session with many MCP tools registered (e.g. 80+ tools), the /context output is very long. Three invocations of /context in a conversation consumed ~27k tokens — more than the entire conversation history.

What Should Happen?

Strip ANSI codes from local-command-stdout before injecting into context, and emit only one representation (not both raw + rendered).

Built-in commands from Claude should be token-efficient.

Error Messages/Logs

# First message output snippet:

<local-command-stdout> \^[[1mContext Usage\^[[22m\n\^[[38;2;136;136;136m⛁ ⛁ ⛁ \^[[38;2;177;185;249m⛁ \^[[38;2;255;193;7m⛀ \^[[38;2;130;125;189m⛀ \^[[38;2;153;153;153m⛶ ⛶ ⛶ ⛶ \^[[39m  Sonnet 4.6\n\^[[38;2;153;153;153m⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ \^[[39m  \^[[38;2;153;153;153mus.anthropic.claude-sonnet-4-6\^[[39m\n\^[[38;2;153;153;153m⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ \^[[39m  \^[[38;2;153;153;153m9.6k/200k tokens (5%)\^[[39m\n\^[[38;2;153;153;153m⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ \^[[39m\n\^[[38;2;153;153;153m⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ \^[[39m  \^[[38;2;153;153;153m\^[[3m

# Second message output snippet:

## Context Usage\n\n**Model:** us.anthropic.claude-sonnet-4-6  \n**Tokens:** 9.6k / 200k (5%)\n\n###

Steps to Reproduce

1 - Start a fresh new session
2 - Run the /context command several times in a row
3 - Look at the conversation history in ~/.claude/projects/[...]/<conversation>.jsonl

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.169 (Claude Code)

Platform

AWS Bedrock

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

_No response_

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗