--incremental Made My TypeScript Hook 3.6x Slower. A 200KB Threshold Fixed It
Description and use
A 200 KB threshold in the .tsbuildinfo file automatically switches tsc between incremental and normal mode, eliminating slow cold starts on large projects.
Problem
Using tsc --incremental in a post‑tool‑use hook caused cold starts to become 3.6× slower on large projects because the .tsbuildinfo cache grew too large, negating incremental benefits.
Outcome
The 200 KB threshold guard restores fast incremental type checks for small projects while preventing slowdowns on large ones, enabling the Claude Code agent to run autonomously without human intervention.
Workflow
- 1. Hook triggers after Claude Code edits a file.
- 2. Check for tsconfig.json; exit if missing.
- 3. Resolve timeout command (gtimeout, timeout, or none).
- 4. Define cache path node_modules/.cache/tsc-hook.tsbuildinfo.
- 5. If .tsbuildinfo exists, get its size; if >200 KB set USE_INCREMENTAL=0, else 1.
- 6. Build TSC_ARGS: include --incremental and tsBuildInfoFile if USE_INCREMENTAL=1, otherwise plain --noEmit.
- 7. Run tsc with timeout, capture first 30 lines of output.
- 8. If exit code 124, emit timeout warning and exit 0.
- 9. If tsc exits with errors, print them prefixed with "=== TypeScript型エラー検出 ===" and exit 0.
- 10. Agent reads hook output, uses errors to trigger a fix loop.
- 11. Hook always exits 0 to avoid blocking agent flow.
Evidence
"if the cache file exceeds 200KB, fall back to normal mode"
"cold runs got 3.6x slower"
- Record date: 2026-09-21T10:15:28.661Z