PreToolUse Hook Fixes Claude Code Image Crash Problem

A developer has shared a PreToolUse hook that addresses Claude Code's image processing crashes, specifically API Error 400: "Could not process image." The hook intercepts problematic images before they enter the main context, preventing session failures.
Problem Description
The source identifies specific image types that cause Claude Code sessions to crash: PNG files with transparency, large screenshots, and multiple images. Once a problematic image enters the context, every subsequent message errors out. Users can sometimes recover by double-escaping back, but this results in lost context and tokens.
Solution Implementation
The solution is a PreToolUse hook that:
- Intercepts Read calls on images
- Converts images safely before processing
- Proxies them through a Haiku subprocess
- Ensures zero image data enters the main context
This approach prevents the API Error 400 crashes by handling image processing externally before Claude Code attempts to read them.
Technical Details
The hook specifically targets the Read tool use calls that involve images. By using a Haiku subprocess for image conversion and proxying, it isolates potentially problematic image data from the main Claude Code session context. This prevents the cascade of errors that occurs once a bad image enters the context.
The developer notes this solution eliminates the need to double-escape back to recover from crashes, preserving both context and tokens during sessions involving images.
📖 Read the full source: r/ClaudeAI
👀 See Also

Nit: A Git Replacement in Zig Optimized for AI Agent Token Efficiency
Nit is a native Git replacement written in Zig that reduces token usage by 35-87% on common commands like status, diff, log, and show. It achieves this through compact output defaults and direct libgit2 integration, eliminating subprocess overhead.

ReRouted: macOS Menu Bar App to Auto-Fallback Across Claude, Codex, Grok, and More
ReRouted is a lightweight macOS menu bar app that acts as a local gateway. Point your AI tools to one endpoint; it routes and auto-fallbacks across your accounts when providers hit limits.

Agent Memory Protocol (AMP): Open Spec for Interoperable AI Agent Memory on Top of MCP
AMP defines a standard interface for persistent memory in MCP-compatible agents with six core verbs: encode, recall, forget, consolidate, pin, and stats. Includes compliance test suite and reference implementation.

Wolfram Tech Now Available as Foundation Tool for LLM Systems
Stephen Wolfram announces Wolfram Language is now available as a foundation tool for LLM systems, providing deep computation and precise knowledge to supplement LLM capabilities. The announcement follows three years of development since the initial Wolfram plugin for ChatGPT was released in March 2023.