[BUG] Custom agents fail with "classifyHandoffIfNeeded is not defined" when run in background

Resolved 💬 5 comments Opened Feb 2, 2026 by kimnamwook1 Closed Mar 7, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Custom agents defined in ~/.claude/agents/ fail with a JavaScript error when executed with run_in_background: true via the Task tool.

The agent launches successfully in background mode, but when it tries to complete and return results, it crashes with "classifyHandoffIfNeeded is not defined" error.

The same custom agent works perfectly when run in foreground mode (without run_in_background or with run_in_background: false).

Built-in agents (Explore, Plan, general-purpose, etc.) work fine in both foreground and background modes.

What Should Happen?

Custom agents should complete successfully in background mode and return results to the main session, just like built-in agents do.

Error Messages/Logs

Agent "n8n beta docker tag research" failed: classifyHandoffIfNeeded is not defined


Task notification received:

<task-notification>
<task-id>a830048</task-id>
<status>failed</status>
<summary>Agent "n8n beta docker tag research" failed: classifyHandoffIfNeeded is not defined</summary>
</task-notification>

Steps to Reproduce

  1. Create a custom agent in ~/.claude/agents/web-research.md:
---
name: web-research
description: Use this agent for web research tasks
model: sonnet
color: blue
---

You are a web research specialist...
  1. Invoke the agent via Task tool with background mode:
{
  "subagent_type": "web-research",
  "prompt": "Search for information about n8n docker tags",
  "description": "n8n beta docker tag research",
  "run_in_background": true
}
  1. Wait for agent to complete.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.29

Platform

Other

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

_No response_

View original on GitHub ↗

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