Skip to content

[BUG] Custom Agents in ~/.claude/agents/ Not Loaded as Task Subagent Types #20931

Description

@islee

Preflight Checklist

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

What's Wrong?

Environment:

  • OS: macOS Darwin 25.2.0
  • Claude Code Version: [Your version - check with claude --version]
  • Working Directory: /Users/insu/code/pyright-mcp-server

Summary:
Custom agents placed in ~/.claude/agents/ are not discovered or loaded at session start, making them unavailable for Task(agent-name, "...") invocations. The error message
states the agent "isn't available as a built-in Task subagent type."

Expected Behavior:
Custom agents defined in ~/.claude/agents/*.md should be:

  1. Discovered and loaded at session start
  2. Available for invocation via Task(agent-name, "...")
  3. Persist across sessions

Actual Behavior:

  • Custom agent files are completely ignored
  • Task(coordinator, "...") fails with error: "coordinator agent isn't available as a built-in Task subagent type"
  • Only built-in agents (Explore, Plan, general-purpose) and UI-created agents work
  • UI-created agents disappear after session restart

Evidence:

1. Agent File Exists and Is Valid

$ ls -lh ~/.claude/agents/coordinator.md                                                                                                                                         
-rw-r--r--  1 insu  staff  99KB Jan 26 15:20 ~/.claude/agents/coordinator.md                                                                                                     
                                                                                                                                                                                 
$ head -20 ~/.claude/agents/coordinator.md                                                                                                                                       
---                                                                                                                                                                              
# Agent Identity                                                                                                                                                                 
name: coordinator                                                                                                                                                                
slug: coordinator                                                                                                                                                                
model: haiku                                                                                                                                                                     
tier: haiku                                                                                                                                                                      
version: "2.0"                                                                                                                                                                   
                                                                                                                                                                                 
# AI-OD Capability Declaration                                                                                                                                                   
capabilities:                                                                                                                                                                    
  strengths:                                                                                                                                                                     
    - "DAG plan execution and orchestration"                                                                                                                                     
    - "Task dispatch and worker coordination"                                                                                                                                    
    ...                                                                                                                                                                          
                                                                                                                                                                                 
2. Referenced in Configuration Files                                                                                                                                             
                                                                                                                                                                                 
# routing.yaml (lines 101-106)                                                                                                                                                   
$ grep -A5 "coordinator:" ~/.claude/config/routing.yaml                                                                                                                          
coordinator:                                                                                                                                                                     
  tier: haiku                                                                                                                                                                    
  model: haiku                                                                                                                                                                   
  delegates_to: [all workers]                                                                                                                                                    
  description: "Plan execution and orchestration"                                                                                                                                
                                                                                                                                                                                 
# autonomy.yaml (lines 192-194)                                                                                                                                                  
$ grep -A2 "coordinator:" ~/.claude/config/autonomy.yaml                                                                                                                         
  coordinator:                                                                                                                                                                   
    always_supervised: false                                                                                                                                                     
    auto_execute_threshold: 0.85                                                                                                                                                 
                                                                                                                                                                                 
3. Never Appears in Metrics                                                                                                                                                      
                                                                                                                                                                                 
$ grep '"subagent_type": "coordinator"' ~/.claude/metrics/sessions/*.jsonl                                                                                                       
# Returns nothing - coordinator has NEVER been invoked                                                                                                                           
                                                                                                                                                                                 
# Compare with other agents that DO work:                                                                                                                                        
$ grep -o '"subagent_type": "[^"]*"' ~/.claude/metrics/sessions/*.jsonl | sort | uniq -c                                                                                         
  12 "subagent_type": "Explore"                                                                                                                                                  
   8 "subagent_type": "Plan"                                                                                                                                                     
   6 "subagent_type": "git-ops"                                                                                                                                                  
   4 "subagent_type": "delegation-guide-manager"                                                                                                                                 
   3 "subagent_type": "dba"                                                                                                                                                      
                                                                                                                                                                                 
4. Other Custom Agents Also Fail                                                                                                                                                 
                                                                                                                                                                                 
The issue affects ALL file-based custom agents:                                                                                                                                  
- coordinator.md (2,853 lines)                                                                                                                                                   
- analyst.md (exists, never loaded)                                                                                                                                              
- Multiple other .md files in ~/.claude/agents/                                                                                                                                  
                                                                                                                                                                                 
Impact:                                                                                                                                                                          
- HIGH: Completely breaks custom agent functionality                                                                                                                             
- Users cannot create reusable specialized agents via file definitions                                                                                                           
- Forces reliance on UI-created agents that don't persist                                                                                                                        
- Documented agent system unusable                                                                                                                                               
                                                                                                                                                                                 
Workarounds:                                                                                                                                                                     
1. Use built-in agents (Explore, Plan, general-purpose)                                                                                                                          
2. Recreate agents via /agents UI each session (session-scoped only)                                                                                                             
3. Use Task(thinker, "MODE: plan") as replacement for coordinator                                                                                                                
                                                                                                                                                                                 
Additional Context:                                                                                                                                                              
- settings.json is valid JSON                                                                                                                                                    
- Hooks system works correctly (SessionStart hooks execute)                                                                                                                      
- Commands/skills load properly from ~/.claude/commands/                                                                                                                         
- Only agent file discovery is broken                                                                                                                                            
                                                                                                                                                                                 
Related Issues:                                                                                                                                                                  
This may be related to earlier reports about agent discovery (#11205 if it exists).                                                                                              
                                                                                                                                                                                 
Requested Fix:                                                                                                                                                                   
Either:                                                                                                                                                                          
1. Fix file discovery: Scan ~/.claude/agents/*.md at session start and register agents                                                                                           
2. Document limitation: Clarify that file-based agents aren't supported                                                                                                          
3. Add diagnostics: Provide /agents debug command to show why agents fail to load                                                                                                
                                                                                                                                                                                 
Files for Review:                                                                                                                                                                
- ~/.claude/agents/coordinator.md (full agent definition)                                                                                                                        
- ~/.claude/config/routing.yaml (agent routing configuration)                                                                                                                    
- Session logs showing Task() invocation failure                                                                                                                                 
                                                                                                                                                                                 
Happy to provide additional diagnostics or test fixes.                                                                                                                           
                   

### What Should Happen?

Custom agents defined in `~/.claude/agents/*.md` should be:                                                                                                                      
1. Discovered and loaded at session start                                                                                                                                        
2. Available for invocation via `Task(agent-name, "...")`                                                                                                                        
3. Persist across sessions   

### Error Messages/Logs

```shell
⏺ coordinator(Execute Phase 2.5 hardening plan)                                                                                                                                    
⎿  Initializing…                                                                                                                                                                 
⎿  Error: Agent type 'coordinator' not found. Available agents: Bash, general-purpose, statusline-setup, Explore, Plan, claude-code-guide, architect, web-fetcher, maestro,      
   thinker, guide-manager, orchestrator, pyright-specialist   

claude-code-guide(Investigate why coordinator not loadable)                                                                                                                      
⎿  Done (12 tool uses · 42.4k tokens · 50s)                                                                                                                                      
⎿  Running PostToolUse hooks… (1/2 done)                                                                                                                                         
                                                                                                                                                                                 
⏺ Investigation Complete: Root Cause Found                                                                                                                                         
                                                                                                                                                                                 
I've identified why the coordinator agent isn't loading. This is a known bug in Claude Code's agent discovery system.                                                            
                                                                                                                                                                                 
---                                                                                                                                                                              
The Problem                                                                                                                                                                      
                                                                                                                                                                                 
Your coordinator.md file is perfect - correctly placed, valid YAML frontmatter, proper structure. But Claude Code has a broken file discovery mechanism that ignores custom      
agents in ~/.claude/agents/.                                                                                                                                                     
                                                                                                                                                                                 
Evidence                                                                                                                                                                         
                                                                                                                                                                                 
1. coordinator.md exists and is valid (confirmed earlier - 2,853 lines, proper frontmatter)                                                                                      
2. Listed in routing.yaml (lines 101-106)                                                                                                                                        
3. But NEVER appears in metrics - No "subagent_type": "coordinator" in any session                                                                                               
4. Other agents work - git-ops, delegation-guide-manager show up in metrics                                                                                                      
                                                                                                                                                                                 
Why This Happens                                                                                                                                                                 
                                                                                                                                                                                 
Claude Code uses two discovery mechanisms:                                                                                                                                       
┌────────────────────────────────────┬───────────┬────────────────────────┐                                                                                                      
│               Method               │  Status   │    Agents Available    │                                                                                                      
├────────────────────────────────────┼───────────┼────────────────────────┤                                                                                                      
│ File-based (~/.claude/agents/*.md) │ 🔴 BROKEN │ None (files ignored)   │                                                                                                      
├────────────────────────────────────┼───────────┼────────────────────────┤                                                                                                      
│ UI-created (/agents command)       │ ✅ WORKS  │ Session only           │                                                                                                      
├────────────────────────────────────┼───────────┼────────────────────────┤                                                                                                      
│ Built-in                           │ ✅ WORKS  │ Always (Explore, Plan) │                                                                                                      
└────────────────────────────────────┴───────────┴────────────────────────┘                                                                                                      
When you call Task(coordinator, "..."), Claude Code checks its loaded agents registry. Since file discovery is broken, coordinator never gets registered.

Steps to Reproduce

  1. Create a custom agent file:
    cat > ~/.claude/agents/test-agent.md << 'EOF'

name: test-agent
slug: test-agent
model: haiku
tools:
required: ["Read"]

Test Agent

You are a test agent for reproduction.
EOF

  1. Start a new Claude Code session:
    claude

  2. Try to invoke the agent:
    Task(test-agent, "test invocation")

  3. Observe error: "test-agent agent isn't available as a built-in Task subagent type"

  4. Verify file is ignored:
    grep '"subagent_type": "test-agent"' ~/.claude/metrics/sessions/*.jsonl

Returns nothing

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.19 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions