Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

--incremental Made My TypeScript Hook 3.6x Slower. A 200KB Threshold Fixed It

说明与用途

在 .tsbuildinfo 文件中使用 200 KB 阈值,自动在增量和普通模式之间切换,消除大型项目的慢冷启动问题。

问题

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