run-tests-after-changes — Claude Code hook: what it does and setup
Runs quick tests via npm run test:quick immediately after Claude Code edits a file. It catches regressions right away during coding.
npx claude-code-templates@latest --hook post-tool/run-tests-after-changesWhat run-tests-after-changes does
The hook listens to the PostToolUse event for the Edit tool. Whenever the assistant modifies a file, the hook checks for package.json in the directory. If the manifest exists, it runs npm run test:quick --silent >/dev/null 2>&1 in the background.
Feedback appears in the terminal. When the command succeeds, you see ✅ Tests passed. Any failure or missing command prints ⚠️ Tests may need attention. The hook silences test output completely to keep the agent context clean.
Without a package.json file or a configured test:quick script, the hook always flags that tests need attention. You must define this quick script in your project before turning the hook on.
What it helps with
- run quick test suites automatically after every file edit
- catch regressions immediately during agent code changes
- avoid typing test commands manually after each modification
- keep context clean by muting verbose test output
Example prompts for the agent
- Fix the email validation logic in
src/auth.tsand apply the edit - Refactor the discount calculation helper in
src/pricing.js - Add handling for null values in
src/parser.ts
How to install run-tests-after-changes
1claude-code-templates
npx claude-code-templates@latest --hook post-tool/run-tests-after-changes2Manually: put the files in place
.claude/settings.jsonThe hooks block: event (PreToolUse, PostToolUse, Stop…) → command. Personal ones go to ~/.claude/settings.json
Step by step, with commands for each platform: Claude Code hooks: what they are, where to configure them, how to block a risky command
Questions about run-tests-after-changes
How to install run-tests-after-changes in Claude Code?
Run npx claude-code-templates@latest --hook post-tool/run-tests-after-changes in your terminal. You can also configure the hook inside .claude/settings.json.
What does run-tests-after-changes do?
It catches Edit operations and triggers npm run test:quick in the background. It then displays ✅ Tests passed on success or ⚠️ Tests may need attention on failure.
Which script is required in package.json?
Your package.json must declare a test:quick command in its scripts field. If the script or the file is missing, the hook will warn that tests need attention.
Source text
run-tests-after-changes.json · MIT
{
"description": "Automatically run quick tests after code modifications to ensure nothing breaks. This hook executes 'npm run test:quick' silently after any Edit operation and provides feedback on test status. Helps catch breaking changes immediately during development. Only runs if package.json exists and the test:quick script is available.",
"hooks": {
"PostToolUse": [
{
"matcher": "Edit",
"hooks": [
{
"type": "command",
"command": "if [[ -f package.json ]] && npm run test:quick --silent >/dev/null 2>&1; then echo '✅ Tests passed'; else echo '⚠️ Tests may need attention'; fi"
}
]
}
]
}
}
© davila7 · MIT · davila7/claude-code-templates