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 checkWhat 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
| Event | PostToolUse |
| Matcher | Edit|Write |
| Scope | project |
| Platforms | macos, linux |
| Async | runs in the background, reports on exit |
| Timeout | 180s |
| Requires | jq typescript |
| Failure mode | warn |
| Verified against | Claude Code hooks reference, event/matcher schema checked 2026-09-10 |
| Test status | needs 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
- Save the script to .claude/hooks/typecheck-after-ts.sh and chmod +x it.
- Add the config fragment to .claude/settings.json (async: true included).
Test it
- Positive: have Claude introduce a type error in one file that breaks another - the async hook should report it.
- Negative: edit a .js or .py file - tsc should not run.
Sources
- Claude Code hooks reference (checked 2026-09-10)
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 checkRun 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 checkPro Pack (later)
Framework bundles, cross-platform scripts, tested blocking policies, and a test harness. Free recipes and the generator stay free.
Waitlist opens soon.