anomalyco / anomalyco/opencode
.md agents unwanted tool calls searching for own instructions on every run - due to .md frontmatter `prompt:` silently dropped
@kitlangton is already working on this.
Since Sep 6, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Issue details
For Markdown-defined agents (.opencode/agents/*.md), a prompt: key set in the YAML frontmatter is silently ignored. The resolved prompt always defaults to the Markdown body text, even if the body is empty.
Additionally, {file:...} and {env:...} token substitutions—which are documented for opencode.json's agent.<name>.prompt—are never applied when parsing these Markdown files. As a result, token references are never resolved.
Impact & Behavioral Cost
When an agent resolves an empty prompt:
- It falls back to OpenCode's generic default system prompt.
- On every invocation, the agent spends extra tool calls (file/glob searches across
.opencode/,~/.config/opencode,~/.claude, and speculativegitcommands) trying to discover its own missing instructions.
This results in wasted tokens, unnecessary execution turns, and context window pollution.
Expected Behavior
The agent's system prompt resolves to the file contents of .opencode/prompts/foo.md.
Actual Behavior
The resolved prompt evaluates to the empty Markdown body. The frontmatter prompt: key and its {file:...} reference are silently dropped without any warnings or errors, causing the agent to run without a system prompt.
Where It Happens
packages/opencode/src/config/agent.ts:load()/loadMode()constructs the configuration object as{ ...md.data, prompt: md.content.trim() }. The body content unconditionally overwrites the frontmatterpromptfield.config/variable.ts: The{file:...}and{env:...}token substitution pass is only invoked foropencode.jsonconfigs and is never run for Markdown files parsed viaConfigMarkdown.parse().
Possible Fix
- Allow
promptset in frontmatter to take precedence over the Markdown body (or fall back to body content only whenpromptis undefined in frontmatter). - Apply the same
{file:...}/{env:...}variable substitution pass used foropencode.jsonto frontmatter fields parsed from Markdown agents and commands.
Plugins
No response
OpenCode version
1.18.27
Steps to reproduce
- Create
.opencode/agent/foo.mdwith YAML frontmatter and an empty body:--- mode: primary prompt: '{file:./prompts/foo.md}' --- - Create
.opencode/prompts/foo.mdwith system instructions (e.g.,You are a helpful assistant.). - Run
opencode debug agent foo(or executeopencodewithfooactive) to inspect the resolved configuration.
Screenshot and/or share link
Operating System
macOS 15.6
Terminal
Terminal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.