Task tool agents crash with 'classifyHandoffIfNeeded is not defined' after completing work
Bug Description
Task tool subagents (spawned via the Task tool) crash with classifyHandoffIfNeeded is not defined after successfully completing their work. The agent produces its full output, but the parent conversation receives a "failed" status notification instead of the result.
Environment
- Claude Code version: 2.1.39
- OS: macOS 15 (Darwin 25.2.0 arm64)
- Node.js: v20.19.0
- Model (parent): claude-opus-4-6
- Model (subagent): claude-haiku-4-5-20251001
Steps to Reproduce
- Use the
Tasktool to spawn an Explore agent (or other subagent type) - Let the agent complete its work (read files, search code, produce analysis)
- Agent finishes and generates its final text response
- Crash occurs on the return path — parent receives:
<task-notification>
<task-id>a6944db</task-id>
<status>failed</status>
<summary>Agent "Explore 3-panel layout structure" failed: classifyHandoffIfNeeded is not defined</summary>
</task-notification>
Expected Behavior
The agent should return its completed result to the parent conversation with status: completed.
Actual Behavior
- The agent completes all its work (file reads, analysis, final text output)
- On the return/handoff path back to the parent, it crashes with
classifyHandoffIfNeeded is not defined - Parent receives a
failedstatus notification - The agent's full output is available in the task output file despite the "failed" status
Workaround
The agent's work products are already applied/saved before the crash. Reading the task output file (/private/tmp/claude-501/.../tasks/<agent-id>.output) reveals the complete result. This is a cosmetic failure — the work is done, but the orchestration layer reports it as failed.
Agent Log Excerpt
From the task output JSONL (a6944db.output):
{
"version": "2.1.39",
"agentId": "a6944db",
"slug": "greedy-squishing-kurzweil",
"isSidechain": true,
"message": {
"model": "claude-haiku-4-5-20251001",
"role": "assistant",
"content": [{"type": "text", "text": "Perfect! I have enough information now..."}],
"stop_reason": null
}
}
The agent successfully produced ~2500 words of analysis, then crashed before the result could be delivered to the parent.
Frequency
Occurs intermittently. Not every agent invocation fails — some complete and return normally. The same agent type (Explore with haiku) sometimes succeeds and sometimes hits this error. Reproducible across multiple sessions.
Additional Context
- The function name
classifyHandoffIfNeededsuggests it's part of the agent orchestration/handoff system - The crash always happens after the agent's final assistant message, never during tool use
stop_reason: nullin the last message may be relevant — possibly the response was still streaming when the handoff was attempted
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗