anthropics / anthropics/claude-code

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

未关闭
#89,659 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
area:cost area:tui bug has repro platform:windows
主要语言
Python
星标
145k
派生
23.1k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

这个仓库没有索引到贡献指南

调研方向

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.

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, cli
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
需要澄清
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。