anthropics / anthropics/claude-code

[BUG] Prompt suggestions send a second full-context model call per turn, ~doubling token usage

Aperta
#89,659 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
area:cost area:tui bug has repro platform:windows
Lingua principale
Python
Stelle
145k
Fork
23.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

### 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?

With prompt suggestions enabled (the default), Claude Code sends a **second, separate model request on every turn** — a "suggestion mode" call that carries the **entire conversation and the full tool list**. Because it's full-context, it costs almost as much as the actual reply, roughly **doubling per-turn token / quota consumption**. Nothing in the UI indicates a second billed call is happening.

I confirmed it by routing the client through a local proxy and reading the `usage` field of every `POST /v1/messages` response. Per user turn I see two `claude-sonnet-5` requests:

1. the reply (`input=2`, tiny)
2. a second request whose system prompt starts with `[SUGGESTION MODE: Suggest what the user might naturally type next into Claude Code.]`, carrying `n_msgs=20`, all 42 tool definitions, and ~60k tokens of cached context.

Setting `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false` removes the second request entirely, which confirms the suggestion feature is the cause.

### What Should Happen?

Generating a next-prompt suggestion should not cost as much as answering the user. Either:
- make suggestions opt-**in**, or
- generate them with a cheaper model (e.g. Haiku) and a trimmed context instead of the full conversation + all tool definitions, or
- at minimum, surface that suggestions issue a separate billed model call.

### Error Messages/Logs

Captured token usage for a single `ok` turn (warm cache), via mitmproxy reading the `usage` field. No secrets included — token counts only.

**Before (default, suggestions on) — two Sonnet calls per turn:**

| call | model | input | cache_read | cache_write | output |
|------|-------|-------|-----------|-------------|--------|
| reply | claude-sonnet-5 | 2 | 60,381 | 68 | 4 |
| suggestion | claude-sonnet-5 | 504 | 60,449 | 4 | 9 |

Suggestion request system prompt begins:

[SUGGESTION MODE: Suggest what the user might naturally type next into Claude Code.]

**After (`CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false`) — one Sonnet call per turn:**

| call | model | input | cache_read | cache_write | output |
|------|-------|-------|-----------|-------------|--------|
| reply | claude-sonnet-5 | 2 | 59,956 | 0 | 4 |

### Steps to Reproduce

1. Start a local intercepting proxy: `mitmdump -s capture.py`, where the addon parses the `usage` field of each `POST /v1/messages` response (`input_tokens`/`cache_*` from the `message_start` SSE event, `output_tokens` from `message_delta`).
2. Point Claude Code at it: set `HTTPS_PROXY=http://127.0.0.1:8080` and `NODE_EXTRA_CA_CERTS` to the mitmproxy CA cert (the Node client ignores the OS cert store). Restart the app.
3. Send a prompt that triggers no tools and a fixed reply: `Reply with exactly the word ok and nothing else. Do not use any tools.`
4. Observe **two** `claude-sonnet-5` requests per turn — the reply and a `[SUGGESTION MODE...]` request carrying full context.
5. Add `"CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false"` to the `env` block in settings.json, restart, repeat step 3 — now only **one** request per turn.

### Claude Model

Sonnet (default)

### Is this a regression?

I don't know

### Last Working Version

_No response_

### Claude Code Version

2.1.241

### Platform

Anthropic API

### Operating System

Windows

### Terminal/Shell

Other

### Additional Information

- Workaround for anyone hitting this: add `"env": { "CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION": "false" }` to settings.json.
- Related: #74826 (acknowledges suggestions carry a token cost, but frames it as an opt-in tradeoff — this report shows it is on by default and full-context), #52979 (baseline overhead for trivial prompts).

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start by reproducing the two-request behavior with capture.py, mitmdump, and the settings.json environment override described in the report. Trace the prompt-suggestion request path and determine which proposed resolution is accepted; done means the selected behavior is implemented and the capture shows no unnecessary full-context billed call, with suggestions still behaving as intended.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api, cli
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Attiva
Chiarezza
Da chiarire
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.