anthropics / anthropics/claude-code

[BUG] /context subtracts the Skills total from "System tools", so the total never changes when skills are added or removed

Ouverte
#94,346 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
area:core area:skills bug has repro platform:macos
Langage dominant
Python
Étoiles
145k
Forks
23.1k
Métriques de merge des PR
Métriques de PR en attente

Description

## Summary

`/context` computes the "System tools" row as (estimated tokens of loaded built-in tool definitions) minus (the Skills total). In 2.1.270 the skill listing is not part of any tool definition, so the subtraction just moves tokens between the two rows. Enabling or disabling plugins that ship skills changes the Skills row and the System tools row by the same amount in opposite directions, and the reported total stays identical. The real prompt does change. The API's reported input tokens drop by about 4.3k when I disable three skill-heavy plugins, and `/context` shows no difference at all.

## Environment

- Claude Code 2.1.270, native install, macOS (Darwin 25.6.0, arm64)
- Model claude-fable-5-1
- `ENABLE_TOOL_SEARCH=true` in `~/.claude/settings.json` (the behavior is the same with it unset; tool search is on either way and the deferred rows are identical in every run below)

## Steps to reproduce

1. Enable a few plugins that ship skills. I used `figma@claude-plugins-official`, `miro@claude-plugins-official`, and `slack@claude-plugins-official`, which together add about 4.1k tokens of skill descriptions.
2. Start a fresh session and run `/context`. Note "System tools", "Skills", and the total.
3. Disable those plugins and repeat in a fresh session.

Print mode reproduces it too, which makes the comparison easy:

```
claude -p "/context"
claude -p "/context" --settings '{"enabledPlugins":{"figma@claude-plugins-official":false,"miro@claude-plugins-official":false,"slack@claude-plugins-official":false}}'
```

## What I see

| Row | Plugins on | Plugins off |
|---|---|---|
| System prompt | 3.9k | 3.9k |
| System tools | 2.2k | 6.3k |
| System tools (deferred) | 13.9k | 13.9k |
| Skills | 5.9k | 1.8k |
| Total | 14.4k | 14.4k |

System tools + Skills is 8.1k in both columns. Nothing else moved.

For the real prompt size I sent one trivial request per configuration with `--output-format json` and summed `input_tokens`, `cache_creation_input_tokens`, and `cache_read_input_tokens`:

| Configuration | Prompt tokens from the API |
|---|---|
| Plugins on | 26,684 |
| Plugins off | 22,359 |

So the prompt is about 4.3k tokens smaller with the plugins off, and it is also 8k to 12k larger than what `/context` reports in either case.

## What I expected

Disabling plugins that carry 4.1k of skill descriptions should lower the `/context` total by about that much, and the System tools row should not change when nothing about the built-in tools changed.

## Likely cause

From what I can see in the 2.1.270 bundle, the category builder does roughly this:

```js
let rs = builtInToolTokens - skillTokens;
if (rs > 0) categories.push({ name: "System tools", tokens: rs });
...
if (skillTokens > 0) categories.push({ name: "Skills", tokens: skillTokens });
```

That subtraction assumes the skill listing lives inside the Skill tool's description and is therefore already counted in `builtInToolTokens`. In this version the Skill tool's description just says the available skills appear in a system-reminder listing, and the listing is delivered separately. `builtInToolTokens` is 8.1k regardless of how many skills are installed, so subtracting the Skills total from it under-reports System tools by exactly the Skills amount and leaves the listing out of the total entirely.

The same estimate also appears to skip the MCP server instruction blocks and the names-only deferred tool list, which would explain most of the remaining gap between 14.4k and the API's 22k to 27k. I have not traced those two as carefully as the skills case, so treat that part as a guess.

## Suggested fix

Stop subtracting `skillTokens` from `builtInToolTokens`, and count the skill listing where it is actually sent (or keep it as its own row and add it to the total). If the estimate is going to stay an estimate, it would also help to say so next to the total when it can't be reconciled with the API's usage numbers.

Related but different: #21966 (deferred MCP tools not shown, now addressed by the deferred rows), #72218 (undercount of injected agent persona content), #31002 (built-in tools deferred behind ToolSearch).

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.