When Claude runs your tests, the whole output lands in your chat, and your whole chat is sent again with every request after. A hook that keeps only the failures stops that waste. Anthropic's cost docs say this takes a 10,000-line log from tens of thousands of tokens down to hundreds.
Here's the hook, three steps to install it, and the catch.
How it works
- A PreToolUse hook on Bash runs before every command Claude issues.
- If the command is npm test, pytest or go test, the hook rewrites it to pipe through grep, so only the failing lines and five lines after each come back.
- Claude never sees the filter. It just sees the shorter output.
Keep reading
Free, for an email.
Unlocks 5 more sections, 2 copy-paste prompts, the document version, and every other guide on the site, for free. Enter your email once to keep reading.
45,000+ follow where these guides come from.No spam. Unsubscribe in one click.