🪝HOOKS
reel #08Claude tests your code on its own
What this is
A free, step-by-step template from Taha's reels — the exact tools, prompts and links, laid out so you can follow along and ship. Comment the keyword on the reel and it also lands in your DMs.
Hey! 👋 Here's what I promised you:
Claude Code Hooks — commands that run automatically with every step Claude takes: it edits, and the hook tests right after — without you telling it to. These are the two hooks I use myself:
- ON EDIT → any code you edit gets test + lint run on it automatically.
- PRE-COMMIT → before any commit, it checks whether there's any secret / password / API key in the files — if it finds something, it blocks the commit so you don't break anything.
How to start
- Add this to your project's
.claude/settings.json(replacenpm test && npm run lintwith your project's commands):
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{ "type": "command", "command": "npm test && npm run lint" }
]
}
],
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "git diff --cached | grep -qiE 'api[_-]?key|secret|password' && echo 'STOP: secrets f staged files!' >&2 && exit 2 || exit 0" }
]
}
]
}
}exit 2 is what blocks: Claude stops and reads the error message.- Add the rule to your project's
CLAUDE.mdso it becomes a habit for Claude:
Any code you write or edit, run the tests before you consider the task done. Big changes = test the whole workflow.
- Try it: ask Claude to edit a file — you'll see the tests run on their own right after. ✅