60% of a $312 Anthropic bill came from a single pattern: Claude Code hitting a D1 migration failure, then spinning up 7–8 retry Bash calls trying to diagnose what went wrong. Each loop burned 40–60K tokens. Three or four loops per session, and you're looking at $0.50–$0.70 just evaporating.

The fix wasn't prompt engineering. It was a PostToolUse hook that fires the moment wrangler d1 migrations apply exits non-zero — before the agent has a chance to start its retry spiral.

#!/bin/bash

# post_bash_hook.sh

COMMAND="$1"