[FEATURE] Include tool execution duration_ms in PostToolUse and PostToolUseFailure hook inputs

Resolved 💬 2 comments Opened Apr 22, 2026 by serkan-ozal Closed Apr 22, 2026

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

  • PreToolUsePostToolUse correlation: 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_path jsonl backwards to find matching tool_use_id's timestamp. Undocumented format, I/O cost, brittle across Claude Code versions.
  • is_interrupt as 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

  1. Agent runs a turn with 40 tool calls: 30 Read, 5 Edit, 4 Bash, 1 long-running Bash (npm test).
  2. PostToolUse fires for each; my hook captures the event + forwards to a collector.
  3. Today's downstream analytics can answer: "which tools ran, in what order, what failed." Cannot answer: "which tool calls exceeded 2 seconds."
  4. 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.
  1. 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_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗