Image Upload Exceeds 5 MB Size Limit in API Request

Open 💬 20 comments Opened Jun 15, 2025 by NerdNestFelix

Bug Description
i keep getting this for anything I type API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.
0.content.1.image.source.base64: image exceeds 5 MB maximum: 5607404 bytes > 5242880
bytes"}}

Environment Info

  • Platform: darwin
  • Terminal: WarpTerminal
  • Version: 1.0.24
  • Feedback ID: 179665c7-616b-4a83-b1d2-80438c4658d9

Errors

```jsonBug Description
i keep getting this for anything I type API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.
0.content.1.image.source.base64: image exceeds 5 MB maximum: 5607404 bytes > 5242880
bytes"}}

Environment Info

  • Platform: darwin
  • Terminal: WarpTerminal
  • Version: 1.0.24
  • Feedback ID: 179665c7-616b-4a83-b1d2-80438c4658d9

Errors

[{"error":"Error: Command failed: security find-generic-password -a $USER -w -s \"Claude Code\"\nsecurity: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.\n\n    at genericNodeError (node:internal/errors:983:15)\n    at wrappedFn (node:internal/errors:537:14)\n    at checkExecSyncError (node:child_process:882:11)\n    at execSync (node:child_process:954:15)\n    at HZ (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:659:3921)\n    at file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:582:8863\n    at Q (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:526:17199)\n    at tJ (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:582:8009)\n    at HS (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:582:7090)\n    at T6 (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:582:11202)","timestamp":"2025-06-15T06:25:07.968Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64: image exceeds 5 MB maximum: 5607404 bytes > 5242880 bytes\"}}\n    at h6.generate (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1329:12578)\n    at Lw.makeStatusError (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1344:2082)\n    at Lw.makeRequest (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1344:5257)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async ME2.K11.showErrors (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:22008)\n    at async K11 (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:12203)\n    at async ME2 (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:21854)\n    at async file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:17103\n    at async yt1 (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:5151)\n    at async Fu (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:17073)","timestamp":"2025-06-15T06:26:10.388Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64: image exceeds 5 MB maximum: 5607404 bytes > 5242880 bytes\"}}\n    at h6.generate (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1329:12578)\n    at Lw.makeStatusError (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1344:2082)\n    at Lw.makeRequest (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1344:5257)\n    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n    at async ME2.K11.showErrors (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:22008)\n    at async K11 (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:12203)\n    at async ME2 (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:21854)\n    at async file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:17103\n    at async yt1 (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:5151)\n    at async Fu (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:17073)","timestamp":"2025-06-15T06:26:18.797Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64: image exceeds 5 MB maximum: 5607404 bytes > 5242880 bytes\"}}\n    at h6.generate (file:///Users/<my-user>/.nvm/versions/node/v22.12.0/lib/

Note: Error logs were truncated.

[{"error":"Error: Command failed: security find-generic-password -a $USER -w -s \"Claude Code\"\nsecurity: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.\n\n at genericNodeError (node:internal/errors:983:15)\n at wrappedFn (node:internal/errors:537:14)\n at checkExecSyncError (node:child_process:882:11)\n at execSync (node:child_process:954:15)\n at HZ (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:659:3921)\n at file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:582:8863\n at Q (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:526:17199)\n at tJ (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:582:8009)\n at HS (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:582:7090)\n at T6 (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:582:11202)","timestamp":"2025-06-15T06:25:07.968Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64: image exceeds 5 MB maximum: 5607404 bytes > 5242880 bytes\"}}\n at h6.generate (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1329:12578)\n at Lw.makeStatusError (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1344:2082)\n at Lw.makeRequest (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1344:5257)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async ME2.K11.showErrors (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:22008)\n at async K11 (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:12203)\n at async ME2 (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:21854)\n at async file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:17103\n at async yt1 (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:5151)\n at async Fu (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:17073)","timestamp":"2025-06-15T06:26:10.388Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64: image exceeds 5 MB maximum: 5607404 bytes > 5242880 bytes\"}}\n at h6.generate (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1329:12578)\n at Lw.makeStatusError (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1344:2082)\n at Lw.makeRequest (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1344:5257)\n at process.processTicksAndRejections (node:internal/process/task_queues:105:5)\n at async ME2.K11.showErrors (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:22008)\n at async K11 (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:12203)\n at async ME2 (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:21854)\n at async file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:17103\n at async yt1 (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:5151)\n at async Fu (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1698:17073)","timestamp":"2025-06-15T06:26:18.797Z"},{"error":"Error: 400 {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"messages.0.content.1.image.source.base64: image exceeds 5 MB maximum: 5607404 bytes > 5242880 bytes\"}}\n at h6.generate (file:///Users/felixflores/.nvm/versions/node/v22.12.0/lib/


**Note:** Error logs were truncated.

View original on GitHub ↗

20 Comments

ARanch · 1 year ago

also getting this. I originally started in [session 1] with inputting an image that was too large.

I then scaled the image below the 5 mb and 8000 px requirement, but i kept getting the same error om [session 1].
then tried renaming the file, but still got the same error [session 1].
then spawned [session 2] fresh, and in this session it worked.

stevysmith · 1 year ago

If you tap "esc" twice you can go back to a previous message before this happened and fork the conversation from there so you can continue

mendelgordon · 8 months ago

Same issue here

evolsb · 8 months ago

Additional Finding: Clipboard Caching Bug

I'm experiencing a related but distinct behavior that suggests a clipboard caching issue:

Symptoms

  • Pasting a screenshot from CleanShot triggers 5MB error: image exceeds 5 MB maximum: 5290848 bytes > 5242880 bytes
  • Every subsequent paste triggers the same error, even with different/smaller screenshots
  • Restarting Claude Code temporarily fixes the issue (one successful paste, then error returns)

Key Observation

The same 5MB error occurs regardless of the actual size of newly pasted images, suggesting Claude Code is:

  1. Caching the first large image in memory
  2. Reusing cached clipboard data instead of reading fresh clipboard content
  3. Only clearing the cache on restart

Reproduction Steps

  1. Take a screenshot with CleanShot (generates ~5MB PNG on Retina display)
  2. Paste into Claude Code → Get 5MB error
  3. Take a different, smaller screenshot
  4. Paste again → Same 5MB error (proving it's using cached data)
  5. Restart Claude Code
  6. Paste works once, then error repeats

Environment

  • Platform: macOS (Darwin 24.6.0)
  • Screenshot tool: CleanShot
  • Display: Retina (generates 2x/3x resolution screenshots)
  • Claude Code Version: Latest

Workaround

Configure CleanShot to export JPEG at 80-90% quality instead of PNG to stay under 5MB limit.

Impact

This makes the existing 5MB issue worse because once triggered, the session is permanently broken for all image pastes, not just oversized ones. The cache should either:

  • Not exist (always read fresh from clipboard)
  • Clear after each paste
  • Automatically compress images before caching
itinance · 7 months ago

BUMP on this. Once this happens, there is no way back to normal any more. You can add more messages in the chat without any image and it will stick with this error. You need to restart the claude cli

stevysmith · 7 months ago
BUMP on this. Once this happens, there is no way back to normal any more. You can add more messages in the chat without any image and it will stick with this error. You need to restart the claude cli

This helps in existing chats https://github.com/anthropics/claude-code/issues/2104#issuecomment-3063043033

github-actions[bot] · 6 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

cybersader · 6 months ago

Still been happening to me

reyequis · 5 months ago

This should not be closed. It is still an issue. Still unable to recover from this. One issue mentioned using /export, but this isn't available to me with vscode running in Ubuntu WSL 2.

2 images exceed the API limit (5.0 MB): Image 9: 6.3 MB, Image 10: 6.3 MB. Please resize these images before sending.

/compact
Error: Error during compaction: ImageSizeError: 2 images exceed the API limit (5.0 MB): Image 9: 6.3 MB, Image 10: 6.3 MB. Please resize these images before sending.
reyequis · 5 months ago

Workaround: Automated Session Repair for "Image Exceeds 5MB" Error

For anyone experiencing the persistent "image exceeds 5 MB maximum" error that continues even after you stop sending images, the issue is (appears to be) that the oversized Base64-encoded payload remains in your local .jsonl session history. Because Claude Code resends the conversation history with every new message, the session remains "corrupted" until that specific line is removed or replaced.
I have put together a comprehensive repair prompt and manual workflow that identifies these oversized lines (threshold: 5,242,880 bytes) and replaces them with a lightweight summary placeholder. This preserves the session integrity while allowing you to resume work without starting over.

This is working for me, on my system. I hope it works for you, too. That said, use with caution and make sure you create backups of the files before modification!

---

~~~

# Repair Oversized Image Session Bug

This prompt fixes the Claude Code bug where pasting an image >5MB corrupts a session, causing all subsequent messages to fail with "image exceeds 5 MB maximum" errors.

**Related issues:**
- https://github.com/anthropics/claude-code/issues/2104
- https://github.com/anthropics/claude-code/issues/8039
- https://github.com/anthropics/claude-code/issues/8202

---

## Option 1: Standalone Prompt

Copy and paste this entire block when you encounter the error:

Fix my broken Claude Code session. I'm getting "image exceeds 5 MB maximum" errors that persist even for text-only messages.

Session selection (use the first option that applies):

  • If I specified a session file path: use that file directly
  • If I specified a session ID: find the .jsonl file with that ID in ~/.claude/projects/*/
  • If I said "list sessions": show me all sessions with their IDs, file sizes, dates, and first prompts, then wait for me to pick one
  • If I specified a custom sessions directory: look there instead of ~/.claude/projects/
  • Otherwise: auto-detect by scanning all recent .jsonl files in ~/.claude/projects/*/ for files with lines exceeding 5,242,880 bytes

Repair steps:

  1. Locate the target session file based on the selection method above
  2. Create a backup with .backup extension
  3. Find all lines containing images: grep -n '"type":"image"' <file>
  4. Check each image line's size: sed -n '<N>p' <file> | wc -c
  5. For lines over 5,242,880 bytes (5MB), replace the entire line with:

{"type":"summary","summary":"[Image removed - exceeded 5MB limit]","uuid":"REMOVED-<line-number>"}

  1. Report: session file path, number of images removed, old vs new file size

Idempotency: Skip lines already containing "REMOVED-" in the uuid. If no oversized images found, report that the session appears clean.

Resuming the session:
After repair, the session can be resumed via:

  • Terminal: claude --resume <session-id>
  • VSCode: Reload window (Ctrl+Shift+P → "Developer: Reload Window"), then use session picker
---

## Option 2: Add to CLAUDE.md

Add this section to your project's `CLAUDE.md` file:

Emergency Commands

Fix Oversized Image Bug

When I say "fix image bug" or "fix session images", run this repair:

  1. Session selection (first matching option):
  • Explicit path provided → use that file
  • Session ID provided → find matching .jsonl in ~/.claude/projects/*/
  • "list sessions" → show all sessions (ID, size, date, first prompt) and wait for selection
  • Custom directory provided → search there instead
  • Default → auto-detect by scanning recent .jsonl files for lines >5,242,880 bytes
  1. Backup: copy to .backup extension
  1. Identify oversized image lines (>5,242,880 bytes per line) using:
  • grep -n '"type":"image"' <file> for line numbers
  • Check line sizes with sed -n '<N>p' <file> | wc -c
  1. Replace oversized lines with: {"type":"summary","summary":"[Image removed - exceeded 5MB limit]","uuid":"REMOVED-<line-number>"}
  1. Report: file path, images removed, size reduction
  1. Provide resume instructions:
  • Terminal: claude --resume <session-id>
  • VSCode: Reload window, then use session picker

Be idempotent. Skip lines with "REMOVED-" in uuid. Report if no oversized images found.


### Example usage:

fix image bug

fix image bug for session 13348384-f296-4f89-a19d-f0d101b06831

fix image bug at /home/user/.claude/projects/-home-user-myproject/abc123.jsonl

fix image bug - list sessions

fix image bug in /custom/path/to/sessions/


---

## Option 3: Manual Fix (if prompt doesn't work)

1. Find your sessions

ls -la ~/.claude/projects/

2. Navigate to your project's folder (escape leading dash with --)

cd -- ~/.claude/projects/-home-username-projectname/

3. List sessions by size (largest first)

ls -lhS *.jsonl

4. Optionally, view session details from index

cat sessions-index.json | python3 -m json.tool

5. Backup

cp SESSIONID.jsonl SESSIONID.jsonl.backup

6. Find image lines and their sizes

grep -n '"type":"image"' SESSIONID.jsonl | cut -d: -f1 | while read line; do
size=$(sed -n "${line}p" SESSIONID.jsonl | wc -c)
if [ "$size" -gt 5242880 ]; then
echo "OVERSIZED - Line $line: $size bytes"
else
echo "OK - Line $line: $size bytes"
fi
done

7. Replace oversized lines with the summary placeholder

Note: Linux users use -i; macOS users use -i ''

Replace LINE_NUMBER with the actual number from step 6

Linux (GNU sed):

sed -i 'LINE_NUMBERs/.*/{"type":"summary","summary":"[Image removed - exceeded 5MB limit]","uuid":"REMOVED-LINE_NUMBER"}/' SESSIONID.jsonl

macOS (BSD sed):

sed -i '' 'LINE_NUMBERs/.*/{"type":"summary","summary":"[Image removed - exceeded 5MB limit]","uuid":"REMOVED-LINE_NUMBER"}/' SESSIONID.jsonl

8. Resume via terminal or reload VSCode window and use session picker

claude --resume SESSIONID


---

## Notes

- **The 5MB Threshold:** The limit is **5,242,880 bytes of text**. Because Base64 encoding adds ~33% overhead, an original image file larger than **~3.75 MiB** will exceed the limit once pasted into the session.
- **Context Persistence:** The bug persists because failed images remain in the JSONL history. Since Claude Code sends the entire conversation history with every turn, the oversized payload triggers a failure on every subsequent message.
- **Shell Navigation:** Session folders use path-based naming often starting with dashes (e.g., `-home-user-dev`). Use `cd -- <path>` to signal to the shell that the dash is part of the name and not a command-line argument.
- **Cleanup:** Backup files (.backup) are not automatically removed. Delete them manually once you have verified the session is stable and resumes correctly.
- **VSCode Sync:** If the session is missing from the sidebar after repair, use the Command Palette (`Ctrl/Cmd+Shift+P` -> **Developer: Reload Window**) to refresh the extension state.

~~~

L13w · 5 months ago

This is still happening. Ran Chris-Irving's script and the sessions are working again:

Session | Before | After | Saved
10a38b4b | 21MB | 7MB | 14MB
1bf9310d | 26MB | 14MB | 11MB
388b8601 | 11MB | 4MB | 6MB
4b6cf629 | 14MB | <1MB | 14MB
8d074528 | 14MB | <1MB | 14MB
b681caa2 | 9MB | 4MB | 5MB
efff2cea | 34MB | 19MB | 14MB
87f3fcec | 8MB | 2MB | 6MB

vincentsch · 5 months ago

Adding a CLI (-p) case: the error is clear, but what hurts is that it leaves the session in a broken state. Even compaction failed afterward with the same 400 error.

  • OS: Linux (Xubuntu)
  • Claude Code: 2.0.53
  • Error: “image exceeds 5 MB maximum”
  • Timeframe: Jan 2026

Impact: after the error appears, the session doesn’t recover; compaction and retries both fail.

sarob · 5 months ago

i have been getting these msg in prompts over the past couple of days

  • Image base64 size (5.0 MB) exceeds API limit (5.0 MB). Please resize the image before sending.
  • prompt is too long
  • they are starting to impact my ability to work as I am regularly losing the conversation history. updating a plan markdown file is a workaround, but it is slowing me down.
  • when I try to report these bugs, the Fin AI Agent regularly hallucinates and tries to get me to use non-existing methods to report bugs, e.g. use /doctor or /bug or /debug within claude code.
  • when I ask for a human to help, I get a boilerplate we will email you and then nothing else. The communication stops. No more chat and no email that anything will happen.
  • I like the claude code tooling, but this is a poor experience with little hope of being repaired.
  • I am posting here as a last ditch option of getting any type of support
Robvienne · 4 months ago

I found an easy solution which worked just fine for me, i click on my very last input (before the bug appeared) and click "Message Actions --> Fork Conversation from here", usually its alot easier to start from that point again rather than starting a new conversation. Let me know if this works for you. Have a nice one

sarob · 4 months ago

Since losing conversation history was a recurring problem for me, I built a bash dashboard to track all Claude Code operational files (CLAUDE.md, MEMORY.md, conversation logs) across projects. It helps you see what Claude knows per project and clean up old session logs.

Zero dependencies, single script: https://github.com/sarob/claude-ops

10ANT · 4 months ago
### Workaround: Automated Session Repair for "Image Exceeds 5MB" Error For anyone experiencing the persistent "image exceeds 5 MB maximum" error that continues even after you stop sending images, the issue is (appears to be) that the oversized Base64-encoded payload remains in your local .jsonl session history. Because Claude Code resends the conversation history with every new message, the session remains "corrupted" until that specific line is removed or replaced. I have put together a comprehensive repair prompt and manual workflow that identifies these oversized lines (threshold: 5,242,880 bytes) and replaces them with a lightweight summary placeholder. This preserves the session integrity while allowing you to resume work without starting over. This is working for me, on my system. I hope it works for you, too. That said, use with caution and make sure you create backups of the files before modification! `` `markdown # Repair Oversized Image Session Bug This prompt fixes the Claude Code bug where pasting an image >5MB corrupts a session, causing all subsequent messages to fail with "image exceeds 5 MB maximum" errors. **Related issues:** - https://github.com/anthropics/claude-code/issues/2104 - https://github.com/anthropics/claude-code/issues/8039 - https://github.com/anthropics/claude-code/issues/8202 --- ## Option 1: Standalone Prompt Copy and paste this entire block when you encounter the error: ` Fix my broken Claude Code session. I'm getting "image exceeds 5 MB maximum" errors that persist even for text-only messages. **Session selection** (use the first option that applies): - If I specified a session file path: use that file directly - If I specified a session ID: find the .jsonl file with that ID in ~/.claude/projects/*/ - If I said "list sessions": show me all sessions with their IDs, file sizes, dates, and first prompts, then wait for me to pick one - If I specified a custom sessions directory: look there instead of ~/.claude/projects/ - Otherwise: auto-detect by scanning all recent .jsonl files in ~/.claude/projects/*/ for files with lines exceeding 5,242,880 bytes **Repair steps:** 1. Locate the target session file based on the selection method above 2. Create a backup with .backup extension 3. Find all lines containing images: grep -n '"type":"image"' <file> 4. Check each image line's size: sed -n '<N>p' <file> | wc -c 5. For lines over 5,242,880 bytes (5MB), replace the entire line with: {"type":"summary","summary":"[Image removed - exceeded 5MB limit]","uuid":"REMOVED-<line-number>"} 6. Report: session file path, number of images removed, old vs new file size **Idempotency:** Skip lines already containing "REMOVED-" in the uuid. If no oversized images found, report that the session appears clean. **Resuming the session:** After repair, the session can be resumed via: - Terminal: claude --resume <session-id> - VSCode: Reload window (Ctrl+Shift+P → "Developer: Reload Window"), then use session picker ` --- ## Option 2: Add to CLAUDE.md Add this section to your project's CLAUDE.md file: ` ## Emergency Commands ### Fix Oversized Image Bug When I say "fix image bug" or "fix session images", run this repair: 1. **Session selection** (first matching option): - Explicit path provided → use that file - Session ID provided → find matching .jsonl in ~/.claude/projects/*/ - "list sessions" → show all sessions (ID, size, date, first prompt) and wait for selection - Custom directory provided → search there instead - Default → auto-detect by scanning recent .jsonl files for lines >5,242,880 bytes 2. Backup: copy to .backup extension 3. Identify oversized image lines (>5,242,880 bytes per line) using: - grep -n '"type":"image"' <file> for line numbers - Check line sizes with sed -n '<N>p' <file> | wc -c 4. Replace oversized lines with: {"type":"summary","summary":"[Image removed - exceeded 5MB limit]","uuid":"REMOVED-<line-number>"} 5. Report: file path, images removed, size reduction 6. Provide resume instructions: - Terminal: claude --resume <session-id> - VSCode: Reload window, then use session picker Be idempotent. Skip lines with "REMOVED-" in uuid. Report if no oversized images found. ` ### Example usage: ` fix image bug ` ` fix image bug for session 13348384-f296-4f89-a19d-f0d101b06831 ` ` fix image bug at /home/user/.claude/projects/-home-user-myproject/abc123.jsonl ` ` fix image bug - list sessions ` ` fix image bug in /custom/path/to/sessions/ ` --- ## Option 3: Manual Fix (if prompt doesn't work) ` # 1. Find your sessions ls -la ~/.claude/projects/ # 2. Navigate to your project's folder (escape leading dash with --) cd -- ~/.claude/projects/-home-username-projectname/ # 3. List sessions by size (largest first) ls -lhS *.jsonl # 4. Optionally, view session details from index cat sessions-index.json | python3 -m json.tool # 5. Backup cp SESSIONID.jsonl SESSIONID.jsonl.backup # 6. Find image lines and their sizes grep -n '"type":"image"' SESSIONID.jsonl | cut -d: -f1 | while read line; do size=$(sed -n "${line}p" SESSIONID.jsonl | wc -c) if [ "$size" -gt 5242880 ]; then echo "OVERSIZED - Line $line: $size bytes" else echo "OK - Line $line: $size bytes" fi done # 7. Replace oversized lines with the summary placeholder # Note: Linux users use -i; macOS users use -i '' # Replace LINE_NUMBER with the actual number from step 6 # Linux (GNU sed): sed -i 'LINE_NUMBERs/.*/{"type":"summary","summary":"[Image removed - exceeded 5MB limit]","uuid":"REMOVED-LINE_NUMBER"}/' SESSIONID.jsonl # macOS (BSD sed): sed -i '' 'LINE_NUMBERs/.*/{"type":"summary","summary":"[Image removed - exceeded 5MB limit]","uuid":"REMOVED-LINE_NUMBER"}/' SESSIONID.jsonl # 8. Resume via terminal or reload VSCode window and use session picker claude --resume SESSIONID ` --- ## Notes - **The 5MB Threshold:** The limit is **5,242,880 bytes of text**. Because Base64 encoding adds ~33% overhead, an original image file larger than **~3.75 MiB** will exceed the limit once pasted into the session. - **Context Persistence:** The bug persists because failed images remain in the JSONL history. Since Claude Code sends the entire conversation history with every turn, the oversized payload triggers a failure on every subsequent message. - **Shell Navigation:** Session folders use path-based naming often starting with dashes (e.g., -home-user-dev). Use cd -- <path> to signal to the shell that the dash is part of the name and not a command-line argument. - **Cleanup:** Backup files (.backup) are not automatically removed. Delete them manually once you have verified the session is stable and resumes correctly. - **VSCode Sync:** If the session is missing from the sidebar after repair, use the Command Palette (Ctrl/Cmd+Shift+P -> **Developer: Reload Window**) to refresh the extension state. ` ``

Not all heroes wear capes

sarob · 4 months ago

Its a simple solution. Thx! I also created a shell script to monitor and clear conversation logs. ~ SeanOn Feb 17, 2026, at 12:11, Rob @.***> wrote:Robvienne left a comment (anthropics/claude-code#2104)
I found an easy solution which worked just fine for me, i click on my very last input (before the bug appeared) and click "Message Actions --> Fork Conversation from here", usually its alot easier to start from that point again rather than starting a new conversation. Let me know if this works for you. Have a nice one

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

HikariKogen · 4 months ago
HBT89 · 3 months ago

This is a persistent and annoying issue. Several bugs and feature requests are related to this and so far no progress from Antrhopic

HBT89 · 3 months ago

Does anyone actually work at this company who looks at GitHub?