Skip to content

Load subagent names from agents/ markdown files#117

Open
OZoneGuy wants to merge 4 commits into
Nomadcxx:mainfrom
OZoneGuy:feat/read-agents-from-directory
Open

Load subagent names from agents/ markdown files#117
OZoneGuy wants to merge 4 commits into
Nomadcxx:mainfrom
OZoneGuy:feat/read-agents-from-directory

Conversation

@OZoneGuy

@OZoneGuy OZoneGuy commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Extend readSubagentNames to load agents from agents/*.md next to the OpenCode config, in addition to the agent section in opencode.json
  • Parse markdown frontmatter for mode and disable, merge with JSON-defined agents (directory wins on name clash), and keep existing subagent selection behavior
  • Add unit tests for directory-only agents, merge/override, and disabled markdown agents

Test plan

  • bun test tests/unit/mcp-config.test.ts

Made with Cursor


I have my agents defined in markdown files for opencode, https://opencode.ai/docs/agents/#markdown, and they are not picked up by the plugin. Adding code to pick up the markdown agents.

OpenCode also defines agents as *.md files under the config agents directory, so readSubagentNames now merges those definitions with opencode.json agents.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Nomadcxx

Copy link
Copy Markdown
Owner

FYI, three follow-ups that align this with how OpenCode itself loads agents (packages/opencode/src/config/agent.ts). I will push them on top of your branch so this PR carries them.

  1. Read agent/ as well as agents/. OpenCode globs {agent,agents}/**/*.md, so anyone on the singular agent/ layout gets nothing from the current code. This is the main gap.

  2. Recurse into subdirectories. The flat readdirSync skips nested agent files, and the basename-only name can differ from the path-based name OpenCode uses.

  3. Handle quoted and alternate frontmatter values. mode: "subagent" keeps its quotes under the current regex and stops matching subagent, and disable: "true" or disable: yes slips past the exact === "true" check. Strip the quotes and accept the truthy forms. No YAML dependency, so your regex approach stays.

Commits to follow. Thanks for kicking this off.

Read from both `agent/` and `agents/` (OpenCode globs {agent,agents}/**/*.md),
scan recursively with path-based names, and parse quoted/alternate frontmatter
values (`mode: "subagent"`, `disable: "true"`, `disable: yes`).

Adds unit tests plus a real-filesystem test exercising both directories and
nested agents on disk.
@Nomadcxx

Copy link
Copy Markdown
Owner

Pushed the three fixes as a commit on top. Covered by unit tests and a real-filesystem test that writes agent/ and agents/ trees to disk (with a nested agent) and reads them back, so the recursive readdirSync and path-based naming run for real, not just against mocks.

Still needs a live check before merge: confirm that in a running OpenCode session the discovered names actually reach the task tool, so the model can spawn an agent defined only in agent/foo.md. The loader is verified end to end at the filesystem layer; the path through OpenCode subagent selection is not, since that needs a real session.

Nomadcxx added 2 commits July 21, 2026 14:32
OpenCode deletes JSON agents marked `disable: true` (agent/agent.ts). The loader
passed them through, so markdown `disable` worked but JSON `disable` did not.
Filter disabled JSON agents to match, with a regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants