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

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

Mô tả

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

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

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

Đánh giá

Lĩnh vực
cli, documentation
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Sôi nổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/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.