claude-code - 💡(How to fix) Fix Image paste ID collisions after /compact cause wrong image to be referenced [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52074Fetched 2026-04-23 07:37:15
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

[Image #N] paste IDs are session-local and the counter resets after /compact, so two different pasted images in the same session can both be tagged [Image #1] (or any N). When the model resolves an [Image #N] reference via the compacted summary, it can pick up the wrong image binary. The on-disk cache file (~/.claude/image-cache/<session-id>/<N>.png) is also overwritten when N collides, so the fallback path points to whichever image was pasted most recently under that number.

Claude Code version: 2.1.117 Platform: Windows 11 (native claude.exe)

Root Cause

Because N is reused across the compact boundary, the path \<sid>\1.png also resolves to different images at different points in the same session.

Fix Action

Fix / Workaround

Users hit "Claude is looking at the wrong image" when they paste multiple images in a long session, especially after /compact. Workarounds (single-image turns, /clear, absolute path references) are workable but obscure the root cause.

Code Example

// real data
{"type":"user","message":{"role":"user","content":[
  {"type":"text","text":"[Image #1]"},
  {"type":"image","source":{"type":"base64","media_type":"image/png","data":"..."}}
]},"imagePasteIds":[1], ...}

// meta follow-up with just a path string
{"type":"user","isMeta":true,"message":{"role":"user","content":[
  {"type":"text","text":"[Image: source: C:\Users\<me>\.claude\image-cache\<sid>\1.png]"}
]}, ...}
RAW_BUFFERClick to expand / collapse

Summary

[Image #N] paste IDs are session-local and the counter resets after /compact, so two different pasted images in the same session can both be tagged [Image #1] (or any N). When the model resolves an [Image #N] reference via the compacted summary, it can pick up the wrong image binary. The on-disk cache file (~/.claude/image-cache/<session-id>/<N>.png) is also overwritten when N collides, so the fallback path points to whichever image was pasted most recently under that number.

Claude Code version: 2.1.117 Platform: Windows 11 (native claude.exe)

Reproduction

  1. Start a Claude Code session.
  2. Paste an image. It's tagged [Image #1] and saved to ~/.claude/image-cache/<sid>/1.png.
  3. Paste several more images ([Image #2], [Image #3], ...).
  4. Run /compact.
  5. Paste a new, unrelated image. It is also tagged [Image #1] and overwrites 1.png on disk. The transcript JSONL's imagePasteIds field still records [1] for it.
  6. Ask a follow-up that references the earlier [Image #1]. The model conflates the two.

Evidence from my own transcripts

Session 9817be82-ad86-44df-bc27-dda94fd1bdd9.jsonl from ~/.claude/projects/. Each row is a user turn with an attached image — paste_id is the value of the imagePasteIds field on the record; SHA1 is the first 12 chars of sha1(base64 image data).

Linepaste_idSHA1 prefixUser message (truncated)
552155a05f2937f1I don't see it [Image #1]
22582b874e52e8c19no... there's 2 issues ...
23163c32fd2c02048this is what I see from the desktop [Image #3]
242143b496518b398I see it in desktop [Image #4] ...
273552b2b2c9c23ccwhy do I get these responses? [Image #5]
35216c8139158797d[Image #6]
352578a4e51ca626dhere is that menu [Image #7]
(compact boundary around here)
464818f205e1a6477 (different image)I only want new sessions [Image #1]
473929e113dadfe03 (different image)I see it! Some problems though...
479433982abcb4530 (different image)I see the new thread [Image #3]
486541e4bd9ae2a01 (different image)[Image #4]
490056ce928eafddc (different image)better! couple things to fix ...
494167cf86b2f19e5 (different image)still missing the last interaction [Image #6]
4989789ff38552055 (different image)no... it got worse...
50558, 9c8c6ce8c1e51, c3d6c3149906still not working... [Image #8] [Image #9]

All seven paste IDs (1–7) get reassigned to different image binaries after compaction, inside one session.

What Claude Code writes to the transcript

Each paste produces two user turns in the JSONL:

// real data
{"type":"user","message":{"role":"user","content":[
  {"type":"text","text":"[Image #1]"},
  {"type":"image","source":{"type":"base64","media_type":"image/png","data":"..."}}
]},"imagePasteIds":[1], ...}

// meta follow-up with just a path string
{"type":"user","isMeta":true,"message":{"role":"user","content":[
  {"type":"text","text":"[Image: source: C:\Users\<me>\.claude\image-cache\<sid>\1.png]"}
]}, ...}

Because N is reused across the compact boundary, the path \<sid>\1.png also resolves to different images at different points in the same session.

Expected behavior

Paste IDs should be globally unique within a session (monotonic across compactions), and cache filenames should reflect that. Either:

  • Continue incrementing N past compaction, so [Image #8] is never reused, OR
  • Use a content-addressed filename (e.g., first 8 chars of sha1) instead of a counter.

Impact

Users hit "Claude is looking at the wrong image" when they paste multiple images in a long session, especially after /compact. Workarounds (single-image turns, /clear, absolute path references) are workable but obscure the root cause.

Environment

  • Claude Code 2.1.117
  • Windows 11 (native claude.exe build)
  • Image cache dir: ~/.claude/image-cache/<session-id>/<N>.png
  • Transcripts: ~/.claude/projects/*/*.jsonl with imagePasteIds field on user records

extent analysis

TL;DR

The issue can be fixed by ensuring that paste IDs are globally unique within a session, either by continuing to increment the counter past compaction or by using a content-addressed filename.

Guidance

  • To verify the issue, check the imagePasteIds field in the transcript JSONL files and the corresponding image cache files to see if the same paste ID is being reused for different images after compaction.
  • One possible solution is to modify the code to continue incrementing the paste ID counter past compaction, so that [Image #8] is never reused.
  • Another possible solution is to use a content-addressed filename, such as the first 8 characters of the SHA1 hash of the image data, instead of a counter.
  • To mitigate the issue, users can use workarounds such as single-image turns, /clear, or absolute path references, but these do not address the root cause.

Example

// example of a user turn with a unique paste ID
{
  "type": "user",
  "message": {
    "role": "user",
    "content": [
      {
        "type": "text",
        "text": "[Image #8]"
      },
      {
        "type": "image",
        "source": {
          "type": "base64",
          "media_type": "image/png",
          "data": "..."
        }
      }
    ]
  },
  "imagePasteIds": [8]
}

Notes

The issue is specific to Claude Code version 2.1.117 and may not be present in other versions. The solution will require modifications to the code that handles paste IDs and image caching.

Recommendation

Apply a workaround, such as using single-image turns or absolute path references, until a fix can be implemented to ensure globally unique paste IDs within a session.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Paste IDs should be globally unique within a session (monotonic across compactions), and cache filenames should reflect that. Either:

  • Continue incrementing N past compaction, so [Image #8] is never reused, OR
  • Use a content-addressed filename (e.g., first 8 chars of sha1) instead of a counter.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Image paste ID collisions after /compact cause wrong image to be referenced [1 participants]