[BUG] Custom Subagents in ~/.claude/agents/ Not Discovered or Loaded (v2.0.35)

Status Open
Maintainer reply None cached
Activity 12 comments · opened Nov 7, 2025

[BUG] Custom Subagents in ~/.claude/agents/ Not Discovered or Loaded (v2.0.35)

Summary

Custom subagents placed in ~/.claude/agents/ are completely ignored by Claude Code v2.0.35, despite following the official documentation exactly. This has been an ongoing issue since v1.0.60 when subagents were first introduced (75+ versions ago), making custom agents effectively unusable for users who manually create agent files.

Environment

  • Claude Code Version: 2.0.35
  • Platform: Android (Termux)
  • OS: Linux 5.4.254-qgki-gd2808d43acca aarch64
  • Shell: Bash
  • Installation Method: npm (via Termux)

Expected Behavior

According to the official documentation (https://code.claude.com/docs/en/subagents):

File locations Subagents are stored as Markdown files with YAML frontmatter in two possible locations: | Type | Location | Scope | |------|----------|-------| | User subagents | ~/.claude/agents/ | Available across all projects |

Custom agents in ~/.claude/agents/ should be automatically discovered at session startup and available via the Task tool with subagent_type parameter.

Actual Behavior

Custom agents in ~/.claude/agents/ are completely ignored. Only built-in agents are available:

  • general-purpose
  • statusline-setup
  • Explore
  • Plan

When attempting to invoke a custom agent:

Task({
  subagent_type: "termux-platform-agent",
  prompt: "Test agent"
})

Error: Agent type 'termux-platform-agent' not found.
Available agents: general-purpose, statusline-setup, Explore, Plan

Reproduction Steps

1. Create a Valid Custom Agent

mkdir -p ~/.claude/agents
cat > ~/.claude/agents/test-agent.md << 'EOF'
---
name: test-agent
description: Simple test agent to verify discovery mechanism
tools: Read, Bash
model: sonnet
---

You are a test agent. Confirm you're operational when invoked.
EOF

2. Verify File Exists and is Valid

$ ls -la ~/.claude/agents/test-agent.md
-rw-------. 1 user user 156 Nov 7 12:00 ~/.claude/agents/test-agent.md

$ head -10 ~/.claude/agents/test-agent.md
---
name: test-agent
description: Simple test agent to verify discovery mechanism
tools: Read, Bash
model: sonnet
---

You are a test agent. Confirm you're operational when invoked.

3. Start Fresh Claude Code Session

claude
# or restart existing session with /exit and relaunch

4. Attempt to Invoke Custom Agent

Within Claude Code:

> Use the Task tool to invoke test-agent

Result: Agent type 'test-agent' not found

5. Compare with UI-Created Agent

> /agents
[Select "Create New Agent"]
[Create any simple agent through UI]

Result: UI-created agent DOES work immediately, proving the Task tool itself functions correctly.

Evidence Collected

Agent Files Present (16 custom agents)

$ ls -1 ~/.claude/agents/*.md | grep -v README | grep -v SUMMARY
/home/user/.claude/agents/companion-platform-agent.md
/home/user/.claude/agents/config-validator.md
/home/user/.claude/agents/cross-platform-builder.md
/home/user/.claude/agents/cross-platform-validator.md
/home/user/.claude/agents/integrated-system-validator.md
/home/user/.claude/agents/integration-tester.md
/home/user/.claude/agents/mobile-platform-agent.md
/home/user/.claude/agents/quadra-lock-cssr.md
/home/user/.claude/agents/quadran-lock-gatekeeper.md
/home/user/.claude/agents/restraint-doctrine.md
/home/user/.claude/agents/security-audit-agent.md
/home/user/.claude/agents/termux-platform-agent.md
/home/user/.claude/agents/test-agent.md
/home/user/.claude/agents/test-discovery.md
/home/user/.claude/agents/test-suite-auditor.md
/home/user/.claude/agents/windows-platform-agent.md

Example Valid Agent File

---
name: termux-platform-agent
description: Termux Android CLI development and deployment specialist. Use when working with Termux-specific features, Android environment, or mobile CLI deployments.
tools: Read, Grep, Bash, Glob, Edit, Write
model: sonnet
color: green
---

You are a Termux platform specialist with expertise in Android CLI development, Termux environment configuration, and mobile deployment strategies.

[... system prompt continues ...]

Validation Results

All agent files pass validation:

  • ✅ Valid YAML frontmatter
  • ✅ Required fields present (name, description)
  • ✅ Optional fields properly formatted (tools, model, color)
  • ✅ System prompt content after frontmatter
  • ✅ No syntax errors or hidden characters

Tested Scenarios

| Scenario | Result |
|----------|--------|
| Manually created agent before session start | ❌ Not discovered |
| Manually created agent during active session | ❌ Not discovered |
| Manually created agent, then restart | ❌ Not discovered |
| UI-created agent via /agents command | ✅ Works immediately |
| Adding color field to match UI format | ❌ Still not discovered |
| Built-in agents (Explore, Plan, etc.) | ✅ Work correctly |

Key Findings

1. Only UI-Created Agents Work

Agents created through the /agents interactive UI are immediately available and functional. The UI does something special (registration/indexing?) that manual file creation does not trigger.

2. No Reload/Refresh Mechanism

There's no command to reload agents from ~/.claude/agents/:

  • No /reload-agents command
  • --agents CLI flag only works for inline JSON definitions
  • Restarting Claude Code doesn't help

3. UI-Created Agents Also Disappear

Even UI-created agents (like config-validator) that worked in one session are gone after restart, suggesting the agent registry is session-scoped only and never persists from file discovery.

4. File Location is Correct

$ echo $HOME
/data/data/com.termux/files/home

$ ls -ld ~/.claude/agents
drwx------. 2 user user 8192 Nov 7 12:02 /data/data/com.termux/files/home/.claude/agents

The directory structure matches documentation exactly.

Impact

Severity: HIGH - Custom agents are a core feature introduced in v1.0.60 (75 versions ago) but remain completely broken for manual file creation.

User Impact:

  • Custom agents are effectively unusable unless created via UI
  • No way to version control or share agent files with teams
  • Cannot automate agent deployment
  • Cannot bulk-create or programmatically generate agents
  • Forces tedious manual UI recreation for each agent
  • Breaks expected workflow documented in official docs

Affected Users:

  • Anyone following the official documentation to create custom agents manually
  • Users wanting to version control their agent configurations
  • Teams wanting to share agent definitions via git
  • Power users creating multiple specialized agents
  • Anyone who's been trying to use this feature since v1.0.60

Workarounds Attempted

❌ Failed Workarounds

  1. Adding color field to match UI-created agents
  2. Restarting Claude Code
  3. Creating agents during active session
  4. Different YAML formatting
  5. Checking file permissions (all files readable)
  6. Verifying no hidden characters in frontmatter

✅ Working Workaround (suboptimal)

Use /agents UI command to manually recreate each agent. This is:

  • Tedious for multiple agents
  • Not version controllable
  • Not automatable
  • Doesn't persist between major sessions
  • Defeats the purpose of file-based agent definitions

Additional Context

Historical Context

This issue has persisted since v1.0.60 when custom subagents were first introduced. Users have been dealing with this broken behavior across:

  • v1.0.60 → v1.0.x (initial buggy releases)
  • v2.0.0 (major rewrite: "Claude Code SDK" → "Claude Agent SDK")
  • v2.0.1 → v2.0.35 (current, 35 patch versions with issue still present)

Related Files Checked

# No agent registration/cache files found
$ find ~/.claude -name "*agent*" -type f | grep -v ".md" | grep -v "archive"
# Only session transcripts and todos, no registry/index

# Config files don't reference agent discovery
$ grep -r "agent" ~/.claude/*.json
# No relevant agent configuration found

Requested Fix

  1. Implement proper file discovery at session startup that scans ~/.claude/agents/ recursively
  2. Add reload command like /reload-agents to trigger discovery without restart
  3. Make UI and manual creation equivalent - whatever the UI does should work for manual files
  4. Add debugging - show which agents were discovered during startup (e.g., in verbose mode)
  5. Document limitations if certain fields are required that aren't in docs

Additional Questions for Maintainers

  1. Is there an agent registry/index file we're supposed to create?
  2. Are there required fields beyond name and description that aren't documented?
  3. Is ~/.claude/agents/ discovery actually implemented in v2.0.35?
  4. Should we be using project-level .claude/agents/ instead?
  5. Is the --agents CLI flag the intended way to use custom agents?

Files Available for Testing

I can provide:

  • All 16 agent files for reproduction
  • Test script that validates agent file formats
  • Session transcripts showing the issue
  • Comparison between working UI-created and non-working manual agents

---

This bug makes custom agents effectively unusable for the documented workflow. Please prioritize fixing agent file discovery in ~/.claude/agents/ to match the official documentation.

Filed by user experiencing this issue consistently since v1.0.60 (75+ versions).

View original on GitHub ↗

12 Comments

github-actions[bot] · 9 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/8256
  2. https://github.com/anthropics/claude-code/issues/5289
  3. https://github.com/anthropics/claude-code/issues/9366

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

GrizzlyRooster34 · 9 months ago

This is a issue, seriously

github-actions[bot] · 8 months ago

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.

guppy-jpf · 7 months ago

i never had this problem until "upgrading" to 2.1.1 this week.
now 2 of my 5 custom agents are not showing up. they had previously worked well for several months.

after letting claude flail around trying to figure it out across several sessions, the best it could come up with
is that it may be related to the size of the agent definition file (the files defining the missing agents are 17548
and 29387 bytes; of the ones that show up, the largest size is 15541). however, it seems pretty unlikely that
size would be the issue. claude's own analysis showed no syntax or related issues with the definitions of the
missing agents, which have been stable for several weeks. the only change has been CC itself.

CC 2.1.1 on macos

notable output from /doctor:

 Agent Parse Errors
 └ Failed to parse 2 agent file(s):
   └ /Users/jpf/.claude/agents/tech-translator-en-ja.md: Missing required "name" field in frontmatter
   └ /Users/jpf/.claude/agents/android-build-expert.md: Missing required "name" field in frontmatter

however, both files do have properly defined name fields.

update 2 - a possible solution (for the issue as described in this comment anyway):
upon closer inspection of the failing-to-parse definition files, i became suspicious of the way the description
fields were formatted, specifically with regard to quoting. all my agents have been developed via an iterative
process wherein i ask claude to create an agent definition based on my criteria, which are then refined over
the course of different sessions as issues are discovered or enhancements are required. this is done not by
using the /agents interface, but rather by discussing the changes with CC and then having it edit the files
directly. across various refinement sessions, some of the descriptions became quite complex (spanning multiple
lines, containing both single and double-quotes, colons, XML-like markup, etc.). my issue turns out to have been
caused by these (formerly parse-able) descriptions. apparently 2.1.x is using stricter parsing for the YAML
frontmatter. when i updated the description fields to use literal block scalars, the issue no longer occurred.
hopefully this may help others if they've been experiencing similar problems since 2.1 ...

properly quoted description block, e.g.:

---
name: android-build-expert
description: |
  Use this agent when you need expertise with Android app builds, Gradle build system, Android Gradle Plugin (AGP), dependency management, build configuration, or Flutter Android builds. This includes tasks like analyzing Gradle configurations, understanding build file impacts, optimizing build performance, debugging build failures, ensuring build reproducibility, or understanding how Android build components interact. Examples:

  <example>
  Context: The user needs to understand which Gradle files affect build output.
  user: "What Gradle configuration files can affect my Android build output?"
  assistant: "I'll use the android-build-expert agent to explain which Gradle files affect build output and how each impacts your builds."
  <commentary>
  Understanding configuration file impacts requires deep knowledge of Gradle build lifecycle and plugin architecture - perfect for the android-build-expert agent.
  </commentary>
  </example>
[...]
model: opus
color: yellow
---
markg85 · 7 months ago

Same issue here.

The problem in my case was the examples containing html blocks. Regardless, i used claude to fix claude :)

I just used the /doctor output as input for this query:

❯ My agent files have issues. They have a name property but the examples are probably messing something up?
 <doctor output>
  Inspect and fix them!

That fixed them all.
Claude probably needs to be a little less strict in it's parsing or use itself to parse those files and install those agents.

mabry-prv · 7 months ago

Confirmed Bug in Claude Code 2.1.7

Everything is set up correctly:

  • ✅ .claude/agents/ directory exists
  • ✅ 9 agent files with proper YAML frontmatter
  • ✅ Files are readable
  • ✅ Format matches documentation

But /agents shows "No agents found" - this is a regression bug.

You should report this:

Issue: Custom agents in .claude/agents/ not loaded

Claude Code version: 2.1.7
OS: macOS Darwin 25.2.0

Steps to reproduce:

  1. Create .claude/agents/code-reviewer.md with valid YAML frontmatter
  2. Run /agents command
  3. Shows "No agents found" despite files existing

Expected: Agents from .claude/agents/*.md should appear in /agents list
Actual: "No agents found"

Agent file format (confirmed valid per docs):
---
name: code-reviewer
description: Use this agent to perform comprehensive code reviews...
model: opus
---
[agent body]

DLTKDavidFarthing · 6 months ago

Samesies, running 2.1.31 on Windows and we have several agents defined in .claude/agents which worked before but which no longer load. Very annoying. I tried using /feedback to report the bug in Claude, but it kept cancelling out after typing a few characters in the bug description (which may itself be a bug...)

ulisseshen · 6 months ago

Yet persists

Rhapso · 5 months ago

Claude CLI created subagents loaded uncompletely. Only one out of several PERSONAL agents from ~/.claude/agents and one out of several PROJECT agents from .claude/agents.

verified on version: 2.1.80 and 2.1.62

bigjonroberts · 5 months ago

This was plaguing me and seemed random.
Took a copy of the leaked source code and made a utility with better error reporting in between steps to look up agents by file.

For our use case, we were installing globally in a devcontainer via npm and the following resolved the issue for us.

Root cause: npm install -g @anthropic-ai/claude-code strips execute permissions from the vendor ripgrep binary (vendor/ripgrep/x64-linux/rg gets 644 instead of 755). CC's loadMarkdownFiles() catches the resulting EACCES error and silently returns [].

fix:

chmod +x $(npm root -g)/@anthropic-ai/claude-code/vendor/ripgrep/*/rg

The relevant caller from cc => loadMarkdownFiles() in claude-code/src/utils/markdownConfigLoader.ts, lines 546-600:

/**
 * Generic function to load markdown files from specified directories
 * @param dir Directory (eg. "~/.claude/commands")
 * @returns Array of parsed markdown files with metadata
 */
async function loadMarkdownFiles(dir: string): Promise<
  {
    filePath: string
    frontmatter: FrontmatterData
    content: string
  }[]
> {
  // File search strategy:
  // - Default: ripgrep (faster, battle-tested)
  // - Fallback: native Node.js (when CLAUDE_CODE_USE_NATIVE_FILE_SEARCH is set)
  //
  // Why both? Ripgrep has poor startup performance in native builds.
  const useNative = isEnvTruthy(process.env.CLAUDE_CODE_USE_NATIVE_FILE_SEARCH)
  const signal = AbortSignal.timeout(3000)
  let files: string[]
  try {
    files = useNative
      ? await findMarkdownFilesNative(dir, signal)
      : await ripGrep(
          ['--files', '--hidden', '--follow', '--no-ignore', '--glob', '*.md'],
          dir,
          signal,
        )
  } catch (e: unknown) {
    // Handle missing/inaccessible dir directly instead of pre-checking
    // existence (TOCTOU). findMarkdownFilesNative already catches internally;
    // ripGrep rejects on inaccessible target paths.
    if (isFsInaccessible(e)) return []
    throw e
  }

  const results = await Promise.all(
    files.map(async filePath => {
      try {
        const rawContent = await readFile(filePath, { encoding: 'utf-8' })
        const { frontmatter, content } = parseFrontmatter(rawContent, filePath)

        return {
          filePath,
          frontmatter,
          content,
        }
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error)
        logForDebugging(
          `Failed to read/parse markdown file:  ${filePath}: ${errorMessage}`,
        )
        return null
      }
    }),
  )

  return results.filter(_ => _ !== null)
}
weihong15 · 3 months ago

Reproducing on macOS Darwin 25.2.0 with Claude Code v2.1.143

Hit this today — confirming the bug is platform-agnostic and still present 75+ versions later.

Environment

  • Claude Code: v2.1.143
  • OS: macOS Darwin 25.2.0
  • Install: official CLI

Setup

  • 3 user-level custom agents at ~/.claude/agents/:
  • fetch-vault.md (tools: Read, Glob, Grep)
  • vault-curator.md (tools: Read, Edit, Glob, Grep, Bash)
  • vault-scribe.md (tools: Read, Write, Edit, Glob, Grep)
  • All have valid frontmatter (name, description, tools, model: inherit)
  • No project-level .claude/agents/ involved
  • ~/.claude/settings.json and ~/.claude/settings.local.json contain no agent-related allow/deny rules

Observed

  • ✅ Agents ARE discovered at startup — they appear in the Agent tool's static description in the system prompt, with their descriptions intact
  • ❌ Agents are NOT in the runtime registry — calling \Agent(subagent_type="fetch-vault", ...)\ returns:

> \Agent type 'fetch-vault' not found. Available agents: claude-code-guide, Explore, general-purpose, Plan, statusline-setup\

  • Only the 5 built-in subagents are invocable. Custom names hit the dead branch.

Downstream effect
Any slash-command or skill that wraps a custom subagent fails mid-flow. In my case /fetch_agent (a thin wrapper around Agent(subagent_type="fetch-vault", ...)) errors out at every invocation.

Discovery vs runtime registry are out of sync. Discovery scans ~/.claude/agents/ correctly; the registry that gates the Agent tool's subagent_type enum doesn't see them.

Likely same root cause as the open #59881 (project-scope) and the closed-as-dup #20931.

kcarriedo · 3 months ago

Still hitting this on Linux (x86_64, npm install, v2.0.35+) — not Termux-specific. Reproduces the same way: agents in ~/.claude/agents/ are silently ignored, only the four builtin types (general-purpose, Plan, Explore, statusline-setup) resolve, and subagent_type: "<custom>" returns Agent type 'X' not found.

A few diagnostic notes from chasing this down on my end — sharing in case they help narrow it:

  1. Project-scoped agents under <project>/.claude/agents/ work fine. The discovery bug is specific to the user-scoped path. That tells me the file format, YAML frontmatter, and CLI-side parsing are all healthy — what's broken is whichever code path walks ~/.claude/agents/ at session init.
  1. claude --list-agents (when available in your build) confirms it. On affected builds, the user-scoped directory contents simply don't appear in the listing. That decouples the bug from "discovery happened but resolution failed" — it's a load-time miss, not a runtime mismatch.
  1. Symlinking project-scoped onto user-scoped works as a workaround. ln -s ~/.claude/agents/my-agent.md <project>/.claude/agents/my-agent.md is ugly but it side-steps the missing user-scope walker entirely. Useful only if you've got a small number of projects.
  1. The "75+ versions and still broken" framing is the load-bearing point. This isn't a fresh regression — it's a feature gap masquerading as a bug. Anyone building a personal agent library (the documented use case for the user-scoped path) is effectively unable to use it, which is why the same issue keeps getting reopened under slightly different titles (#41973, #58353 etc.).

If a maintainer wants more debug surface, happy to share strace/fs_usage traces showing the session-init process never opens any path under ~/.claude/agents/ on affected builds — the absence of those file opens is the clearest fingerprint of the load-time miss.