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

Closed
opened 2026-02-16 17:44:55 -05:00 by yindo · 2 comments
Owner

Originally created by @yanmxa on GitHub (Jan 10, 2026).

Originally assigned to: @thdxr on GitHub.

Description

Commit b9ef09a0f4 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: b9ef09a0f4
Originally created by @yanmxa on GitHub (Jan 10, 2026). Originally assigned to: @thdxr on GitHub. ## Description Commit b9ef09a0f4e8c96b4549352b53a64cee4be32aa7 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: ```typescript const COMMAND_GLOB = new Bun.Glob("{command,commands}/**/*.md") ``` 2. But the name extraction logic only checks for singular patterns: ```typescript 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: b9ef09a0f4e8c96b4549352b53a64cee4be32aa7
yindo closed this issue 2026-02-16 17:44:55 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 10, 2026):

This issue addresses the implementation gap for plural directory support that was requested in #5052. The plural patterns were added to the glob patterns but the name extraction logic wasn't updated accordingly. This fix ensures that commands and agents defined in plural directories (e.g., commands/, agents/) have their names extracted correctly, preserving nested directory prefixes as intended.

@github-actions[bot] commented on GitHub (Jan 10, 2026): This issue addresses the implementation gap for plural directory support that was requested in #5052. The plural patterns were added to the glob patterns but the name extraction logic wasn't updated accordingly. This fix ensures that commands and agents defined in plural directories (e.g., `commands/`, `agents/`) have their names extracted correctly, preserving nested directory prefixes as intended.
Author
Owner

@rekram1-node commented on GitHub (Jan 13, 2026):

fixed by: https://github.com/anomalyco/opencode/commit/735f3d17bc836e4b0905d1094794699c45a99804

@rekram1-node commented on GitHub (Jan 13, 2026): fixed by: https://github.com/anomalyco/opencode/commit/735f3d17bc836e4b0905d1094794699c45a99804
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4652