Skip to content

fix: name extraction missing plural directory support (commands/, agents/) #7667

@yanmxa

Description

@yanmxa

Description

Commit b9ef09a added glob pattern support for plural directory names (commands/, agents/), but did not update the name extraction logic accordingly.

This causes nested command/agent names to lose their prefix when using plural directory names.

Reproduction

When using OPENCODE_CONFIG_DIR pointing to a custom config directory with structure:

commands/
  email/
    digest.md
  • Expected command name: email/digest
  • Actual command name: digest (prefix lost)

Root Cause

In packages/opencode/src/config/config.ts:

  1. The glob pattern correctly matches both singular and plural:

    const COMMAND_GLOB = new Bun.Glob("{command,commands}/**/*.md")
  2. But the name extraction logic only checks for singular patterns:

    const patterns = ["/.opencode/command/", "/command/"]
  3. When the path contains /commands/ (plural), no pattern matches, causing fallback to path.basename() which loses the directory prefix.

The same issue exists in loadAgent function.

Proposed Fix

Add plural patterns to the name extraction logic:

  • For commands: add "/.opencode/commands/" and "/commands/"
  • For agents: add "/.opencode/agents/" and "/agents/"

I have a fix ready and can submit a PR if this approach is approved.

Related

  • Original commit adding plural support: b9ef09a

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions