Agent fails with 'classifyHandoffIfNeeded is not defined' after successful completion
Description
Agents spawned via the Task tool consistently fail with the error classifyHandoffIfNeeded is not defined even though the agent's work completed successfully.
Environment
- Claude Code version: 2.1.44
- Platform: macOS Darwin 25.2.0
- Model: claude-opus-4-5-20251101
Steps to Reproduce
- Spawn an agent using the Task tool with
subagent_type: "code-simplifier:code-simplifier"(or other types) - Agent performs its work successfully (creates files, runs commands, creates PRs)
- Agent completes all requested tasks
- On cleanup/handoff, agent reports failure:
classifyHandoffIfNeeded is not defined
Expected Behavior
Agent should complete successfully without error since all work was done.
Actual Behavior
Agent reports failure status with error: classifyHandoffIfNeeded is not defined
The work IS completed - files are created, commits are made, PRs are opened. The error occurs during the teardown/handoff phase, not during execution.
Evidence
In a single session, 10+ agents all exhibited this behavior:
- 6 implementation agents (all created PRs successfully)
- 4+ review agents (all pushed fixes successfully)
Each agent's transcript shows successful completion of all tasks, followed by the system error.
Example from agent log:
{"type":"assistant","message":{"content":[{"type":"text","text":"The PR has been created successfully: **https://github.com/.../pull/281**..."}]}}
Followed by task notification: Agent "..." failed: classifyHandoffIfNeeded is not defined
Impact
- Functional impact: None - all work completes successfully
- UX impact: Confusing error messages, need to manually verify work completed
- Workflow impact: Cannot rely on task status to determine if work succeeded
Workaround
Check if the actual work was done (PR exists, files created, CI running) rather than trusting the agent status.
Additional Context
This appears to be a JavaScript/TypeScript runtime error in the agent orchestration code - classifyHandoffIfNeeded is likely a function that should be defined but isn't available in the execution context during agent teardown.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗