[FEATURE] Include tool execution duration_ms in PostToolUse and PostToolUseFailure hook inputs
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
I build session level telemetry on top of Claude Code hooks which captures every tool call event for downstream analytics (which tools are slow, which fail, how long a session spends in verification vs. editing, etc.). The one field I can't get is tool execution duration.
PostToolUse and PostToolUseFailure hook stdin include tool_name, tool_input, tool_response/error, tool_use_id, and the base fields, but no duration.
Claude Code does measure this internally as that value is used for OTel / internal stats but never flows into the hook input.
Proposed Solution
Add duration_ms to both hook input schemas (PostToolUse and PostToolUseFailure)
Alternative Solutions
PreToolUse→PostToolUsecorrelation: works but adds one extra hook invocation per tool (~80–120ms Node startup). Worse, the resulting "duration" includes permission wait time, which in default permission mode can be hours (user away from keyboard). Misleading.- Transcript parsing: read
transcript_pathjsonl backwards to find matchingtool_use_id's timestamp. Undocumented format, I/O cost, brittle across Claude Code versions. is_interruptas a proxy: doesn't help, tells me what happened but not when. - Reporting -1 / omitting duration: current workaround; analytics lose a core signal.
Cursor's postToolUseFailure hook already ships a duration field (see [docs.cursor.com/hooks](docs.cursor.com/hooks)). Parity would simplify cross-IDE telemetry pipelines.
Priority
Critical - Blocking my work
Feature Category
Developer tools/SDK
Use Case Example
Scenario: session-level tool performance analytics for an AI coding agent
- Agent runs a turn with 40 tool calls: 30 Read, 5 Edit, 4 Bash, 1 long-running Bash (npm test).
PostToolUsefires for each; my hook captures the event + forwards to a collector.- Today's downstream analytics can answer: "which tools ran, in what order, what failed." Cannot answer: "which tool calls exceeded 2 seconds."
- With
duration_ms, I can:
- Flag slow tools per session (most common culprit: long Bash commands on unindexed codebases).
- Build p50/p95/p99 distributions per tool type across many sessions.
- Correlate "time in tools" vs. "time in model" to surface agent efficiency.
- Same data is already captured internally by Claude Code — exposing it costs ~1 line of schema + ~1 line to pass it through.
Concrete downstream query (after the field is added):
"In the last 100 agent sessions, which tool_calls took >5s, sorted by duration, grouped by tool_name?"
Today: impossible without the PreToolUse-correlation hack. After: trivial.
Additional Context
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗