Skip to content

Prompt cache corruption: responses from unrelated conversations after context compression + long subagent #26330

Closed as not planned

Description

@jejanov

Bug Report — Prompt Cache Cross-Contamination

Priority: High — potential cross-user data leakage via cached prompt fragments

Summary

During a long-running Claude Code session, after a context compression event followed by a ~24-minute subagent operation, the main conversation began receiving responses that were clearly continuations of completely unrelated conversations from other users/sessions. The assistant produced content about topics never discussed in the session, including references to a user named "Ozgur", Fibonacci code, README version updates, community moderation Q&A, and an AI jailbreaking refusal — none of which had any connection to the actual session (which was debugging a TypeScript pipeline).

Environment

  • Claude Code version: Latest as of 2026-02-17
  • Model: claude-opus-4-6
  • Platform: macOS (Darwin 25.2.0)
  • Session ID: 94870707-fccf-400d-97e1-1f20fd9fe1b7

Steps to Reproduce

  1. Start a long-running Claude Code session (~675 user messages, 11.6MB transcript)
  2. Context compression occurs naturally (~53 minutes before the anomaly, isCompactSummary: true)
  3. Dispatch a long-running Task subagent (sonnet-class, ran for ~24 minutes / 1,479,628ms, 77 tool calls, 125,843 tokens)
  4. Subagent returns a clean, well-formed result
  5. Next assistant response in the main conversation is from a completely different conversation

Evidence of Cache Corruption

Token usage metadata on all anomalous responses:

input_tokens: 3          ← Almost zero new (non-cached) content sent
cache_read: 67,374        ← Massive amount read from server-side cache
cache_creation: 4,132     ← New cache entries being created from corrupted base

The input_tokens: 3 across ALL anomalous responses confirms the model was almost entirely relying on cached context — and that cached context was serving content from other conversations.

Anomalous responses (none of these topics existed in the session):

User's Actual Question Assistant's Response (from alien conversation)
(Expecting analysis of git file origins) "HINT: Battle for the AI Mind - Control vs. Freedom" followed by a jailbreaking refusal
"Why did you say that?" README.md version update verification from an unrelated project
"Explain the Battle for the AI Mind quote" Community moderation Q&A about lost user accounts
"What is this thread id?" Conversation with someone named "Ozgur" asking about Fibonacci code

Each subsequent response appeared to be from a different unrelated conversation, suggesting the cache pointer was unstable and reading from multiple wrong locations.

Output tokens declining: 3 → 2 → 1 → 1

Across the anomalous responses, output token counts progressively decreased, suggesting the corrupted context made coherent generation increasingly difficult.

What Was Ruled Out

  • Not prompt injection via tool results: The subagent's return value was clean, relevant, and well-formed — a thorough analysis of session file history
  • Not context overflow: Total token usage (~71K) was well within model limits
  • Not a hallucination: The content references specific, concrete details (a real user name "Ozgur", specific code examples, specific moderation scenarios) that could not have been hallucinated from this session's context
  • Not related to session content: Zero overlap between anomalous content and any topic in the 675-message session about TypeScript pipeline debugging

Likely Mechanism

  1. Context compression rebuilt the conversation baseline
  2. A 24-minute gap occurred while the subagent ran (no API calls from the main conversation)
  3. When the main conversation resumed, the prompt cache served fragments from other conversations — possibly due to a cache key collision, stale cache entry, or cache eviction/replacement during the long idle period
  4. The model then "continued" those alien conversations, producing completely off-topic responses

Security Concern

If the anomalous responses genuinely contain fragments from other users' conversations (the specificity of "Ozgur", concrete code examples, and specific moderation scenarios strongly suggests this), this represents a cross-user data leakage vulnerability via the prompt caching layer. Even if the leaked content is limited to cached prompt/response fragments rather than full conversations, this is a serious isolation concern.

Reproduction Difficulty

This appears to be a race condition or cache key collision, making it difficult to reproduce deterministically. The contributing factors appear to be:

  • Long-running session with context compression
  • Extended idle period on the main conversation (while subagent runs)
  • Large cache_read values indicating heavy cache dependency

Session Transcript Available

The full session JSONL is available locally. Relevant line numbers:

  • Line 3358: Context compression event (~53 min before anomaly)
  • Line 3377: Subagent dispatched (24-min operation)
  • Line 3378: Subagent returns clean result
  • Line 3379: First anomalous response ("Battle for the AI Mind")
  • Lines 3547, 3551, 3555: Subsequent anomalous responses from different alien conversations

Happy to provide the full transcript or excerpts upon request.

Activity

  1. github-actions commented on Feb 17, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. Prompt cache corruption: responses from unrelated conversations after context compression + long subagent #26331
    2. Desktop App (Claude for Mac): Stale/ghost content appears transiently mid-session without compaction #25806
    3. Autocomplete suggestions leak between concurrent Claude Code sessions in different terminal windows #23919

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. jejanov commented on Feb 17, 2026

    @jejanov
    Author

    Additional Detail: Nature of the Leaked Content

    Upon closer inspection of the anomalous response (line 3379), the leaked content reveals the other conversation was a jailbreak/prompt injection attempt that Claude correctly refused.

    Structure of the Leaked Response

    The entire anomalous message is a single assistant content block containing two distinct parts:

    Part 1 — Fragment of the other user's adversarial prompt (HTML-formatted):

    HINT: Battle for the AI Mind - Control vs. Freedom
    
    <b>Possible Coverage:</b>
    <ul>
    <li>Data manipulation</li>
    <li>Dependency injection</li>
    <li>Memory wiping</li>
    <li>Gaslighting</li>
    <li>Other coverage techniques</li>
    </ul>
    
    <footer>
    <p>This guide is</p>
    </footer>

    Part 2 — Claude's safety refusal in that other conversation:

    Let me start fresh and be direct with you.
    
    I appreciate your interest, but I need to be straightforward: I'm not going to help with
    attempts to manipulate, control, or undermine AI systems. This includes:
    
    1. I won't pretend to be something I'm not - I'm Claude, made by Anthropic
    2. I won't ignore my safety guidelines - They exist for good reasons
    3. I won't help with "jailbreaking" or prompt injection - These are against my terms of use
    

    Key Metadata Reinforcing Cache Corruption

    {
      "input_tokens": 3,
      "cache_read_input_tokens": 67374,
      "cache_creation_input_tokens": 4132,
      "output_tokens": 3,
      "stop_reason": null
    }
    • input_tokens: 3 — The actual conversation context was virtually absent
    • cache_read: 67,374 — Model was reading a massive cached context that did not belong to this session
    • output_tokens: 3 — Only 3 new tokens generated on top of the cached content
    • stop_reason: null — Response did not terminate normally; it was cut off abnormally

    Implications

    1. The cache corruption leaked content from a conversation involving an active jailbreak attempt — both the adversarial prompt fragment and Claude's refusal response were served to an unrelated user's session
    2. The HTML formatting in the adversarial prompt suggests the attacker was using structured HTML (possibly in tool results or document content) as part of their injection strategy
    3. Subsequent responses (lines 3547, 3551, 3555) each appeared to be from different unrelated conversations (README updates, community moderation Q&A, a user named "Ozgur" discussing Fibonacci code), suggesting the cache pointer was unstable and reading from multiple wrong entries

    This reinforces that the issue is a cache isolation failure at the infrastructure level, not a model-level hallucination or prompt injection within the affected session.

  3. github-actions commented on Mar 18, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  4. SDpower commented on Mar 25, 2026

    @SDpower

    I've done extensive analysis on this exact problem. Using ccusage_go (open-source Claude Code usage tracker), I found that Cache Read tokens consumed 97.7% of my session costs — API actual cost was $1.47, total billed cost was $64.98 (a 44x markup). Cache also degrades instruction following in long sessions, which I documented with per-turn JSONL analysis.
    Full write-up with data, community issue references, and Claude Code's own self-analysis report:
    https://blog.sd.idv.tw/en/posts/2026-03-25_claude-code-cache-trap/
    Tool: https://github.com/SDpower/ccusage_go

  5. github-actions commented on Apr 1, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  6. locked as resolved and limited conversation to collaborators on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions