[BUG] Bash tool stdout containing data:image URLs is intercepted as image block, causing unrecoverable API 400 "Could not process image" session corruption

Resolved 💬 5 comments Opened Mar 20, 2026 by NodeDiver Closed Apr 28, 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?

When a Bash tool command outputs a string containing data:image/...;base64, to stdout (e.g. via echo), Claude Code intercepts that output and converts it into an image content block before sending it to the API. If the base64 data is truncated or partial, the API rejects it with a 400 error, which permanently corrupts the session. Every subsequent message — including plain text like "test" — triggers the same error, making the session completely unusable.

What Should Happen?

Claude CLI should not intercept Bash tool stdout as image data. Bash tool output is text and should be treated as text. If image detection from stdout is intentional by design, the CLI should:

  1. Validate the base64 data before constructing an image block
  2. On validation failure, surface a warning without corrupting session state
  3. Allow the session to continue normally after the error

Error Messages/Logs

API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"},"request_id":"req_011CZDqY1re9PNNJrPW1SK5b"}

After the initial error, every subsequent message (even plain text) triggers:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Could not process image"}}

The session becomes permanently unrecoverable until the corrupted image block is manually removed from the .jsonl session file.

Steps to Reproduce

  1. Have an image file on disk (e.g. logo.png)
  2. Ask Claude to embed the image as base64 into an HTML file
  3. Claude runs a Bash command similar to:

LOGO_B64=$(base64 -w0 logo.png) && echo "data:image/png;base64,${LOGO_B64:0:40}..."

  1. Claude CLI intercepts the stdout, detects the data:image/ prefix, and constructs an image content block with truncated/invalid base64
  2. API returns 400 "Could not process image"
  3. Session is now permanently broken — every new message triggers the same error

Workaround: manually clean the session file:
grep -v "data:image" ~/.claude/projects/<project>/<session>.jsonl > /tmp/clean.jsonl && mv /tmp/clean.jsonl ~/.claude/projects/<project>/<session>.jsonl

Claude Model

None

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.80 (Claude Code)

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

  • Platform: Linux (Ubuntu 24.04)
  • Shell: zsh inside tmux
  • Terminal: Kitty
  • The bug is triggered specifically by Bash tool stdout containing a data:image/ URI prefix, not by the user uploading an image manually
  • The session corruption is persistent across /exit and rejoin — the corrupted image block remains in the .jsonl history and is re-sent on every API call
  • /compact also fails because the API call required to compact also triggers the same 400 error
  • The only recovery path is manual .jsonl editing or starting a new session with --new
  • Related issues: #16169 (session corruption on unprocessable image), #12750 (no pre-validation before adding image to context)

View original on GitHub ↗

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