[BUG] Missing error handler for "many-image requests" API error causes infinite retry loop

Resolved 💬 3 comments Opened Feb 1, 2026 by SunflowersLwtech Closed Mar 2, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Root Cause Analysis

After analyzing the minified cli.js, I found the bug:

Current error handling (line contains O34()):

if (A.status === 400 && 
    A.message.includes("image exceeds") && 
    A.message.includes("maximum"))
  return Hz({ content: O34() });

This handler only catches errors whose message contains BOTH "image exceeds" AND "maximum".

However, the API can also return an error like:

"At least one of the image dimensions exceed max allowed size for many-image requests: 2000 pixels"

This message contains "many-image requests" but not "maximum", so it is not caught by the existing condition and falls through.

Suggested Fix

Add a dedicated handler for the "many-image requests" error:

// Handle many-image error explicitly
if (A.status === 400 &&
    A.message.includes("many-image requests"))
  return Hz({
    content: "Too many images in conversation. Please start a new chat or use smaller images."
  });

Or, make the existing check more flexible so it also covers this case:

if (A.status === 400 &&
    (A.message.includes("image exceeds") ||
     A.message.includes("many-image")))
  return Hz({ content: O34() });

Either approach ensures the error is handled gracefully instead of looping.

Evidence

From cli.js in npm package @anthropic-ai/claude-code:

  • Image size constants show a 2000px limit: M_1 = 2000, P_1 = 2000.
  • Only one image error type is defined: return "image_too_large".
  • There is no handler that checks for the "many-image" substring, so this error message is not covered.

Steps to Reproduce

  1. Load 15+ images in a conversation using the view tool.
  2. Attempt to view an image whose dimensions exceed 2000px.
  3. The API returns HTTP 400 with a "many-image requests" error message.
  4. The error is not caught by the current condition, causing the client to enter an infinite retry loop.

Environment

  • Claude Code: Latest
  • Platform: macOS
  • Model: Opus

What Should Happen?

The error should be caught and handled gracefully with a user-friendly message instead of causing an infinite retry loop.

Error Messages/Logs

Steps to Reproduce

  1. Load 15+ images in a conversation using the view tool.
  2. Attempt to view an image whose dimensions exceed 2000px.
  3. The API returns HTTP 400 with a "many-image requests" error message.
  4. The error is not caught by the current condition, causing the client to enter an infinite retry loop.

Claude Model

None

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

Latest (installed via npm)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗