[Bug] Prompt cache re-written on every user turn in fresh sessions of one repo; fixed by CLAUDE_CODE_DISABLE_AUTO_MEMORY=1

Status Open
Reported on v2.1.281
Maintainer reply None cached
Activity 0 comments · opened Sep 24, 2026

Bug Description
Prompt cache re-written on every user turn in fresh sessions of one repo; fixed by CLAUDE_CODE_DISABLE_AUTO_MEMORY=1

Summary

In one git repo, every new user message in a fresh session re-writes the whole message part of the prompt at the cache-write rate. cache_read_input_tokens stays at the tools+system prefix (25,979) and cache_creation_input_tokens is ~24.6k on every turn. The same user config in another repo caches normally. CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 fixes it in the affected repo; an empty autoMemoryDirectory does not.

Environment

  • Claude Code 2.1.281 (native install), macOS (Darwin 25.6.0)
  • claude-opus-5-5[1m], Max plan (OAuth), promptCacheTtl: "1h"
  • Plugins: context-mode (its SessionStart hook adds ~4.6k chars of additionalContext), playwright, claude-md-management. A terminal app adds command hooks on every event. The control repo below has the same plugins and hooks.

Repro

Fresh session in the repo, three short prompts ("2+2? number only", "3+3?", "4+4?"), no tool calls. Values are cache_creation_input_tokens / cache_read_input_tokens for turns 2 and 3.

| Variant | Turn 2 | Turn 3 |
|---|---|---|
| affected repo, default | 24,665 / 25,979 | 24,710 / 25,979 |
| auto permission mode, CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false | 24,661 / 25,979 | 24,706 / 25,979 |
| --setting-sources user,project | 28,073 / 25,979 | 28,118 / 25,979 |
| --setting-sources user,local | 20,135 / 25,979 | 20,180 / 25,979 |
| empty autoMemoryDirectory (via --settings) | 24,419 / 26,011 | 24,464 / 26,011 |
| CLAUDE_CODE_DISABLE_MEMORY_PERIODIC_RESYNC=1 | 24,664 / 25,979 | 24,709 / 25,979 |
| CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 | 84 / 49,665 | 43 / 49,752 |
| another repo, same user config | 85 / 68,070 | 43 / 68,158 |

A long-running session in the same repo, started earlier the same day, does not show it: its user turns write 0.9k-1.4k tokens.

Impact

  • ~24.6k tokens at the 1h cache-write rate on every user message.
  • Prompt suggestions never appear, because the cache_write gate (more than 10k) trips on every turn.
  • The [PROMPT CACHE] break detector does not log it: cache_read never drops, it only never grows.

Notes

  • A logging proxy (ANTHROPIC_BASE_URL) showed the message prefix byte-identical between turns 3 and 4; only cache_control moved to the new last block. cache_read still stayed flat. With a custom base URL, however, the memory-off control also broke and tool deferral was off, so that code path may differ.
  • The request messages contain role: "system" entries: the SessionStart hook context is messages[1], and a <total_tokens> system reminder is the last message and holds the final cache_control.
  • Possibly related: #83913 (prefix rewrite caused by PreToolUse/PostToolUse additionalContext during history rebuild). This case has no tool calls.

Environment Info

  • Platform: darwin
  • Terminal: Orca
  • Version: 2.1.281
  • Feedback ID: f50eeb5c-42b6-4bd9-88ba-22716fffb427

Errors

[]

View original on GitHub ↗