anthropics / anthropics/claude-code

[BUG] /context reports 0 tokens for MCP server instructions that cost 653 per turn

Open
#94,832 0 comments 0 reactions 0 assignees View on GitHub
area:cost area:mcp bug has repro
Dominant language
Python
Stars
145k
Forks
23.1k
PR merge metrics
PR metrics pending

Description

### Preflight Checklist

- [x] I have searched [existing issues](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20state%3Aopen%20label%3Abug) 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?

A MCP server's `instructions` field reaches the model and is billed on every turn, but `/context` attributes it 0 tokens and leaves the total unchanged.

Measured against the API, same host binary 2.1.273, neutral directory, tokens counted rather than estimated:

| Run | Prompt tokens | Delta |
| --- | --- | --- |
| no server | 26,686 | |
| server, instructions emptied | 26,732 | +46 |
| server, full instructions | 27,385 | +699 |

The tool costs 46 tokens, the instructions 653, on every turn. `/context` credits the tool with 66 and the instructions with nothing. The totals for the two images are identical at 16.7k, and the sum of the printed categories confirms nothing was silently folded in.

The instructions used are 1,953 characters, 345 words. That is deliberately under the 2,048-character per-server cap Claude Code applies before building the system prompt, so this measures the omission and not the cap. The cap bounds what one server can hide, not what a session accumulates. The omission is per server.

This is distinct from `anthropics/claude-ai-mcp` anthropics/claude-ai-mcp#93 and anthropics/claude-ai-mcp#131, where the field never reaches the model. Here it does. See the control under Steps to Reproduce.

### What Should Happen?

Server instructions should appear in the `/context` breakdown, as their own category or alongside the server's MCP tools, and count toward the total. A user adding a server currently has no way to see what it costs per turn.

### Error Messages/Logs

```shell

```

### Steps to Reproduce

Two images, `custom/` copied twice, differing only in `config/mcp.json`. Both carry the same Python layer and pinned `mcp` SDK; only `ctx-mcp` declares the server.

```sh
scripts/build-image.sh ctx-base
scripts/build-image.sh ctx-mcp
scripts/benchmark-image.sh --model claude-opus-5 ctx-base:2.1.273 | tee context-base.txt
scripts/benchmark-image.sh --model claude-opus-5 ctx-mcp:2.1.273 | tee context-mcp.txt
diff context-base.txt context-mcp.txt
```

The diff is twelve lines: an MCP Tools section appears, the tool is credited 66 tokens, the instructions appear nowhere, the total is unchanged.

**Control that the instructions do reach the model.** The last line of `instructions.txt` defines a safe word. With the server attached the model answers it; without, it reports having no server instructions in context. Placing it last means truncation would have removed it first, so the field arrives whole.

Everything is on branch `context-omits-mcp-instructions` of : `ctx-base/`, `ctx-mcp/`, the two outputs, the diff, and the method in `ctx-mcp/README.md`. The benchmark runs offline with no API key and sends nothing to Anthropic.

### Claude Model

Opus

### Is this a regression?

I don't know

### Last Working Version

_No response_

### Claude Code Version

2.1.273

### Platform

Anthropic API

### Operating System

macOS

### Terminal/Shell

Terminal.app (macOS)

### Additional Information

`/context` estimates the startup context while the API figures include what a live session adds on top, which is why 16.7k and 26,686 differ. The claim rests on the deltas between the three runs, taken in an identical environment, not on either absolute.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the /context command and the MCP context assembly, then run the listed scripts/build-image.sh and scripts/benchmark-image.sh commands against ctx-base and ctx-mcp from the linked reproduction branch. Compare the output with the supplied diff and API token deltas. Done means MCP server instructions appear in the /context breakdown and are included in its total.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.