Skip to content

feat: forward OpenCode agent prompts and instructions to Claude - #25

Open
karimodm wants to merge 1 commit into
openchamber:mainfrom
karimodm:feat/forward-agent-system-context
Open

karimodm wants to merge 1 commit into
openchamber:mainfrom
karimodm:feat/forward-agent-system-context

Conversation

@karimodm

Copy link
Copy Markdown

Fixes #6.

Today every claude-code/* request replaces OpenCode's system prompt with the Claude Code preset. That's the right call for OpenCode's own boilerplate, but the same system prompt also carries user configuration that nothing else delivers:

  • custom agent prompts, which define the agent (a reviewer persona, a planner's rules, multi-agent plugins' agents)
  • instructions files and AGENTS.md
  • MCP server instructions
  • the available-skills list

We noticed because a critic subagent ran with the right model, variant and permissions but none of its persona, and our instruction files never applied.

Fix: openCodeSystemContext() (src/system-context.ts) splits the OpenCode system text around its <env> block:

  • The text before the env block is the agent prompt. It's forwarded as "Agent role", unless it is OpenCode's stock base prompt (You are OpenCode…), which is skipped.
  • The env block itself is skipped; Claude Code writes its own.
  • Everything after it (instructions, MCP notes, skills) is forwarded as "OpenCode context".

Both parts are appended to the claude_code preset (systemPrompt.append), so the preset stays the base. Meta requests (title/summary) are unchanged.

It's on by default because the current behaviour silently breaks custom agents. OPENCODE_CLAUDE_FORWARD_SYSTEM_CONTEXT=0 turns it off (documented in the README). Happy to flip the default to opt-in if you'd rather keep the current behaviour for everyone.

Caveat: the split relies on OpenCode's current wording ("You are powered by the model named…" before <env>, "You are OpenCode" for the stock prompt). If OpenCode rewords these, the effect is that more text gets forwarded (the stock prompt would come through too), not that user config is lost.

We've run this locally for a day with custom subagents, instruction files and skills, and they all take effect.

Test: test/system-context-regression.ts covers the stock-agent case (base prompt and env dropped, instructions and skills kept) and the custom-agent case (persona forwarded), then goes through the proxy to check the preset append with forwarding on and with =0. On main the persona is missing and the test fails. bun test/smoke.ts and tsc --noEmit pass.

The Claude Code preset replaced OpenCode's system prompt wholesale,
which also dropped user configuration: custom agent prompts, instructions
files / AGENTS.md, MCP server instructions and the skills list. Append
those to the preset, skipping OpenCode's stock base prompt and <env>
block. OPENCODE_CLAUDE_FORWARD_SYSTEM_CONTEXT=0 restores the old
behaviour.

Fixes openchamber#6
JosueGalRe added a commit to JosueGalRe/opencode-claude that referenced this pull request Sep 22, 2026
On by default; OPENCODE_CLAUDE_FORWARD_SYSTEM_CONTEXT=0 opts out.

Upstream: openchamber#25 (fixes openchamber#6)
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.

Agent system prompts are discarded on claude-code/* with no opt-out - multi-agent plugins silently lose their agent definitions

1 participant