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

Exporting AI Agent Memories Using Claude's Import Function
A Reddit user shares a prompt for extracting stored memories from AI agents like ChatGPT and Claude, then importing them into OpenClaw. The prompt requests all stored context including instructions, personal details, projects, tools, and preferences.

Brand-Docs: Open-Source Tool for Claude to Generate DOCX, PPTX, XLSX from Templates
A Reddit user open-sourced Brand-Docs, a solution for Claude to generate Office documents (DOCX, PPTX, XLSX) that faithfully preserve company brand templates — layout, styles, images — without recreation.

Claude-First Analytics MCP Server: Giving AI Agents Direct Access to Web Analytics Context
A developer rebuilt their web analytics tool as an MCP server, exposing simple web analytics, trackable links, and product insight tools directly to Claude, enabling AI agents to leverage site data alongside code and database context.

Claude Command Center: Open-Source Dashboard for Claude Code Analytics
Claude Command Center is a local dashboard that reads your ~/.claude/ directory to display Claude Code session data, costs, and MCP server configurations. Built entirely using Claude Code with an Express backend and React frontend, it requires zero configuration and runs locally with no cloud or telemetry.