Plan agent fails with 'classifyHandoffIfNeeded is not defined' after completing work

Resolved 💬 3 comments Opened Feb 12, 2026 by allenhurff Closed Feb 16, 2026

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

  1. Spawn a Plan agent via the Task tool with a research-only prompt (no implementation planning)
  2. The agent reads files, performs analysis, and produces output normally
  3. The agent completes its work without calling ExitPlanMode (since the task was research, not implementation planning)
  4. 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.

View original on GitHub ↗

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