Plan agent fails with 'classifyHandoffIfNeeded is not defined' after completing work
Bug Description
When a Plan agent (spawned via Task tool) completes its research work without calling ExitPlanMode, the agent teardown phase throws a ReferenceError: classifyHandoffIfNeeded is not defined. The agent is marked as failed despite producing full, complete output.
Environment
- Claude Code version: 2.1.39
- OS: macOS Darwin 25.3.0
- Model: claude-opus-4-6
Steps to Reproduce
- Spawn a Plan agent via the Task tool with a research-only prompt (no implementation planning)
- The agent reads files, performs analysis, and produces output normally
- The agent completes its work without calling
ExitPlanMode(since the task was research, not implementation planning) - On agent completion/teardown, the error is thrown
Expected Behavior
The agent should complete successfully and return its output to the parent with status completed.
Actual Behavior
The agent produces full output but is marked as failed with error:
classifyHandoffIfNeeded is not defined
The output is still accessible (the parent agent can read it), but the status is incorrect.
Analysis
The classifyHandoffIfNeeded function appears to be referenced in the agent handoff/completion code path but is not defined or imported. This seems specific to the Plan agent code path where the agent completes naturally without calling ExitPlanMode — likely an edge case in the "plan agent that finished without exiting plan mode" branch.
Impact
Low — the error is cosmetic. No data loss, no state corruption. The full agent output is generated and consumable by the parent. The only impact is the incorrect failed status label.
Workaround
Read the agent's output file directly — the content is complete despite the failed status.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗