Bug: Task agents fail with 'classifyHandoffIfNeeded is not defined'
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
- Start a conversation with plan mode active
- Launch Task agents with
run_in_background: truefor exploration tasks - Wait for agents to complete their work
- 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 explorationsubagent_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.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗