Feature Request: Support custom agents from .claude/agents/ in Task tool
Feature Request
Summary
Allow the Task tool to use custom agent definitions from directory as options.
Current Behavior
The Task tool only supports three built-in agent types:
general-purposestatusline-setupoutput-style-setup
Custom agent definitions can be created in .claude/agents/*.md (e.g., plan-architect.md, research-specialist.md), but cannot be invoked via the Task tool because they're not recognized as valid subagent_type values.
Desired Behavior
The Task tool should automatically discover and register custom agents from .claude/agents/:
# Example: .claude/agents/plan-architect.md
---
allowed-tools: Read, Write, Grep, Glob, WebSearch
description: Specialized in creating detailed, phased implementation plans
---
# Plan Architect Agent
[Agent instructions and behavioral guidelines...]
Then allow invocation:
Task {
subagent_type: "plan-architect",
description: "Create implementation plan",
prompt: "[Task details]"
}
Use Case
Custom slash commands (e.g., /plan, /orchestrate) can reference specialized agents for workflow phases:
plan-architect- Generates structured implementation plansresearch-specialist- Analyzes codebase and researches best practicescode-writer- Executes implementation plans phase-by-phasedebug-specialist- Root cause analysis and diagnostic reportingdoc-writer- Updates documentation and generates summaries
This would enable better workflow orchestration with tool-restricted, purpose-specific agents while maintaining the existing agent definition format.
Current Workaround
Use subagent_type: "general-purpose" and include custom agent instructions in the prompt, but this loses the benefits of:
- Tool access restrictions per agent type
- Clear agent type discovery/documentation
- Separation of concerns between agent definitions and command logic
Proposed Implementation
- Scan
.claude/agents/*.mdon startup - Parse frontmatter for
allowed-toolsanddescription - Register as valid
subagent_typeoptions for Task tool - Pass agent definition content as system instructions when invoked
- Enforce
allowed-toolsrestrictions from frontmatter
Additional Context
- Agent definitions already support frontmatter with
allowed-toolsanddescription - Slash commands in
.claude/commands/already reference these agents - This would align with the existing pattern of user-defined commands and hooks
This works for me, but I noticed it doesn't pick it up if the frontmatter is invalid. I think you are missing the name: name-with-dashes here. I also had it when the description was formatted over multiple lines.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
yes the issue still exist as per the latest sdk version 0.1.18
bump
This Should Be Labeled as BUG, Not Enhancement
This issue describes a broken documented feature, not a feature request.
Evidence This Is a Bug
Official SDK Documentation Promises This Works:
- https://docs.claude.com/en/api/agent-sdk/subagents
- Python SDK:
ClaudeAgentOptions(agents={...}) - TypeScript SDK: Agent definitions with custom tools
But It Doesn't Work:
- ✅ SDK correctly passes
--agentsparameter (verified insubprocess_cli.py:171-176) - ✅ CLI receives the parameter
- ❌ Task tool ignores custom agents - only shows 4 built-in agents
- ❌ Error: "Agent type 'X' not found. Available agents: general-purpose, statusline-setup, output-style-setup, Explore"
Root Cause (From Code Analysis)
Location: cli.js - Task tool agent lookup
let J = Z.options.agentDefinitions.activeAgents // Only contains 4 built-in agents
let I = J.find((z) => z.agentType === B);
if (!I) throw Error(`Agent type '${B}' not found`);
Problem: The activeAgents array is never populated with:
- Custom agents from
--agentsCLI parameter - Custom agents from
.claude/agents/*.mdfiles
Impact
This breaks core SDK functionality:
- ❌ Multi-agent workflows impossible
- ❌ Specialist delegation doesn't work
- ❌ Tool access restrictions non-functional
- ❌ All SDK users following official docs are blocked
Confirmed Still Broken
- SDK v0.1.4 (Oct 2025) - broken
- SDK v0.1.18 (Jan 2026) - still broken (confirmed by @nikhil-oteai on Jan 3)
- Claude Code v2.1.9 (Jan 2026) - still broken (see #18622)
Related Issues With More Details
- #9865 - My original detailed bug report (auto-closed as duplicate, now locked)
- Contains SDK code analysis
- Shows CLI source code location
- Proves SDK works correctly, CLI doesn't
- #18622 - Task tool schema doesn't show custom agents (unlike Skill tool which works)
- #11205 - Custom subagents not discovered in v2.0.35
Requested Actions
-
Re-label this issue:
- Remove:
enhancement - Add:
bug,area:core,regression
- Remove:
-
Prioritize: This breaks documented SDK features that users rely on
-
Timeline: Any ETA for fix? This seems like a ~half-day effort based on code analysis
Thank you for maintaining Claude Code! This is a critical issue for SDK users building multi-agent systems.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.