CClaude Code Catalog
All Hooks

TypeScript Type Checker

Post-ToolIntermediateHook Type: post-tool-use

TypeScript Type Checker hooks into post-tool-use events for Write and Edit operations on TypeScript files. After each edit, it runs tsc --noEmit on the project to verify type safety. Rather than running a full project check every time, it uses incremental compilation with tsbuildinfo cache for fast feedback. When type errors are found, it reports them with file locations and error messages so Claude can fix them immediately. This prevents the common problem of multiple edits building up cascading type errors.

typescripttype-checktsctype-safetyvalidation

Hook Code

#!/bin/bash # TypeScript Type Checker Hook # Runs tsc --noEmit after TypeScript file edits # Only trigger on Write or Edit if [[ "$TOOL_NAME" != "Edit" ]] && [[ "$TOOL_NAME" != "Write" ]]; then exit 0 fi FILE_PATH=$(echo "$TOOL_INPUT" | jq -r '.file_path // .path // empty') if [ -z "$FILE_PATH" ]; then exit 0 fi # Only check TypeScript files if ! echo "$FILE_PATH" | grep -qE '\.(ts|tsx)$'; then exit 0 fi # Find the nearest tsconfig.json SEARCH_DIR=$(dirname "$FILE_PATH") TSCONFIG="" while [ "$SEARCH_DIR" != "/" ]; do if [ -f "$SEARCH_DIR/tsconfig.json" ]; then TSCONFIG="$SEARCH_DIR/tsconfig.json" break fi SEARCH_DIR=$(dirname "$SEARCH_DIR") done if [ -z "$TSCONFIG" ]; then echo "No tsconfig.json found, skipping type check." exit 0 fi PROJECT_DIR=$(dirname "$TSCONFIG") echo "Running type check..." OUTPUT=$(cd "$PROJECT_DIR" && npx tsc --noEmit --incremental 2>&1) EXIT_CODE=$? if [ $EXIT_CODE -ne 0 ]; then ERROR_COUNT=$(echo "$OUTPUT" | grep -c "error TS") echo "TYPE ERRORS: $ERROR_COUNT error(s) found" echo "$OUTPUT" | grep "error TS" | head -5 if [ "$ERROR_COUNT" -gt 5 ]; then echo " ... and $((ERROR_COUNT - 5)) more errors" fi exit 1 fi echo "Type check passed." exit 0

Add this hook to your Claude Code settings or .claude/settings.json to activate.

Terminal Preview

TypeScript Type Checker

About TypeScript Type Checker

Claude Code hooks let you run custom shell commands automatically in response to specific events during Claude's operation. TypeScript Type Checker is a Post-Tool hook at the Intermediate level that automates tasks at key moments in your development workflow, reducing manual steps and enforcing consistency across your team.

Related Hooks