Everyone automates formatting. Almost nobody automates the feedback loop✨
Here’s the most underused Claude Code hook - and the one with the biggest payoff.
Without it: Claude edits your code, says “done”, and you find the broken test an hour later. You’re the QA step.
With it: every edit triggers your tests automatically, and failures land straight in Claude’s context - so it fixes its own mistakes before you even see them 🔁
Setup takes 2 minutes. Create .claude/hooks.json in your project:
{ “hooks”:
{ “PostToolUse”:
[{
“matcher”: “Write|Edit”,
“hooks”:
[{
“type”: “command”,
“command”: “npm test — —findRelatedTests \”${file}\””,
“timeout”: 120
}]
}] }
}
What it does:
⚡ Fires after every file Claude writes or edits
🎯 Runs only the tests related to that file (fast, not noisy)
🔁 Test output goes back to Claude → it self-corrects
That’s it. Every AI edit is now self-verifying. You review working code instead of debugging surprises.
Try it on your next session and t...
Suggested Credits
Tags, Events, and Projects