--incremental Made My TypeScript Hook 3.6x Slower. A 200KB Threshold Fixed It
Описание и применение
Порог 200 КБ в файле .tsbuildinfo позволяет автоматически переключать режим tsc между инкрементальным и обычным, устраняя медленные холодные старты на больших проектах.
Задача
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.
Результат
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.
Рабочий процесс
- 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.
Доказательства
"if the cache file exceeds 200KB, fall back to normal mode"
"cold runs got 3.6x slower"
- Дата записи: 2026-09-21T10:15:28.661Z