anthropics / anthropics/claude-code
[BUG] /effort mid-session invalidates the prompt cache on Sonnet 5 and Opus 5 (full rewrite on Opus), docs say no effect; Fable 5.1 unaffected
- 主要言語
- Python
- スター
- 145k
- フォーク
- 23.1k
- PR マージ指標
- PR 指標を取得中
説明
### Bug description
Anthropic's own prompt-caching docs state effort is "not part of the cache key... changing it mid-session has no effect on the cache" (https://code.claude.com/docs/en/prompt-caching). Empirically this holds only for Fable 5.1. On Sonnet 5 and Opus 5, a mid-session `/effort` change invalidates the cache — partially on Sonnet, fully on Opus.
This resolves the apparent contradiction between #61984 (Opus 4.7: full/near-full cache miss on effort change) and #63962 (repro showing cache fully preserved, model unspecified but consistent with Fable): both were correct, for different models. Neither issue was fixed — both were auto-closed by the stale bot for inactivity.
### Reproduction
One interactive session per model, ~65-78K token base context (a short pasted text + one Q&A to establish it), effort held steady for a control turn, then switched twice. Numbers are `cache_read_input_tokens` / `cache_creation_input_tokens` read directly from each session's transcript.
| Model | Turn | Effort | ctx | read | write |
|---|---|---|---|---|---|
| Sonnet 5 | control | high→high | 77.6K | 77.4K | 0.17K |
| Sonnet 5 | switch 1 | high→low | 77.8K | 51.3K | 26.5K |
| Sonnet 5 | switch 2 | low→medium | 77.9K | 45.4K | 32.5K |
| Opus 5 | control | high→high | 65.8K | 65.7K | 0.13K |
| Opus 5 | switch 1 | high→low | 65.9K | **0** | **65.9K** |
| Opus 5 | switch 2 | low→medium | 66.1K | **0** | **66.1K** |
| Fable 5.1 | control | high→high | 66.8K | 66.6K | 0.22K |
| Fable 5.1 | switch 1 | high→low | 66.9K | 66.8K | 0.14K |
| Fable 5.1 | switch 2 | low→medium | 67.0K | 66.9K | 0.13K |
Opus 5's `read=0` on both switches means the entire prefix was rewritten from scratch, not merely a partial miss — the worst outcome of the three models tested.
### Impact
- Docs are actively wrong for two of the three current model families, leading users to believe changing effort mid-session is free when it isn't (partial cost on Sonnet, full re-cache cost on Opus).
- The in-app confirmation dialog (per #63962) warns of a cache miss unconditionally, which is *correct* for Sonnet/Opus but incorrectly alarms Fable users where the switch is genuinely free.
### Suggested fix
Differentiate the docs and the confirmation dialog by model family rather than treating effort-cache behavior as uniform: Fable 5.1 (free), Sonnet 5 (partial rewrite), Opus 5 (full rewrite).
### Additional context
Single session per model so far, not a repeated-cell matrix, and not tested at larger (~400K) context sizes where the absolute cost is highest — happy to extend this if useful.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
Start by reviewing the prompt-caching documentation linked in the issue and the in-app /effort confirmation dialog referenced there. Reproduce the reported behavior for Sonnet 5, Opus 5, and Fable 5.1 using session transcripts and compare cache_read_input_tokens with cache_creation_input_tokens. Done means the documentation and dialog accurately describe the model-specific cache impact, with any behavior changes covered by the project's relevant checks.
索引モデルが issue の本文から書いたものです。
評価
- 領域
- cli, documentation
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100