Original Reddit post

If you’ve ever had Claude Code crash with API Error: 400 "Could not process image" and then every subsequent message fails - this hook fixes it permanently. The problem Reading ~8 images in one session accumulates image data in context until the API chokes.Transparent PNGs, oversized images, unusual encodings - all trigger it. Once it happens, the session is bricked. Rewind (Esc Esc) or /clear are your only options. Related GitHub issues: #24387, #13594, #36511, #34566, #39580 and ~15 more. The fix A PreToolUse hook that proxies every image read through a fresh claude --model haiku subprocess: Converts image to safe JPEG (800px, q70, flattens transparency) Haiku analyzes it in its own context Returns text-only description to your main session Zero image data ever enters your context Result Unlimited image reads per session. Stress-tested with 15 images (PNG + JPG, 313B–240KB) - zero errors. Extra features Auto-context - hook reads your session transcript so Haiku knows what you’re asking about (“check if the logo is centered” → Haiku focuses on centering) Direct mode and PostToolUse cleanup - temp files auto-deleted after Read Fallback - if Haiku subprocess fails, passes converted JPEG directly I nstall (2 minutes): mkdir -p ~/.claude/hooks curl -o ~/.claude/hooks/png-safe-read.sh \ ‘https://gist.githubusercontent.com/justi/8265b84e70e8204a8e01dc9f99b8f1d0/raw/png-safe-read.sh’ chmod +x ~/.claude/hooks/png-safe-read.sh Then add hooks to ~/.claude/settings.json - full config in the gist. Gist: https://gist.github.com/justi/8265b84e70e8204a8e01dc9f99b8f1d0 Dependency check: curl -s ‘https://gist.githubusercontent.com/justi/8265b84e70e8204a8e01dc9f99b8f1d0/raw/check-deps.sh’ | bash

Only tested on macOS - would love feedback from Linux/WSL2 users. The hook falls back to ImageMagick if sips isn’t available. submitted by /u/justi84_1

Originally posted by u/justi84_1 on r/ClaudeCode