Skip to content

Support OpenCode --agent passthrough for sub-agent routing per workflow #355

@cameronmpalmer

Description

@cameronmpalmer

Problem

OpenCode supports named agents via opencode run --agent <name>, allowing users to define agents with different system prompts and permission profiles. For example:

  • Planner agent: read-only analysis (edit: ask, bash: ask), system prompt instructs "never edit files"
  • Implementer agent: full editing (edit: allow, bash: allow), system prompt instructs writing production code

This maps perfectly to roborev's review/fix workflow split — use a conservative read-only agent for reviews, and a capable editing agent for fixes.

However, roborev's OpenCode integration invokes:

opencode run --format json [--model MODEL] [prompt]

There is no mechanism to pass --agent <name> through to the OpenCode CLI. This means roborev always gets whichever agent OpenCode defaults to, regardless of whether the job is a review or a fix.

Why this matters

In non-interactive mode (opencode run --format json), OpenCode auto-approves permission prompts — so edit: ask becomes effectively allow. But the system prompt still governs behavior. A Planner agent whose instructions say "never edit files" will refuse to make changes even when permissions allow it.

This creates a deadlock for the fix workflow:

  • The default agent (Planner) won't edit files due to its system prompt
  • The agent that can edit (Implementer) can't be selected by roborev

The workaround today is to use a different top-level agent for fixes (e.g., fix_agent = "claude-code"), which defeats the purpose of having OpenCode's agent system.

Proposed solutions

Any of these would resolve the issue (in rough order of preference):

1. Per-workflow OpenCode agent config keys

# .roborev.toml or global config
opencode_agent = "implementer"              # default for all opencode workflows
review_opencode_agent = "planner"           # override for reviews
fix_opencode_agent = "implementer"          # override for fixes

roborev would then invoke opencode run --agent <name> --format json ....

2. Generic per-agent extra args

A more general mechanism that works for any agent:

# Extra CLI args appended when invoking a specific agent
[agent_args]
opencode = "--agent implementer"

# Or per-workflow
[review_agent_args]
opencode = "--agent planner"

[fix_agent_args]
opencode = "--agent implementer"

3. opencode_cmd config key

Similar to the existing claude_code_cmd, codex_cmd, and cursor_cmd keys — allow overriding the command used to invoke OpenCode:

opencode_cmd = "/path/to/wrapper-script"

This is the least ergonomic option but would unblock the use case immediately.

Environment

  • roborev v0.37.0
  • OpenCode (latest, installed via opencode-ai npm package)
  • OpenCode agents defined in ~/.config/opencode/agent/ with distinct system prompts and permissions

Metadata

Metadata

Assignees

No one assigned

    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