Claude Code

The Claude Hook That Cuts Test Output Down to Just the Failures

A small PreToolUse hook rewrites your test command so only the failing lines reach Claude. The settings entry, the script, how to check it works, and where it falls short

2min read
2prompts to copy
5numbered steps
6sections

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.

Read next