hook-latency-wrap
Skill0 starsChanged 5 months agoMITView on GitHub
Claude Code の任意 hook (PostToolUse / Stop / UserPromptSubmit 等) の実行時間と失敗率を観測したいとき、bash $EPOCHREALTIME ベースの透過 wrapper で計測する手順。
1 other project uses a version of this.
Adopted by
Most recently taken up by
- ummshun/claude-code-skillstheir own version, first seen Nov 8, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- ummshun/claude-code-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository99 other files it gives its agents.
- agents-tools-quoted-jsonSkill
- asc-api-app-store-submitSkill
- asd-ste100Skill
- automation-bool-selector-pitfallsSkill
- automation-stale-cooldown-flagSkill
- autonomous-build-verifySkill
- book-to-skillSkill
- ccusage-cli-cost-trackingSkill
- chrome-ext-mv3-programmatic-injectSkill
- chrome-ext-store-assetsSkill
- claude-headless-p-invocationSkill
- claude-plugin-context-auditSkill
- claude-session-log-to-kbSkill
- cloudflare-workers-do-deploySkill
- codebase-to-courseSkill
- codesign-keychain-prompt-fixSkill
- codex-cli-setupSkill
- codex-delegation-handoffSkill
- content-factory-grounding-dedupSkill
- conversation-log-append-patternSkill
- cron-to-launchd-macosSkill
- cross-automation-shared-resource-killSkill
- design-token-migration-rnSkill
- discord-bot-image-to-claudeSkill
- discord-gateway-resume-dedupSkill
- excel-filtered-url-http-auditSkill
- execution-budget-vs-capsSkill
- expo-free-local-ios-testflightSkill
- ga4-connect-projectsSkill
- gcal-oauth-desktop-setupSkill
- git-commit-helperSkill
- git-prepush-secret-remote-checkSkill
- gsc-cli-automationSkill
- hatena-blogsync-autopostSkill
- hook-log-append-patternSkill
- html-to-pdf-slide-deckSkill
- humanizerSkill
- human-review-gate-shellSkill
- implementation-model-routingSkill
- insights-to-claude-mdSkill
- ios-permission-key-security-matrixSkill
- ios-sim-store-screenshotsSkill
- launchd-exit78-exconfig-debugSkill
- llm-content-pipeline-quality-gateSkill
- local-ai-video-pipelineSkill
- local-flux-mflux-image-genSkill
- local-llm-slow-diagnosisSkill
- local-music-generationSkill
- lottie-skottie-authoring-pitfallsSkill
- machine-wide-api-ratelimit-latchSkill
- macos-hook-path-timeoutSkill
- md-to-docx-reportSkill
- memory-md-inject-bloat-auditSkill
- message-display-secrets-maskSkill
- metric-source-attributionSkill
- migrate-icloud-desktop-assetsSkill
- nextauth-local-e2e-sessionSkill
- nextjs-rsc-payload-slimSkill
- nothing-designSkill
- openclaw-ollama-setupSkill
- The first 60 shown.
The file
Files
Procedure
- wrapper script 設置:
~/.claude/scripts/hook-latency-wrap.sh <real_hook_path> "$@"で stdin を保持しつつ実 hook を exec 前後で$EPOCHREALTIMEを取得。差分を µs 精度で~/.claude/logs/hook-latency.jsonlに追記 (ts/hook/duration_ms/exit_code)。 - settings.json の配線書き換え: 該当 hook の
commandを~/.claude/scripts/hook-latency-wrap.sh ~/.claude/hooks/<real>.shに差し替え。複数 hook 同時 wrap 可能。 - stdin 透過: wrapper は
cat | <real_hook>ではなくexec直前まで stdin を保持し、実 hook に丸ごと渡す (Claude Code hook protocol を壊さない)。 - 失敗時 passthrough: 実 hook の exit code をそのまま返す。wrap 自体は失敗しても
exit 0で hook chain を止めない。 - レポート集計:
~/.claude/scripts/hook-latency-report.shで過去 7d を hook 別に p50/p95/max/fail rate に集計。
Pitfalls
- bash 5+ の
$EPOCHREALTIMEを使うこと。macOS 標準 bash 3.2 では未定義 →/opt/homebrew/bin/bashshebang を明示する。python3 を spawn すると 30-50ms オーバーヘッドが追加で乗る (本末転倒)。 - wrap 自体のオーバーヘッドは ~20ms。1ms 単位の精度を求めるなら別途差し引き必要。
exec前に>>で log に追記すると実 hook の stdout/stderr を巻き込む → 計測ログは別 fd (e.g.exec 9>>...) か wrap 終了後に書く。stop_notify.shのような非同期 hook は wrap の終了タイミングと実完了がズレる場合あり。fire-and-forget なら計測無意味。
Verification
bash -n ~/.claude/scripts/hook-latency-wrap.shで構文 OK。- 試験 hook で
echo '{}' | ~/.claude/scripts/hook-latency-wrap.sh ~/.claude/hooks/<target>.sh実行 → log に entry 1 行追加。 - 通常 hook 発火 (Edit/Stop 等) 後に
tail ~/.claude/logs/hook-latency.jsonlで記録確認。 hook-latency-report.shで p95 が想定範囲 (< 500ms 推奨) に収まっている。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

