claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Feature Request: Support custom agents from .claude/agents/ in Task tool

Open benbrastmckie opened this issue 1 year ago • 7 comments

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-purpose
  • statusline-setup
  • output-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 plans
  • research-specialist - Analyzes codebase and researches best practices
  • code-writer - Executes implementation plans phase-by-phase
  • debug-specialist - Root cause analysis and diagnostic reporting
  • doc-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

  1. Scan .claude/agents/*.md on startup
  2. Parse frontmatter for allowed-tools and description
  3. Register as valid subagent_type options for Task tool
  4. Pass agent definition content as system instructions when invoked
  5. Enforce allowed-tools restrictions from frontmatter

Additional Context

  • Agent definitions already support frontmatter with allowed-tools and description
  • Slash commands in .claude/commands/ already reference these agents
  • This would align with the existing pattern of user-defined commands and hooks

benbrastmckie avatar Oct 01 '25 21:10 benbrastmckie

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.

tino avatar Oct 23 '25 11:10 tino

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.

github-actions[bot] avatar Dec 11 '25 10:12 github-actions[bot]

yes the issue still exist as per the latest sdk version 0.1.18

otel-ai avatar Jan 03 '26 23:01 otel-ai

bump

riptscripts avatar Jan 17 '26 04:01 riptscripts

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:

  1. ✅ SDK correctly passes --agents parameter (verified in subprocess_cli.py:171-176)
  2. ✅ CLI receives the parameter
  3. ❌ Task tool ignores custom agents - only shows 4 built-in agents
  4. ❌ 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 --agents CLI parameter
  • Custom agents from .claude/agents/*.md files

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

  1. Re-label this issue:

    • Remove: enhancement
    • Add: bug, area:core, regression
  2. Prioritize: This breaks documented SDK features that users rely on

  3. 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.

mthakran-1510 avatar Jan 17 '26 23:01 mthakran-1510

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] avatar Feb 28 '26 10:02 github-actions[bot]

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.

github-actions[bot] avatar Mar 07 '26 14:03 github-actions[bot]