ipIterPrompt
Workflow templateDeveloper WorkflowVerified Last verified 2026-07-24

Test-on-Save Hook

by Community pattern

A `PostToolUse` hook configured in `.claude/settings.json` that runs your test or lint command whenever Claude Code edits a file. The agent sees failures immediately and self-corrects, turning 'write code, hope it works' into a tight write-test-fix loop without you prompting for it.

Works with

MCP servers, subagents, skills, slash commands, and hooks.

When to use it

  • On projects with a fast test or typecheck command
  • When you want the agent to catch its own regressions before you review

When not to

  • When your test suite is slow (the loop will crawl) — scope it to affected tests instead

What it does

  • Runs a command automatically after the agent edits files
  • Feeds test/lint failures straight back to the agent
  • Deterministic — it always runs, unlike a reminder in a prompt

How to install

Setup steps with copy-paste config. Sources are cited under each method.

Configure the hook

Claude Code

Requires: Claude Code installed · A test or typecheck command

  1. Add the hook to settings

    In `.claude/settings.json`, register a PostToolUse hook that runs after Edit/Write.

    json
    {
      "hooks": {
        "PostToolUse": [
          {
            "matcher": "Edit|Write",
            "hooks": [{ "type": "command", "command": "npm run -s typecheck" }]
          }
        ]
      }
    }
  2. Keep it fast

    Point the command at a quick check (typecheck or affected tests). The agent reads its output and fixes failures on the next turn.

How to prompt it

Copy-paste prompts written to exercise this plugin, with what to expect.

Let the loop do the work

You ask for a refactor and want it to stay green.

Refactor the pricing module to use the new currency helper. Keep everything type-clean.

What to expect: After each edit the hook runs your typecheck; if it fails, Claude Code sees the errors and fixes them before moving on — you review a working result.

  • Start with `typecheck`; graduate to `test -- --changed` once you trust the loop.

Tips for getting the most out of it

  • Return a non-zero exit code on failure so the agent treats it as a signal.
  • Use a `SessionStart` hook to install deps so web/CI sessions can run the check too.

Prompts to pair with it

Real prompts from the IterPrompt library you can copy or run.

Web Application Testing Skill

Turn any AI chat into a web application testing skill with this community persona prompt.

1,049 copiesOpen ↗

Accessibility Testing Superpower

Turn any AI chat into an accessibility testing superpower with this community persona prompt.

5,099 copiesOpen ↗

White-Box Web Application Security Audit & Penetration Testing Prompt for AI Code Editors (Cursor, Windsurf, Antigravity)

Turn any AI chat into a white-box web application security audit & penetration testing prompt for ai code editors (cursor, windsurf, antigravity) with this community persona prompt.

3,160 copiesOpen ↗

Software Implementor AI Agent for Data Entry and Testing

Turn any AI chat into a software implementor ai agent for data entry and testing with this community persona prompt.

2,649 copiesOpen ↗

TypeScript Unit Testing with Vitest

Turn any AI chat into a typescript unit testing with vitest with this community persona prompt.

1,987 copiesOpen ↗

AI Performance & Deep Testing Engineer

Turn any AI chat into an ai performance & deep testing engineer with this community persona prompt.

4,440 copiesOpen ↗
See more prompts in the library

Frequently asked questions

Won't running tests after every edit be slow?+

It can be. Scope the command to a typecheck or to affected tests only. The speed of the check sets the speed of the loop.

Pairs well with

Related guides

Alternatives to Test-on-Save Hook

Sources & verification

The facts on this page and where they come from. Anything unverified is labeled — we'd rather say "unknown" than guess.

Install steps, pricing, and availability change often. Always confirm on the official page before relying on setup details.