Skip to content

Hooks: include the tool call id in preToolUse, postToolUse and postToolUseFailure input #5261

Backlog

Description

@LoopGlitch26

Describe the feature or problem you'd like to solve

Tool hook input has no tool call id, so a hook can't tell which preToolUse a postToolUse or postToolUseFailure belongs to.

Proposed solution

Add the call's id to the preToolUse, postToolUse and postToolUseFailure input (and permissionRequest, where there is one):
toolCallId in the camelCase format and tool_use_id in the VS Code compatible format.

The hooks reference lists sessionId, timestamp, cwd, toolName, toolArgs (plus toolResult or error)
for these events, and nothing that names the call. VS Code's own agent hooks send tool_use_id on PreToolUse and
PostToolUse (VS Code docs, agents/reference/hooks-reference), and the CLI's PascalCase format is described as matching
the VS Code extension's format, so a hook written against VS Code that reads tool_use_id gets nothing from the CLI.
Claude Code's hooks carry the same field.

Without it, two calls of the same tool with the same arguments (the same file viewed twice, a retried command, calls
dispatched in parallel) can't be told apart, and a hook has to pair pre and post events by tool and arguments in
arrival order, which is wrong when they finish in another order.

Example prompts or workflows

  1. An audit hook writes one record per call: the decision at preToolUse, the outcome at postToolUse or postToolUseFailure, joined by id.
  2. A policy hook holds a call for a person's approval in another system, then attaches the result to that approval.
  3. A telemetry hook measures each call's duration while calls run in parallel.
  4. A hook links its record to the same call in the session's event log or an OpenTelemetry span.

Additional context

Context: I maintain Tracekit (https://github.com/Cygnux-Labs/Tracekit), which records and gates agent tool calls; this would let it gate Copilot CLI calls and pair each result with the call it decided by id.

Activity

  1. added
    area:plugins
    and removed on Oct 28, 2026
  2. k4otix commented on Dec 3, 2026

    @k4otix

    +1. This is the missing join key between hooks and the native OTel export.

    A common enterprise pattern is managed preToolUse/postToolUse hooks for policy and audit, with OTel for observability. Joining "hook decision → execute_tool span → outcome" isn't reliable today. Hook input has no call id, so parallel calls to the same tool look identical. The OTel github.copilot.hook.* span events also lack gen_ai.tool.call.id, even though the execute_tool spans have it (checked on 1.0.119).

    Putting the same id in both the hook input and the hook span events would let security teams tie a deny or ask decision to the exact tool call, without guessing from timestamps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:plugins

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions