Skip to content

User-level agents (~/.claude/agents/) only loads last file alphabetically #26044

@charleswoerner-wayve

Description

@charleswoerner-wayve

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?

When placing multiple agent .md files in ~/.claude/agents/ (user-level agents), only the last file alphabetically is loaded. All other agent files are silently ignored.

Workaround: Use project-level agents (.claude/agents/ in the repo root). Project-level agent loading does not have this bug.

What Should Happen?

All agents should have loaded from ~/.claude/agents, not just the last agent alphabetically.

Error Messages/Logs

Steps to Reproduce

  1. Create multiple valid agent .md files in ~/.claude/agents/ (aaa-agent, bbb-agent, ccc-agent)
  2. Restart Claude Code
  3. Check /agents dialog
  4. of user agents, only ccc-agent will be visible in /agents list, along with built-in and project level agents

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

2.1.41

Claude Code Version

2.1.42

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Terminal.app (macOS)

Additional Information

Claude itself diagnosed this issue. I created a Claude expert subagent and kept pushing it to run tests and eventually it stumbled upon the issue. Here is it's diagnostic info:

` Diagnostic Evidence

┌──────────────────────────────────────┬──────────────────────────────────────────┐
│ Files in ~/.claude/agents/ │ Agent that loads │
├──────────────────────────────────────┼──────────────────────────────────────────┤
│ 10 agents (a-w) │ weekly-dev-summary (last alphabetically) │
├──────────────────────────────────────┼──────────────────────────────────────────┤
│ claude-config-architect + test-agent │ test-agent (last alphabetically) │
├──────────────────────────────────────┼──────────────────────────────────────────┤
│ All above + zzz-test-agent │ zzz-test-agent (last alphabetically) │
└──────────────────────────────────────┴──────────────────────────────────────────┘

Each test involved a full restart of Claude Code.

Root Cause Hypothesis

The agent loader for user-level agents appears to overwrite a variable instead of appending to a collection when iterating over files. Since iteration
is alphabetical, only the last file survives.`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingplatform:linuxIssue specifically occurs on Linux

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions