[BUG] Custom agents fail with "classifyHandoffIfNeeded is not defined" when run in background
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
- 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...
- 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
}
- 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_
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗