anomalyco / anomalyco/opencode

.md agents unwanted tool calls searching for own instructions on every run - due to .md frontmatter `prompt:` silently dropped

Open
#47,616 1 comment 0 reactions 1 assignee View on GitHub

@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 speculative git commands) 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 frontmatter prompt field.
  • config/variable.ts: The {file:...} and {env:...} token substitution pass is only invoked for opencode.json configs and is never run for Markdown files parsed via ConfigMarkdown.parse().

Possible Fix

  • Allow prompt set in frontmatter to take precedence over the Markdown body (or fall back to body content only when prompt is undefined in frontmatter).
  • Apply the same {file:...} / {env:...} variable substitution pass used for opencode.json to frontmatter fields parsed from Markdown agents and commands.
Plugins

No response

OpenCode version

1.18.27

Steps to reproduce
  1. Create .opencode/agent/foo.md with YAML frontmatter and an empty body:
    ---
    mode: primary
    prompt: '{file:./prompts/foo.md}'
    ---
    
  2. Create .opencode/prompts/foo.md with system instructions (e.g., You are a helpful assistant.).
  3. Run opencode debug agent foo (or execute opencode with foo active) to inspect the resolved configuration.
Screenshot and/or share link
Image
Operating System

macOS 15.6

Terminal

Terminal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.