claude-code - 💡(How to fix) Fix [BUG] /context commands blows up context

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Error Messages/Logs

Root Cause

  1. Load huge MCP into Claude (mine had approx 1500 tools)
  2. run /context command
  3. run /context command again and observe the difference
  4. [OPTIONAL] ask claude why it compacted the conversation, if it was because of the context command

Code Example

The autocompact wasn't from your prompt — it was from /context itself. That command isn't free to run: its output (the <local-command-stdout> block you saw on screen)
  gets captured into Messages, and that output enumerates every one of the 1467 deferred MCP tools with per-tool token costs. So each /context call dumps roughly 70–145k
  tokens of tool catalog into the conversation.

  Your trajectory this session:
  - Messages started around 45.2k
  - First /context → captured its own output → ~52.9k
  - Second /context → captured the much-larger annotated listing → 197.5k (98.7%)
  - 197.5k Messages + 33k autocompact buffer + system/tools overhead = 218.3k / 200k → 109%
  - Next prompt had nowhere to land, so autocompact fired before processing it

  The irony: checking how much context you have left consumes the context you were checking on. In a session with this many deferred tools, /context is effectively a
  ~145k-token operation the second time around.

---

/context
Context Usage
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀   Opus 4.7
     ⛀ ⛁ ⛀ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   claude-opus-4-7
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   21.6k/200k tokens (11%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   Estimated usage by category
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 8.3k tokens (4.2%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System tools: 11.2k tokens (5.6%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Memory files: 584 tokens (0.3%)
     ⛶ ⛶ ⛶ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛁ Skills: 1.4k tokens (0.7%)
     ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛁ Messages: 80 tokens (0.0%)
Free space: 145.4k (72.7%)
Autocompact buffer: 33k tokens (16.5%)

---

/context
Context Usage
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀   Opus 4.7
     ⛀ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   claude-opus-4-7
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   64.6k/200k tokens (32%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   Estimated usage by category
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ System prompt: 8.3k tokens (4.2%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ System tools: 11.2k tokens (5.6%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ MCP tools: 200 tokens (0.1%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ Memory files: 584 tokens (0.3%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ Skills: 1.4k tokens (0.7%)
Messages: 187.9k tokens (93.9%)
Autocompact buffer: 33k tokens (16.5%)

---
RAW_BUFFERClick to expand / collapse

Preflight Checklist

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

What's Wrong?

I was playing around with lazy loading and I've loaded MCP with approx 1500 tools. It is working fine, but if you run the /context command, it will blown up the LLM context itself. Running the /context command injects a massive payload of tool catalog data into the conversation history. This creates an "observer effect" where checking the context violently consumes it. Furthermore, the UI displays mathematically impossible usage metrics on subsequent runs. Here's summary from Claude:

The autocompact wasn't from your prompt — it was from /context itself. That command isn't free to run: its output (the <local-command-stdout> block you saw on screen)
  gets captured into Messages, and that output enumerates every one of the 1467 deferred MCP tools with per-tool token costs. So each /context call dumps roughly 70–145k
  tokens of tool catalog into the conversation.

  Your trajectory this session:
  - Messages started around 45.2k
  - First /context → captured its own output → ~52.9k
  - Second /context → captured the much-larger annotated listing → 197.5k (98.7%)
  - 197.5k Messages + 33k autocompact buffer + system/tools overhead = 218.3k / 200k → 109%
  - Next prompt had nowhere to land, so autocompact fired before processing it

  The irony: checking how much context you have left consumes the context you were checking on. In a session with this many deferred tools, /context is effectively a
  ~145k-token operation the second time around.

I've confirmed this behavior by running /context command twice in clean session without any prompts:

First context command:

❯ /context
  ⎿  Context Usage
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀   Opus 4.7
     ⛀ ⛁ ⛀ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   claude-opus-4-7
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   21.6k/200k tokens (11%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   Estimated usage by category
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System prompt: 8.3k tokens (4.2%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ System tools: 11.2k tokens (5.6%)
     ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶ ⛶   ⛁ Memory files: 584 tokens (0.3%)
     ⛶ ⛶ ⛶ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛁ Skills: 1.4k tokens (0.7%)
     ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝ ⛝   ⛁ Messages: 80 tokens (0.0%)
                           ⛶ Free space: 145.4k (72.7%)
                           ⛝ Autocompact buffer: 33k tokens (16.5%)

Immediately after that, without any prompts I've run the /context command second time:

❯ /context
  ⎿  Context Usage
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛀   Opus 4.7
     ⛀ ⛀ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   claude-opus-4-7
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   64.6k/200k tokens (32%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   Estimated usage by category
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ System prompt: 8.3k tokens (4.2%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ System tools: 11.2k tokens (5.6%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ MCP tools: 200 tokens (0.1%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ Memory files: 584 tokens (0.3%)
     ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁ ⛁   ⛁ Skills: 1.4k tokens (0.7%)
                           ⛁ Messages: 187.9k tokens (93.9%)
                           ⛝ Autocompact buffer: 33k tokens (16.5%)

The output of the first /context call (including the per-tool token costs for 1,467 tools) is captured into the Messages block, inflating it from 80 tokens to 187.9k tokens on the next turn.

The second output contains broken math. The header reads 64.6k/200k tokens (32%), while the breakdown line items sum to over 208k tokens (with Messages alone claiming 187.9k / 93.9%).

What Should Happen?

/context command should not affect the context itself.

Error Messages/Logs

Steps to Reproduce

  1. Load huge MCP into Claude (mine had approx 1500 tools)
  2. run /context command
  3. run /context command again and observe the difference
  4. [OPTIONAL] ask claude why it compacted the conversation, if it was because of the context command

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.153

Platform

Other

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING