Skip to content

feat(opencode): support custom system prompt per model#18178

Open
mjdouglas wants to merge 2 commits intoanomalyco:devfrom
mjdouglas:feat/custom-model-prompt
Open

feat(opencode): support custom system prompt per model#18178
mjdouglas wants to merge 2 commits intoanomalyco:devfrom
mjdouglas:feat/custom-model-prompt

Conversation

@mjdouglas
Copy link

@mjdouglas mjdouglas commented Mar 19, 2026

Issue for this PR

Closes #18177

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Custom models configured in opencode.json fall back to a generic system prompt because SystemPrompt.provider() only matches known model families (claude, gemini, gpt, etc.). The agent-level prompt field doesn't solve this because agents and models are orthogonal — a model may need specific instructions regardless of which agent uses it.

This adds a prompt field to the model config. When set, it's used as the system prompt instead of the default model-family matching. Supports inline strings or file references via the existing {file:path} config substitution:

{
  "provider": {
    "my-provider": {
      "models": {
        "my-model": {
          "prompt": "You are a custom coding assistant."
        }
      }
    }
  }
}
{
  "provider": {
    "my-provider": {
      "models": {
        "my-model": {
          "prompt": "{file:./prompts/my-model.md}"
        }
      }
    }
  }
}

How did you verify your code works?

bun test test/session/system.test.ts test/provider/provider.test.ts — 79 tests pass, covering inline prompts, priority over model ID matching, fallback behavior, and config plumbing.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 19, 2026
@mjdouglas mjdouglas force-pushed the feat/custom-model-prompt branch from 52b4772 to a541197 Compare March 19, 2026 02:23
@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 19, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@mjdouglas mjdouglas force-pushed the feat/custom-model-prompt branch 3 times, most recently from ae053c9 to afa062d Compare March 19, 2026 03:16
Allow custom models to define their own system prompt via the `prompt`
field in provider model config, overriding the default model-family
matching logic in SystemPrompt.provider().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mjdouglas mjdouglas force-pushed the feat/custom-model-prompt branch from afa062d to 13e1f33 Compare March 19, 2026 12:44
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.

[FEATURE]: Support custom system prompt per model in config

1 participant