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

Abierto
#92,444 0 comentarios 0 reacciones 0 asignados Ver en GitHub
area:cost bug documentation has repro
Lenguaje dominante
Python
Estrellas
145k
Forks
23.1k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Área
cli, documentation
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Activo
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.