Skip to main content
hook

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.

Install into Claude Code · claude-code-templates All methods and platforms ↓
npx claude-code-templates@latest --hook post-tool/run-tests-after-changes
Open on GitHub

What 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.ts and 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-changes

2Manually: put the files in place

.claude/settings.json

The 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

Similar hooks

Everything for Testing and QA →

From the same set740

The whole set →
nextjs-code-quality-enforcer A PostToolUse hook that checks every Next.js file you write: App Router structure, Server and Client Component directives, imports, types. It runs right after an edit. 2,249installs react-performance-optimizer This subagent tracks down unnecessary renders, optimizes bundle chunking, and tunes Core Web Vitals in React apps. Useful when web pages lag during heavy UI updates. 2,081installs add-changelog Generates and maintains CHANGELOG.md using the Keep a Changelog format. Reads recent commits and git tags to structure release notes. 2,025installs unused-code-cleaner A subagent that finds unused imports, functions and classes and removes them one at a time, validating after each step. Handy after a refactor or before a production deploy. 1,990installs report-generator Converts collected research notes into an organized Markdown document with numbered citations. It takes over at the final stage once all investigation data is ready. 1,930installs fact-checker A Claude subagent that pulls verifiable claims out of a text and rates how trustworthy the sources behind them are. Handy before you publish a draft or repeat someone's number. 1,919installs performance-profiler A Claude subagent that hunts down performance bottlenecks, memory leaks and load problems. Useful when an app is slow and the cause is not obvious. 1,875installs academic-researcher Searches scholarly literature, checks source quality, and builds research reviews. Use it to compare study methods, trace citations, and identify gaps. 1,855installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor