fix: concatenate system prompt to system[0] instead of push() to preserve agent prompts#380
Conversation
When using custom OpenCode agents (defined in ~/.config/opencode/agents/),
output.system.push() creates a second element in the system[] array.
OpenCode maps each element to a separate {role: 'system'} message,
and providers only respect the last one — which drops the agent prompt.
Fix: concatenate DCP prompt to system[0] instead of pushing a new element.
Tested: isolated A/B test confirmed push() breaks agent prompt,
concatenation preserves it.
|
I think your AI halucinated to you here, I don't think this diagnosis is accurate... Have you actually tested this? |
|
Yes, this was tested with isolated A/B methodology — not a guess. Setup: Custom agent defined in Test 1 — only hooks.js patched (system[0] += instead of push), inject.js original: Test 2 — only inject.js patched (user message instead of assistant), hooks.js original (push): Each test was a clean restart of OpenCode with only one change at a time. The agent prompt loss is 100% reproducible with The issue is that OpenCode maps each messages: [
...system.map((x) => ({ role: "system", content: x })),
...input.messages
]When DCP pushes a second element, the provider receives two system messages. The agent prompt in Happy to provide any additional details or screen recordings of the test. |

Problem
When using custom OpenCode agents (defined in
~/.config/opencode/agents/), the agent's system prompt is lost when DCP is enabled.Root cause:
createSystemPromptHandlerinhooks.tsline 95 doesoutput.system.push(renderSystemPrompt(flags)), creating a second element in thesystem[]array.OpenCode maps each
system[]element to a separate{role: "system"}message:Providers typically only respect one system message — the agent prompt in
system[0]gets dropped.Isolated A/B Test
output.system.push(dcpPrompt)(original)output.system[0] += "\n\n" + dcpPrompt(fix)The test was performed with
inject.jsin both original and patched states — only thehooks.tschange affected the outcome.Fix
Concatenate DCP prompt to
system[0]instead of pushing a new element. Falls back topush()ifsystem[]is empty (defensive).Reproduction
~/.config/opencode/agents/myagent.md