Skip to content

[Bug]: opencode integration dispatch fails — uses unsupported -p flag instead of run subcommand #2409

@markuswondrak

Description

@markuswondrak

Bug Description

When dispatching workflow commands via the opencode integration, OpencodeIntegration inherits build_exec_args() from MarkdownIntegration, which generates ["opencode", "-p", "/speckit.specify ..."]. The opencode CLI does not support the -p short flag — it uses --prompt (long form only) for prompt input, and the intended headless dispatch mode is opencode run [message..].

When opencode receives the unrecognized -p flag, it prints its full help text and exits — the workflow step sees exit code 0 but no actual output, causing the step to fail silently.

Steps to Reproduce

  1. Initialize a project with opencode: specify init --ai opencode
  2. Run a workflow: specify workflow run speckit --input spec="build a login page" --input integration=opencode
  3. Observe: opencode prints its CLI help text instead of executing the /speckit.specify command
  4. The workflow step fails with empty stdout/stderr and exit_code: 0 (help exits successfully)

Expected Behavior

The workflow should dispatch opencode run "/speckit.specify build a login page" which:

  • Uses the run subcommand (headless/batch mode, not interactive TUI)
  • Processes the slash-command from .opencode/command/speckit.specify.md
  • Runs to completion and exits with the appropriate exit code

Actual Behavior

The inherited build_exec_args() generates ["opencode", "-p", "/speckit.specify build a login page"]. Since -p is not a valid opencode flag, opencode prints its help text and exits — no command is executed.

Environment

  • Specify CLI Version: 0.8.3.dev0
  • AI Agent: opencode
  • Operating System: Linux x86_64
  • Python: 3.12.3

Error Output

$ specify workflow run speckit \
    --input spec="$(cat ./01_chat_mvp.md)" \
    --input integration=opencode

Running workflow: Full SDD Cycle (speckit)
Version: 1.0.0

  ▸  speckit.specify …

[opencode prints full CLI help text — same output as `opencode --help`]

Root Cause

Code location: src/specify_cli/integrations/opencode/__init__.py (21 lines)

OpencodeIntegration does NOT override build_exec_args(). It inherits from MarkdownIntegration which hardcodes -p:

# src/specify_cli/integrations/base.py, lines 833-847
class MarkdownIntegration(IntegrationBase):
    def build_exec_args(self, prompt, *, model=None, output_json=True):
        if not self.config or not self.config.get("requires_cli"):
            return None
        args = [self.key, "-p", prompt]     # ← "-p" invalid for opencode
        if model:
            args.extend(["--model", model])  # ← opencode uses "-m"
        if output_json:
            args.extend(["--output-format", "json"])  # ← not supported
        return args

Other integrations with non-standard CLI dispatch DO override build_exec_args() — e.g., CopilotIntegration (copilot/__init__.py line 127). OpencodeIntegration should do the same.

Proposed Fix

Override build_exec_args() in OpencodeIntegration:

def build_exec_args(self, prompt, *, model=None, output_json=True):
    """Build CLI args for opencode headless dispatch via ``run`` subcommand."""
    args = [self.key, "run", prompt]
    if model:
        args.extend(["-m", model])
    return args

Key changes:

  1. Replace -p flag with run subcommand (opencode headless/batch mode)
  2. Use -m instead of --model (matches opencode actual flag)
  3. Drop --output-format json (not supported by opencode)

Additional Context

The "auto" integration resolution (which reads .specify/integration.json) works correctly — when a project is initialized with --ai opencode, the engine correctly resolves the integration key to "opencode". The bug is solely in the CLI argument construction.

A full forensic analysis with evidence chain is documented in the repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions