Bug: Task agents fail with 'classifyHandoffIfNeeded is not defined'

Resolved 💬 4 comments Opened Feb 4, 2026 by dwadrian Closed Mar 5, 2026

Description

Task tool agents (subagents) fail with the error classifyHandoffIfNeeded is not defined after completing their work successfully. The agents complete their exploration/planning tasks but crash when trying to return control to the parent conversation.

Environment

  • Claude Code Version: 2.1.31
  • OS: macOS Darwin 25.2.0
  • Node: (Claude Code internal)

Steps to Reproduce

  1. Start a conversation with plan mode active
  2. Launch Task agents with run_in_background: true for exploration tasks
  3. Wait for agents to complete their work
  4. Agents fail with the error despite having completed their tasks

Error Message

Agent "Find ALL dead audit code" failed: classifyHandoffIfNeeded is not defined
Agent "Plan Spatie implementation" failed: classifyHandoffIfNeeded is not defined

Expected Behavior

Agents should complete successfully and return their results to the parent conversation without errors.

Actual Behavior

  • Agents complete their work (exploration, file reading, analysis)
  • Agents write their findings/output correctly
  • At the handoff/return phase, they crash with classifyHandoffIfNeeded is not defined
  • The error appears to be in the agent termination/handoff logic

Workaround

The agents complete their work before failing, so the output can still be retrieved from the output files. However, the failure notification is confusing and suggests the task failed when it actually succeeded.

Additional Context

This happened with two different agent types in the same session:

  • subagent_type: Explore - for codebase exploration
  • subagent_type: planner - for implementation planning

Both failed with the identical error at the handoff phase.

Logs

From the task output file, the last successful operation before failure:

{"type":"assistant","message":{"content":[{"type":"text","text":"...completed analysis..."}]}}

Then immediately:

<error>classifyHandoffIfNeeded is not defined</error>

The function classifyHandoffIfNeeded appears to be missing from the agent's runtime context when attempting to complete the handoff back to the parent conversation.

View original on GitHub ↗

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