Skip to content

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

Description

@dnielistvn

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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