BUG: classifyHandoffIfNeeded called but never defined in cli.js bundle (v2.1.32)

Resolved 💬 3 comments Opened Feb 6, 2026 by Walid-Azur Closed Feb 9, 2026

Bug Description

classifyHandoffIfNeeded is called at runtime but never defined in the bundled cli.js, causing a ReferenceError that marks successfully completed subagents as "failed".

Root Cause Analysis

We traced this directly in the installed bundle:

File: node_modules/@anthropic-ai/claude-code/cli.js (line ~2980)

v1 = await classifyHandoffIfNeeded({
  agentMessages: z1,
  toolPermissionContext: S1.toolPermissionContext,
  abortSignal: _1.abortController.signal,
  isNonInteractiveSession: J.options.isNonInteractiveSession,
  subagentType: q,
  totalToolUseCount: I1.totalToolUseCount
});

Key finding: The function is referenced 1 time but defined 0 times in the entire cli.js bundle. This is a build/bundler issue — the call site was included but the function definition was tree-shaken or the module containing it was not bundled.

Trigger Path

The error only occurs in the background-transition code path — specifically when a synchronous subagent gets backgrounded mid-execution (the isBackgrounded branch). The relevant code flow:

  1. Synchronous agent starts via Task tool
  2. Agent runs long enough to trigger background transition (sLY = 2000ms threshold)
  3. Agent completes successfully in the background
  4. Completion handler calls classifyHandoffIfNeeded()ReferenceError
  5. Catch block marks task as "failed" despite work completing successfully

Regular foreground-only agents that complete before the background threshold do not hit this path, which explains why the bug is intermittent for some users.

Verification

# Only 1 reference, 0 definitions:
rg "classifyHandoffIfNeeded" node_modules/@anthropic-ai/claude-code/cli.js
# Returns exactly 1 match (the call site), no function/const/var definition

Environment

  • Claude Code: 2.1.32 (latest as of 2026-02-06)
  • Platform: macOS Darwin 25.2.0
  • Node: confirmed via npm view @anthropic-ai/claude-code version → 2.1.32

Impact

  • All subagent types affected: Explore, general-purpose, Plan, custom plugin agents
  • Severity: Medium — work completes but results may not propagate correctly to parent, and task is incorrectly marked "failed"
  • Workaround: Redirect agents via PreToolUse hook to avoid long-running paths, but no user-space fix possible for the missing function

Related Issues

  • #22087
  • #22098
  • #22312
  • #22544

All report the same symptom but none identified the root cause as a missing bundle definition.

Suggested Fix

Re-include the classifyHandoffIfNeeded function in the build output, or add a fallback/no-op guard:

// Minimal guard until proper fix
const classifyHandoffResult = typeof classifyHandoffIfNeeded === 'function'
  ? await classifyHandoffIfNeeded({...})
  : undefined;

View original on GitHub ↗

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