Runs when Claude finishes a task, providing TypeScript type checking and a summary of all changes made during the session.
This Stop hook fires when Claude completes its work. It performs two functions:
- TypeScript Type Checking (blocking) — If TypeScript files were modified, runs
tsc --noEmitand blocks if there are type errors - Change Summary (informational) — Displays a summary of all files changed during the session
If any .ts or .tsx files were modified:
- Locates
tsconfig.json(checks git root, thensrc/,app/,packages/) - Runs
npx tsc --noEmitto check types - Blocks Claude from stopping if type errors are found
- Claude must fix the errors before finishing
This ensures you never end a session with broken TypeScript.
If any .go files were modified:
- Runs
golangci-linton modified files - Reports issues but doesn't block (non-blocking)
- Shows installation hint if golangci-lint isn't found
Always displays at the end:
═══════════════════════════════════════════════════════════════
SESSION CHANGE SUMMARY
═══════════════════════════════════════════════════════════════
📊 Overall Statistics:
───────────────────────────────────────────────────────────────
3 files changed, 45 insertions(+), 12 deletions(-)
📁 Modified Files:
───────────────────────────────────────────────────────────────
M src/auth/jwt.ts
A src/middleware/auth.ts
M src/routes/index.ts
🔍 Change Preview (per file):
───────────────────────────────────────────────────────────────
► src/auth/jwt.ts
─────────────────────────────────────────────────────────────
+import { sign, verify } from 'jsonwebtoken';
+
+export function generateToken(payload: object) {
...
# For TypeScript checking
npm install -g typescript
# Or have it as a project dependency
# For Go linting (optional)
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latestcp change-summary.sh ~/.claude/hooks/change-summary.sh
chmod +x ~/.claude/hooks/change-summary.shAdd to ~/.claude/settings.json:
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "$HOME/.claude/hooks/change-summary.sh"
}
]
}
]
}
}The auto-format hook doesn't run TypeScript checking because:
- Type checking is slow compared to formatting
- Running it after every edit would interrupt flow
- Type errors often span multiple files
Instead, type checking runs once at the end. If there are errors, Claude is told to fix them before finishing. This ensures:
- Fast feedback during editing (formatting only)
- No broken TypeScript when the session ends
- Claude takes responsibility for type safety
Change exit 1 to exit 0 in the TypeScript section:
if [[ $tsc_exit -ne 0 ]]; then
# ... error output ...
exit 0 # Changed from exit 1
fiAdd sections for other languages before the change summary:
# Example: Python type checking with mypy
python_files_changed=$(git diff --name-only HEAD 2>/dev/null | grep -E '\.py$' || true)
if [[ -n "$python_files_changed" ]]; then
mypy $python_files_changed
fiModify the git commands in the summary section to show more or less detail.
Use /stop to force stop, or temporarily modify the hook to be non-blocking.
The hook checks these locations:
$git_root/tsconfig.json$git_root/src/tsconfig.json$git_root/app/tsconfig.json$git_root/packages/tsconfig.json
Add your location to the script if needed.
Install it with:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latestOr remove the Go linting section if you don't need it.
- auto-format — Formats files after each edit (complements this hook by handling formatting during the session)
- compaction — Improves context preservation when compacting