anthropics / anthropics/claude-code

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

Đang mở
#89,659 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
area:cost area:tui bug has repro platform:windows
Ngôn ngữ chính
Python
Star
145k
Fork
23.1k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

### 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).

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api, cli
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.