Skip to content

Image Upload Exceeds Size Limit Causing Persistent API Request Failure #2939

Done

Description

@alessandrobologna

Bug Description
after submitting an image too large, the context is polluted and any other request returns the error API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.17.content.1.image.source.base64.data: At least one of the image dimensions exceed max allowed size for many-image requests: 2000 pixels"}}

Environment Info

  • Platform: darwin
  • Terminal: cursor
  • Version: 1.0.41
  • Feedback ID: 635919c9-d04d-4562-9842-2a0a15d8e011

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 JI (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:702:3921)\n    at file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:623:9038\n    at Q (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:526:13327)\n    at _X (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:623:8184)\n    at w_ (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:623:7265)\n    at U9 (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:623:11432)","timestamp":"2025-07-03T16:45:23.855Z"},{"error":"Error: Tool mcp__puppeteer__puppeteer_click not found\n    at dT2 (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1958:5596)\n    at ZU (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:65:19802)\n    at UP (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:42556)\n    at wP (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:38105)\n    at o$ (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:38033)\n    at MU (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:37887)\n    at EJ (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:34977)\n    at f5 (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:65:4822)\n    at DB (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:32233)\n    at A.Q.updateContainer (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:71:1835)","timestamp":"2025-07-03T16:45:27.222Z"},{"error":"Error: Tool mcp__puppeteer__puppeteer_click not found\n    at dT2 (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1958:5596)\n    at ZU (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:65:19802)\n    at UP (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:42556)\n    at wP (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:38105)\n    at o$ (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:38033)\n    at MU (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:37887)\n    at EJ (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:34977)\n    at f5 (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:65:4822)\n    at DB (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:32233)\n    at A.Q.updateContainer (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:71:1835)","timestamp":"2025-07-03T16:45:27.236Z"},{"error":"Error: Tool mcp__puppeteer__puppeteer_screenshot not found\n    at dT2 (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1958:5596)\n    at ZU (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:65:19802)\n    at UP (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:42556)\n    at wP (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:38105)\n    at o$ (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:38033)\n    at MU (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:37887)\n    at EJ (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:34977)\n    at f5 (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:65:4822)\n    at DB (file:///Users/alessandro/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:67:32233)\n    at A.Q.updateContainer (file:///Users

Note: Error logs were truncated.

Activity

  1. added
    bug
    has repro
    platform:macos
    on Jul 3, 2025
  2. baryon commented on Oct 3, 2025

    @baryon

    I didn’t upload any images and still encountered this issue—I only asked CC to modify the copy on the webpage and didn’t upload any images to him. After this error appeared, even the /compact command started returning the same error.

    /compact 
      ⎿ Error: Error during compaction: Error: API Error: 400 {"type":"error","error":{"type":"
        invalid_request_error","message":"messages.95.content.12.image.source.base64.data: At 
        least one of the image dimensions exceed max allowed size: 8000 
        pixels"},"request_id":"req_********************"}
    
  3. gthb commented on Oct 3, 2025

    @gthb

    Found my session afflicted with this same thing soon (within a day) after I started working with the chrome-devtools MCP server. That was going great until the session was entirely incapacitated by this error. And yep, /compact is failing too in this session — presumably because it's trying to read that same poisoned item in the context. I'll hazard a guess that a screenshot of the remote-controlled Chrome window (or of a canvas that I have in there in a scrollable container) landed in the context despite violating some size-limit invariant, and then there's no coming back from that.

  4. saynth-ai commented on Oct 12, 2025

    @saynth-ai

    Error: Error during compaction: Error: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.380.content.0.image.source.base64.data: At least one of
    the image dimensions exceed max allowed size: 8000 pixels"},"request_id":"req_011CU35RmzHC6WGfCL6kKbKB"}

  5. lukasmalkmus commented on Oct 23, 2025

    @lukasmalkmus

    Same here! Would be nice to have a command to remove the bad message from the context to compact or instruct otherwise.

  6. JimSander-uniphore commented on Oct 25, 2025

    @JimSander-uniphore

    My Experience: 12+ Hours of Work Lost

    I encountered this exact issue and lost over 12 hours of productive working history with Claude Code. The session became completely unrecoverable after an image >8000 pixels was added to the context.

    Impact:

    • All subsequent requests returned the same API 400 error
    • No way to remove or compact the problematic message
    • Had to abandon the entire session and lose all conversation history
    • Now extremely hesitant to use images in any Claude Code session due to this risk

    Critical Need: This needs a recovery mechanism urgently. Suggestions:

    • Pre-validate image dimensions before adding to context
    • Provide a command to remove specific messages from context (like /remove-message <index>)
    • Make /compact resilient to skip/remove invalid messages instead of failing
    • Add a /recover command to sanitize corrupted contexts

    This is a severe UX issue that makes the tool feel fragile when working with visual content, especially when using MCP servers that generate screenshots automatically.


    Meta note: This comment was drafted by Claude Code itself—the very tool that caused the problem. Even the offender agrees this needs fixing! 😅

  7. tokmakoff commented on Nov 13, 2025

    @tokmakoff

    /rewind worked for me as a recovery mechanism. I went back in the context stack however-many prompts to before the bad image from Chrome was added.

  8. JoeEarly commented on Nov 18, 2025

    @JoeEarly

    API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.8.content.5.image.source.base64.data: At least one of the image dimensions exceed max allowed size: 8000 pixels"},"request_id":"req_011CVFsFR3Yo8qKa9SEVzj8F"}

    Has any of the dev team looked at this?

  9. vovanrew commented on Nov 18, 2025

    @vovanrew

    Same issue to be

        image dimensions exceed max allowed size: 8000 pixels"},"request_id":"req_011CVFv8L4ojR1WvfaonMrw1"}```
    
  10. JoeEarly commented on Nov 18, 2025

    @JoeEarly

    Same issue to be

        image dimensions exceed max allowed size: 8000 pixels"},"request_id":"req_011CVFv8L4ojR1WvfaonMrw1"}```
    

    Well thanks for stating the obvious fella, my query was more in relation to has anyone looked at this from a dev POV with the view to fixing the ability to recover cleanly

  11. Keeline commented on Nov 24, 2025

    @Keeline

    This is a vexing problem and I have been burned by it many times. Yesterday I decided to take a new approach. I use Claude Code on a MacBook Pro with Sequoia. I asked it to write a Bash script to check the pixel and byte sizes to ensure they are within the limits for any image view. If it is too large, it should use ImageMagick to resize or make a copy with the appropriate specs.

    I further instructed it to add it to CLAUDE.md as a priority rule to use the script every time an image might be read into the session.

    I decided to add some other instructions such as a mandate of using shellcheck on Bash scripts and lint for PHP and Python before they try to run them. I was also tired of nonsensical time references to I required the session to check the current date-time before making a statement.

    I can provide the code for image screening (check_image_previe.sh). It is 154 lines with comments.

    In the CLAUDE.md below I have added backslashes before the triple-backticks for the formatting in github. But they may cause a problem if left in for use. With the right prompt, this would be generated by Claude Code. But it shows the intent.

    Having worked with Claude Code since May 2025, this is hopefully going to rein in some of the most frequent issues I have with it. Something akin to this should be part of the core system. Creating a fatal error loop that can't be resolved without starting a new session is a serious blocker for professional use of an otherwise good system.

    James D. Keeline

    # Claude Code Instructions
    
    ## Image Preview Safety
    **CRITICAL:** Always use `./check_image_preview.sh <image_file>` before reading any image with the Read tool. This prevents Claude Code from attempting to load oversized images that cause infinite error loops and context loss.
    
    ### Image Constraints
    - Maximum file size: 5MB
    - Maximum dimensions: 2000px width OR height
    - Script automatically checks both constraints
    - Use `--fix` flag to auto-create compliant versions
    
    ### Example Usage
    \```bash
    # Check image before viewing
    ./check_image_preview.sh "/path/to/image.jpg"
    
    # Auto-fix oversized images
    ./check_image_preview.sh --fix "/path/to/image.png"
    
    # If it passes, then safe to use:
    # Read "/path/to/image.jpg"
    \```
    
    This workflow prevents system crashes and preserves work context.
    
    ## Script Development Standards
    
    ### Bash Scripts
    Always run shellcheck before finalizing any bash script:
    \```bash
    /opt/homebrew/bin/shellcheck script_name.sh
    \```
    Fix all warnings and errors. Common issues:
    - Quote variables to prevent word splitting: `"$var"`
    - Declare and assign separately: `local var; var=$(command)`
    - Remove unused variables
    
    ### PHP Scripts
    Check syntax before execution:
    \```bash
    php -l script_name.php
    \```
    
    ### Python Scripts
    Use appropriate syntax checkers:
    - `python -m py_compile script.py` (built-in)
    - `flake8 script.py` (if installed)
    - `pylint script.py` (if installed)
    
    **Always lint scripts during development to catch errors early.**
    
    ## Temporal References
    
    **CRITICAL:** Always run `date` command before making any date/time-based statements or assumptions in conversations.
    
    \```bash
    date
    \```
    
    Current session time reference: Sat Nov 22 22:13:24 PST 2025
    
    This ensures accuracy when discussing:
    - File timestamps and modifications
    - Log analysis and debugging
    - Scheduling or time-sensitive operations
    - Historical context of changes%
    
  12. jhilgert commented on Nov 24, 2025

    @jhilgert

    Hey everyone,

    ran into the same problem that an oversized image corrupted my conversation with Claude Code. Since it had been running for 1 hour before - without any additional message from me - I was not able to simply rewind. Thus, I looked into the directory, which stores the conversation files (simple .jsonl files) and then basically asked Claude to fix itself. Here is its solution, which worked like a charm. Hope this helps some people until a proper fix is out:

    Fixing Claude Code Conversation Stuck on Oversized Image

    The Problem

    When Claude Code tries to read an image larger than 5MB, the API rejects it with an error like:

    API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.16.content.2.tool_result.content.0.image.source.base64: image exceeds 5 MB maximum: 6521204 bytes > 5242880 bytes"}}
    

    The base64 image data is already saved in the conversation history (.jsonl file), so every subsequent message keeps sending the same oversized image, causing a loop of API errors. Even new messages won't work.

    The Solution

    1. Find the conversation file

    Conversation files are stored in ~/.claude/projects/<project-path>/ with UUID-style names:

    ls -la ~/.claude/projects/*/
    # Look for files like: e45adf17-b504-4108-87f3-53c5eff292da.jsonl

    2. Identify the problematic lines

    Find which lines are huge (contain base64 image data):

    awk '{print NR, length($0)}' <file>.jsonl | sort -k2 -n -r | head -10

    Lines with millions of bytes are the culprits (normal lines are a few KB at most).

    3. Create a backup

    cp <file>.jsonl <file>.jsonl.backup

    4. Fix with this Python script

    import json
    
    file_path = "<your-file>.jsonl"
    problem_lines = [84, 85, 86]  # 1-indexed line numbers from step 2
    
    with open(file_path, 'r') as f:
        lines = f.readlines()
    
    for line_num in problem_lines:
        idx = line_num - 1  # Convert to 0-indexed
        data = json.loads(lines[idx])
    
        # Get tool_use_id and replace image content with text
        tool_use_id = data['message']['content'][0]['tool_use_id']
        data['message']['content'] = [{
            "tool_use_id": tool_use_id,
            "type": "tool_result",
            "content": "[Image removed - exceeded 5MB limit]"
        }]
    
        # IMPORTANT: Remove toolUseResult entirely (causes render crash if malformed)
        if 'toolUseResult' in data:
            del data['toolUseResult']
    
        lines[idx] = json.dumps(data) + '\n'
    
    with open(file_path, 'w') as f:
        f.writelines(lines)
    
    print("Fixed!")

    5. Restart Claude Code

    The conversation should now load without errors.

    Key Points

    • The fix replaces base64 image data with a text placeholder
    • Must delete toolUseResult key entirely (not just modify it) - otherwise Claude Code crashes trying to render it with Cannot destructure property 'numLines' from null
    • Keep the tool_use_id to maintain conversation continuity
    • Original file size drops dramatically (e.g., 51MB -> 262KB)

    Prevention

    Before reading large images, resize them first:

    # Resize to max 2000px width, quality 80%
    convert large-image.jpg -resize 2000x -quality 80 smaller-image.jpg
    
    # Or use ImageMagick to check size first
    identify -format "%b" image.jpg
  13. 15 remaining items

  14. eeshansrivastava89 commented on Feb 8, 2026

    @eeshansrivastava89

    This is happening for me as well. Using the Claudian plugin with Obsidian. The entire conversation is now blocked after this image size issue.

  15. sebastienkothe commented on Feb 9, 2026

    @sebastienkothe

    Cross-posting from ChromeDevTools/chrome-devtools-mcp#879 where this issue is being discussed from the MCP server side.

    The problem: MCP servers like chrome-devtools-mcp return screenshots as base64 images that can easily exceed Claude API's dimension limits (8000px for single images, 2000px when 20+ images are in context). When this happens, the Claude Code session becomes permanently corrupted — every subsequent message (including /compact) fails with the same API 400 error, making the entire session unrecoverable without manual intervention.

    Why this is a Claude Code issue (not just MCP): While MCP servers could add resizing as a workaround, Claude Code should handle this gracefully regardless of the image source. Specifically:

    • Pre-validate image dimensions before adding to context
    • Make /compact resilient — skip or remove invalid messages instead of crashing on them
    • Provide a recovery command (e.g. /remove-message or /recover) to sanitize corrupted contexts

    Multiple users are impacted across different MCP servers (chrome-devtools, mobile-mcp, Marionette for Flutter) and even direct image paste. The workarounds people have built (CLAUDE.md rules, external sanitizer scripts, manual .jsonl surgery) show this is a real and recurring pain point.

    Ref: ChromeDevTools/chrome-devtools-mcp#879

  16. Berfc commented on Mar 10, 2026

    @Berfc

    I have the same issur for Claude Browser extension:
    messages.5.content.14.image.source.base64.data: At least one of the image dimensions exceed max allowed size for many-image requests: 2000 pixels

  17. OBugroviy commented on Mar 18, 2026

    @OBugroviy

    Wow, this issue still hasn't been fixed!
    I encountered this issue in version 2.1.78 of VS Code.

    Image
  18. sitefinitysteve commented on Mar 18, 2026

    @sitefinitysteve

    Wow, this issue still hasn't been fixed! I encountered this issue in version 2.1.78 of VS Code.

    Nuts eh… it knows it’ll be an issue, so instead of just resizing it and continuing on, just stops and breaks, and that’s I guess just fine?

  19. sebastienkothe commented on Mar 18, 2026

    @sebastienkothe

    Workaround: We ran into this too. Images > 2000px break the session.

    We added this to our CLAUDE.md to force resize after every screenshot capture:

    sips -Z 1600 /path/to/screenshot.png

    sips -Z 1600 resizes the image to fit within 1600px (longest side) while keeping aspect ratio. We chain it after every adb pull or xcrun simctl io call. Not a fix, but it prevents the crash reliably.

  20. yurukusa commented on Mar 30, 2026

    @yurukusa

    /tmp/gh-comment-2939.md

  21. ryanhugh commented on Apr 3, 2026

    @ryanhugh
    Image

    Same issue in the Claude Browser connector

  22. dragonfax commented on Apr 4, 2026

    @dragonfax

    Got this today, no idea what to do. Can't get past it.

    This is in Claude in Chrome.

    Image
  23. XiaTiaoQAQ commented on Apr 6, 2026

    @XiaTiaoQAQ

    Same issue in Claude in Chrome.

  24. msaidbilgehan commented on Apr 6, 2026

    @msaidbilgehan

    I guess the issue getting worse.

    Host: MacOS
    Browser: Chrome Version 146.0.7680.178 (Official Build) (arm64)
    Extension: Claude 1.0.66 - Claude in Chrome (Beta)

    Image
  25. antoinekm commented on Apr 7, 2026

    @antoinekm

    For folks hitting this specifically when using the chrome-devtools-mcp server: I've opened a PR upstream that adds opt-in CLI flags to cap screenshot size before it's embedded in the MCP response.

    PR: ChromeDevTools/chrome-devtools-mcp#1823 (tracked at ChromeDevTools/chrome-devtools-mcp#879)

    The flags let operators cap dimensions and switch to JPEG so a single screenshot can't blow past the per-image dimension limits enforced by hosted LLM APIs (typically in the 2000-8000 px range, sometimes lower when many images are in the same request):

    {
      "mcpServers": {
        "chrome-devtools": {
          "command": "node",
          "args": [
            "/absolute/path/to/chrome-devtools-mcp/build/src/bin/chrome-devtools-mcp.js",
            "--screenshot-format=jpeg",
            "--screenshot-max-width=2000",
            "--screenshot-max-height=2000"
          ]
        }
      }
    }

    (See the PR for instructions on running the branch locally before it's merged.)

    Important caveats:

    1. This only helps if your "context polluted" errors are coming from chrome-devtools-mcp screenshots specifically. Other MCPs that return inline images will still hit the same wall.
    2. It's a per-call cap. Once an oversized image is already in the conversation history, this server-side fix can't retroactively shrink it. You still need to start a new session to recover.
    3. The real fix is the one already discussed in this thread: Claude Code should evict or downsample image content from the replayed history during compaction (or proactively, before hitting the limit), so this stops being a problem for any MCP that returns images. Until that lands, the server-side cap is just a way to delay the inevitable for chrome-devtools-mcp users.

    Posting this here because @OrKoN from the chrome-devtools-mcp team explicitly invited a cross-post in ChromeDevTools/chrome-devtools-mcp#879. Hope it helps anyone blocked in the meantime.

  26. QuicksilverSlick commented on Apr 13, 2026

    @QuicksilverSlick

    💡 Session Recovery Workaround (No ffmpeg needed)

    If your session is bricked by an oversized image, here's a clean recovery method that preserves your full context:

    1. Go to ~/.claude/projects/ (or C:\Users\<You>\.claude\projects\ on Windows)
    2. Find your project folder and locate the most recent .jsonl file (by modified date)
    3. Start a fresh session in your project directory
    4. Run /init to re-initialize project context
    5. Drag the .jsonl file into the chat and tell Claude: "Analyze this session log and get fully caught up on where we left off."

    This works because the .jsonl files contain the complete conversation history. Feeding it into a fresh session gives you all the context without the corrupted state (the stuck oversized image causing the 400 error loop).

    Full write-up with details: #13480 (comment)

  27. bpasero-ant commented on Nov 28, 2026

    @bpasero-ant
    Contributor

    This was fixed in Claude Code 2.1.126, so we're closing this issue. If you disagree, let us know here and we can re-open it. Thanks for reporting!

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

    area:apibughas reproplatform:macos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions