Files
opencode-primer/docs/workflows.md
T
Wesam AbousaidandClaude Opus 4.8 29a69a35b0 docs: refresh for OpenCode v1.16.2 and fix correctness bugs
Update the guide to the current release (v1.16.2, 2026-06-05), verified
against opencode.ai/docs and github.com/anomalyco/opencode.

Correctness fixes:
- Plugins: tool.execute.before/after and shell.env are top-level hooks
  with an (input, output) signature, not event.type values. Rewrite both
  shipped example plugins plus the docs/migration examples so they fire.
- Permissions: bash glob maps resolve last-matching-rule-wins (catch-all
  "*" first), not most-specific-wins. Fix prose, reorder examples, and fix
  the shipped opencode.json (rm -rf* deny was shadowed by a later rm *).
- Drop non-existent permission keys repo_clone/repo_overview (15 keys, not
  17); fix steps (integer), deprecate maxSteps/tools, move reasoningEffort
  into model options; fix the `mise` install command.

Currency updates:
- v1.15.4 -> v1.16.2; add v1.16 highlights and a changelog section.
- Refresh OpenCode Zen lineup/pricing (Claude Opus 4.8, gpt-5.4,
  gemini-3.5-flash, qwen3.7, grok-build-0.1; correct free-tier IDs).
- Add `opencode mcp add`, run --replay, extra skill paths, shift+tab, and
  native GitHub commands; correct the specialist-prompt count; bump dates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-08 19:00:39 +02:00

7.3 KiB

Workflows — Real-World Recipes

Glue patterns that combine commands, agents, skills, and MCP. Use them as inspiration or copy them whole.

1. Test-Driven feature development

Goal: implement a feature with tests written first and reviewed in plan mode.

[plan]  > write failing tests for a `slugify` function with these specs:
        - handles unicode (café → cafe)
        - collapses spaces (Hello World → hello-world)
        - strips trailing punctuation
[build] > <Tab>
[build] > run the failing tests to confirm they fail
[build] > implement slugify so the tests pass
[build] > /review @src/util/slugify.ts
[build] > /pr

What's happening:

  • plan writes tests without touching code (edits default to ask in plan agent — easier than expected).
  • build runs the tests and implements.
  • /review custom command surfaces any issues before PR.
  • /pr opens the PR with a generated title and summary.

2. Bug investigation with subagents

Goal: isolate context-heavy research from your main session.

> a user reports the payment webhook is being processed twice
> @explore find every code path that handles the payment webhook
> @scout what does Stripe's docs say about webhook idempotency (latest)?

(based on subagent reports)

[plan]  > given the findings, what's the most likely root cause and how should
          we fix it?
[build] > implement the fix
[build] > add an integration test that exercises the duplicate-delivery path
[build] > /test
[build] > /pr

@explore and @scout run in child sessions — separate from your main session. Their long file reads and search output don't bloat the parent conversation. Navigate between parent and children with the session-child keybinds.

3. Multi-agent review

Goal: get two perspectives on the same change.

[build] > implement the OAuth token refresh path in src/auth/refresh.ts
[build] > @code-reviewer review the changes in src/auth/refresh.ts
[build] > @security-auditor audit src/auth/refresh.ts for token-handling vulns
[build] > address the high-severity findings, then re-run @code-reviewer to verify

Two specialized subagents from .opencode/agents/ give you independent review perspectives. Run them sequentially or in parallel — your call.

4. Cross-repo research with MCP

Goal: find how an idiom is used across GitHub before adopting it.

Configure grep MCP server in opencode.json:

{
  "mcp": {
    "gh_grep": {
      "type": "remote",
      "url": "https://mcp.grep.app"
    }
  }
}

Then:

use gh_grep to search for "useTransition" usage in React 19 codebases on GitHub
look for the 3 most common patterns and summarize when each is used

OpenCode reads the search results through MCP and produces a written summary grounded in real code.

5. Long-running migration plan

Goal: walk a multi-step migration from a fresh plan to a tracked rollout.

[plan]  > Read AGENTS.md and the architecture doc.
          Then propose a migration plan to move from REST to GraphQL.
          Break the plan into atomic, independently-mergeable PRs.
          Output a checklist.
[plan]  > save the plan as docs/migration-graphql.md
[build] > <Tab>
[build] > start on phase 1 of docs/migration-graphql.md — add the GraphQL server
          skeleton. Use the /tdd workflow for each new resolver.

Combine that with the git-release skill so each phase ends with a clean tagged release:

> we're about to merge phase 1 — draft release notes

The agent picks up the git-release skill from the description match and walks through release prep without explicit invocation.

6. CI integration — headless OpenCode in a workflow

Goal: run OpenCode on every PR to audit changes. The example below uses GitHub Actions, but the same pattern works on GitLab CI, Buildkite, CircleCI, Jenkins, or anything else that can run a shell — OpenCode is just a CLI you curl | bash and then invoke.

.github/workflows/opencode-review.yml:

name: OpenCode review
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0
      - run: curl -fsSL https://opencode.ai/install | bash
      - run: |
          opencode run --agent plan --format json \
            "Review the diff between origin/main and HEAD. Surface security and
             correctness issues only. Output JSON with {severity,file,line,issue,fix}." \
            > review.json
        env:
          OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
      - run: gh pr comment ${{ github.event.pull_request.number }} --body-file review.json
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Equivalent shape on GitLab CI:

opencode-review:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  script:
    - curl -fsSL https://opencode.ai/install | bash
    - export PATH="$HOME/.local/bin:$PATH"
    - opencode run --agent plan --format json "Review the diff..." > review.json
    - 'curl -X POST -H "PRIVATE-TOKEN: $CI_TOKEN" --data-urlencode "body=$(cat review.json)" "$CI_API_V4_URL/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID/notes"'
  variables:
    OPENCODE_API_KEY: $OPENCODE_API_KEY

Same idea on Buildkite, CircleCI, Jenkins — install the CLI, set the env var, run a prompt, post the result wherever you post things.

--dangerously-skip-permissions is available for fully unattended runs — use it with care.

🔧 Native GitHub path. Beyond the raw curl | bash recipe, OpenCode ships first-class GitHub commands: opencode github install wires up the GitHub App and workflow so /opencode (or /oc) mentions trigger the agent on issues and PRs, and opencode pr <number> checks out a PR branch locally and opens a session. As of v1.16, the GitHub extension refuses to commit without an existing git author identity — in Actions the runner already configures user.name/user.email, so the comment-only recipes above are unaffected.

7. Visual iteration

Goal: implement UI to match a mock.

[plan]  > [drag screenshot of the mock into the TUI]
        > what HTML/CSS structure best matches this layout?
[build] > <Tab>
[build] > implement it under src/components/Dashboard/.
        > take a screenshot of the result with the playwright MCP server
        > compare the new screenshot to the mock and refine

Two-three iteration rounds usually produces a close visual match. Multimodal models (opencode/gemini-3.1-pro, opencode/claude-sonnet-4-6) handle the comparison well.

Cross-cutting tips

  • Always commit .opencode/ and AGENTS.md. Your workflows become reproducible across teammates.
  • Use /compact aggressively for long sessions — the summary preserves intent at a fraction of the tokens.
  • Use subagents for read-heavy work. Your main session shouldn't carry 50KB of grep output it'll never reference again.
  • Pick a cheap model for explore and scout subagents. They do dumb (but voluminous) work.
  • Audit opencode stats weekly. Surprises in cost almost always trace to one overactive agent or MCP server.

Last reviewed: 2026-06-08 · Canonical source: opencode.ai/docs.