← Open Source & Engineering Work
Vercel · AI SDKMerged Upstream

Isolating Claude Code Subagent Events from Parent-Step Tracking

A Vercel AI SDK contribution that prevents Claude Code subagent messages from contaminating parent-step usage and tool-event tracking. Vercel engineer Felix Arntz approved PR #18631, then reimplemented the same change in signed PR #18740 because the original commits were unsigned. PR #18740 merged upstream with explicit credit to @patrickswedish.

#18740

merged upstream

#18631

credited source PR

69

harness tests

APPROVED

Felix Arntz

01 · Engineering problem

The failure mode

Claude Code Task-tool subagents emit messages with a non-null parent_tool_use_id. The harness processed those messages as though they belonged to the parent agent step, allowing nested usage, tool calls, tool results, and partial text to leak into parent-step accounting and observability.

02 · Technical response

What changed

  1. 01Reproduced the failure using a representative Claude Code event stream.
  2. 02Filtered subagent-originated assistant, user, tool-result, and partial-stream messages before parent-step normalization.
  3. 03Preserved parent-agent token usage and tool handling without changing the public API.
  4. 04Addressed review feedback, including partial stream-event isolation, and kept the patch focused with regression coverage and the required changeset.

03 · Verified outcome

Evidence-backed result

  • Vercel engineer Felix Arntz approved PR #18631 with: Thank you for the PR, LGTM!
  • Vercel's bugfix review marked the issue fully addressed with low side-effect risk and no breaking-change, architecture, performance, or security risk.
  • PR #18631 was closed only because its commits lacked required signatures; Felix reimplemented the same change in signed PR #18740.
  • PR #18740 merged upstream and explicitly states: Same as #18631 - that PR lacked verified commits. Credit goes to @patrickswedish.

04 · Public record

Source evidence

TypeScriptVercel AI SDKClaude CodeAgent HarnessesRegression Testing

Independent open-source engineering by Patrick Ribbsaeter. Company and project names identify the public repository and maintainer context only. No employment, client, vendor, or partnership relationship is implied unless explicitly stated.