Claude Hookbook

Hooks / testing

Typecheck after TypeScript changes

Runs tsc --noEmit in the background after Claude edits TypeScript, so type errors surface even when tests don't cover the file.

PostToolUseEdit|Writereview riskneeds manual check

What it does

Gates on .ts/.tsx edits and runs a project-wide tsc --noEmit asynchronously. Project-wide because cross-file type errors are the ones that matter, async because tsc is too slow to run inline on every edit. One caveat: rapid edit sequences can overlap runs; on huge codebases consider gating to Stop instead.

When it runs

EventPostToolUse
MatcherEdit|Write
Scopeproject
Platformsmacos, linux
Asyncruns in the background, reports on exit
Timeout180s
Requiresjq typescript
Failure modewarn
Verified againstClaude Code hooks reference, event/matcher schema checked 2026-09-10
Test statusneeds manual check - run the test steps below before relying on it

Config

Merge this into .claude/settings.json - or use the generator to combine hooks.

{
  "hooks": {
    "PostToolUse": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/typecheck-after-ts.sh",
            "timeout": 180,
            "async": true
          }
        ],
        "matcher": "Edit|Write"
      }
    ]
  }
}

Script

Save as .claude/hooks/typecheck-after-ts.sh and chmod +x it.

#!/bin/bash
# typecheck-after-ts: background tsc --noEmit on TS edits (async).
set -u
file=$(jq -r '.tool_input.file_path // empty')
case "$file" in *.ts|*.tsx) ;; *) exit 0 ;; esac
cd "${CLAUDE_PROJECT_DIR:-$PWD}" || exit 0
[ -f tsconfig.json ] || exit 0
if ! npx tsc --noEmit >/dev/null 2>&1; then
  echo "TypeScript errors after editing $file:" >&2
  npx tsc --noEmit 2>&1 | head -30 >&2
  exit 2
fi
exit 0

Install

  1. Save the script to .claude/hooks/typecheck-after-ts.sh and chmod +x it.
  2. Add the config fragment to .claude/settings.json (async: true included).

Test it

Sources

Related hooks

ESLint after JS/TS edit

Runs eslint --fix on JavaScript and TypeScript files after Claude edits them, and warns (never blocks) on remaining problems.

PostToolUseEdit|Writereview riskneeds manual check

Run the nearest test after an edit

Finds the test file that belongs to the file Claude just edited and runs it, in the background.

PostToolUseEdit|Writereview riskneeds manual check

Pro Pack (later)

Framework bundles, cross-platform scripts, tested blocking policies, and a test harness. Free recipes and the generator stay free.

Waitlist opens soon.