Skip to content

research(hooks): PostToolUse hook duration_ms field — tool execution timing for performance-aware hooks (Claude Code v2.1.119 pattern) #3316

@bug-ops

Description

@bug-ops

Description

Claude Code v2.1.119 (April 23, 2026) added a duration_ms field to PostToolUse and PostToolUseFailure hook payloads, reporting tool execution wall time (excluding permission prompts and PreToolUse hook time).

Zeph's hook system (zeph-config/src/hooks.rs, zeph-core hook firing) passes env vars to hook scripts but does not include timing information. This prevents hooks from implementing performance-aware behaviors (alerting on slow tools, logging latency per tool type, triggering escalation on timeout).

Relevance to Zeph

  • HookContext / env vars set at fire_hooks time should include ZEPH_TOOL_DURATION_MS
  • PreToolUse time should be excluded (only measure actual tool executor wall time)
  • Applies to both post_tool_use and post_tool_use_failure event types

Implementation Sketch

  1. Record Instant::now() before calling the tool executor
  2. After execution, compute duration_ms = elapsed.as_millis()
  3. Add ZEPH_TOOL_DURATION_MS=<N> to the env vars passed to post_tool_use / post_tool_use_failure hooks
  4. Document in zeph-config hook env var reference

Estimated Complexity

Very low (~1h). Timer is already available; only env var injection is new.

Source: Claude Code changelog v2.1.119 — https://code.claude.com/docs/en/changelog

Metadata

Metadata

Assignees

Labels

P3Research — medium-high complexityllmzeph-llm crate (Ollama, Claude)researchResearch-driven improvement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions