opencode-plugin-flow adds a durable planning and execution workflow to OpenCode.
It turns a goal into a tracked session, breaks that goal into features, executes one feature at a time, and requires validation and reviewer approval before work can advance.
Flow provides:
- planning with a persisted draft plan
- explicit plan approval and feature selection
- single-feature execution with validation evidence
- reviewer-gated completion for each feature
- broad final validation before session completion
- autonomous plan, run, review, and replan loops
- structured recovery metadata for retryable runtime failures
- durable session state in
.flow/session.json - readable derived docs in
.flow/docs/
flowchart TD
A[Goal] --> B[Run flow-plan]
B --> C[Draft plan saved]
C --> D{Plan approved?}
D -->|Yes| E[Run flow-run or flow-auto]
D -->|Select subset| F[Run flow-plan select]
F --> C
E --> G[Start one runnable feature]
G --> H[Implement and run validation]
H --> I[Review current result]
I -->|needs_fix| H
I -->|blocked| J[Blocked session]
I -->|approved| K[Persist feature result]
K --> L{Last required feature?}
L -->|No| E
L -->|Yes| M[Broad validation and final review]
M -->|needs_fix| H
M -->|approved| N[Completed session]
Flow injects these slash commands into OpenCode:
| Command | Purpose |
|---|---|
/flow-plan <goal> |
Create or refresh a draft plan for a goal |
/flow-plan select <feature-id...> |
Keep only the listed features in the current draft |
/flow-plan approve [feature-id...] |
Approve the current draft plan, optionally keeping only listed features |
/flow-run [feature-id] |
Execute exactly one approved feature |
/flow-auto <goal> |
Plan and execute autonomously from a new goal |
/flow-auto resume |
Resume the active autonomous session |
/flow-status |
Show the current session summary |
/flow-reset feature <id> |
Reset a feature and dependent features back to pending |
/flow-reset session |
Clear the active session |
Typical manual flow:
/flow-plan Add a workflow plugin for OpenCode- Review the proposed features
/flow-plan approve/flow-run- Repeat
/flow-rununtil complete /flow-status
Autonomous flow:
/flow-auto Add a workflow plugin for OpenCode- Let Flow plan, execute, validate, review, fix, and continue until complete or blocked
/flow-statusat any point to inspect state
Resume behavior:
/flow-autowith no argument is resume-only/flow-auto resumeis the explicit equivalent- if no active Flow session exists, Flow should stop and ask for a goal
- completed sessions are not considered active resumable sessions
- Flow should not invent a new goal from repository inspection when no session exists
flow-autois runtime-gated throughflow_auto_preparebefore planning begins
Flow is intentionally strict.
For a feature to complete successfully, the runtime requires:
- an approved plan
- exactly one active feature
- recorded validation evidence
- fully passing validation for that completion path
- a recorded reviewer decision
- an approved reviewer decision for the current scope
- a passing
featureReview
For final session completion, Flow also requires:
- broad validation for the repo, not just targeted validation
- a final reviewer decision recorded through the runtime
- a passing
finalReview
This is the main design choice in the plugin: review is not just advice in chat. It is a persisted gate in workflow state.
Retryable runtime failures can include structured recovery metadata alongside the error summary.
That metadata can include:
errorCoderesolutionHintrecoveryStageprerequisite- optional
requiredArtifact nextCommand- optional
nextRuntimeTool - optional
nextRuntimeArgs
The runtime uses this to distinguish between missing prerequisites and immediately executable actions.
Examples:
- missing reviewer approval reports a
reviewer_result_requiredprerequisite and the missing reviewer-decision artifact - missing validation scope or evidence reports
validation_rerun_required - missing final review payload reports
completion_payload_rebuild_required - failing review or validation can point directly to
flow_reset_featurewhen reset is the correct executable next step
nextCommand is always user-facing slash-command guidance. nextRuntimeTool only appears when the runtime can safely recommend an immediately executable tool action.
Flow keeps one active session per worktree.
Authoritative state:
.flow/session.json
Derived docs:
.flow/docs/index.md
.flow/docs/features/<feature-id>.md
session.json is the source of truth. The markdown docs are projections of that state for easier inspection.
The session model includes:
- goal and lifecycle status
- plan approval state
- planning context and implementation approach
- ordered features with dependency metadata
- active feature and execution history
- validation evidence
- reviewer decisions
- notes, artifacts, and timestamps
The plugin is built around a small set of responsibilities:
- A plugin
confighook injects commands and agents. - Runtime tools own all state transitions.
- Session state is stored in
.flow/session.json. - Prompted agents call those tools instead of mutating state directly.
- Derived markdown docs are rendered from saved session state.
Current injected agents:
flow-plannerflow-workerflow-autoflow-reviewerflow-control
Current runtime tools:
flow_statusflow_auto_prepareflow_plan_startflow_plan_applyflow_plan_approveflow_plan_select_featuresflow_run_startflow_run_complete_featureflow_review_record_featureflow_review_record_finalflow_reset_featureflow_reset_session
flow-planner
- reads the repo and creates a compact execution-ready plan
- does not write code
- does not write
.flowfiles directly
flow-worker
- executes exactly one approved feature
- runs validation
- iterates on fixes when review finds issues
- persists completion only through runtime tools
flow-reviewer
- reviews feature-level or final cross-feature state
- returns
approved,needs_fix, orblocked - does not write code
flow-auto
- orchestrates planning, approval, execution, validation, review, fixing, and replanning
- keeps looping until completion or a real blocker
- treats runtime contract errors, completion-gating failures, and failing validation as recovery work when they are internally solvable
- uses repo evidence first and external research when useful to choose the next repair step before resetting and rerunning blocked features
- satisfies structured recovery prerequisites before taking the next runtime action
flow-control
- handles status and reset requests only
Build the plugin:
bun install
bun run buildOpenCode should load the built entrypoint:
dist/index.js
Place that built file in an OpenCode plugin directory such as:
.opencode/plugins/
or:
~/.config/opencode/plugins/
Example:
cp dist/index.js .opencode/plugins/flow.jsFor local development you can also symlink the built file.
This repo is structured like an npm-style plugin package. After publishing, it can be added to opencode.json:
{
"plugin": ["opencode-plugin-flow"]
}Install dependencies and run the full local check:
bun install
bun run checkUseful scripts:
bun run buildbun run testbun run typecheckbun run check
Key source files:
src/index.ts: plugin entrypointsrc/config.ts: command and agent injectionsrc/tools.ts: runtime tool surfacesrc/runtime/schema.ts: session and contract schemassrc/runtime/transitions.ts: state transition rulessrc/runtime/session.ts: load and save helperssrc/runtime/render.ts: derived markdown renderingsrc/prompts/agents.ts: agent instructionssrc/prompts/commands.ts: slash command templates
OpenCode plugin tools expect args to be provided as a raw Zod shape, not a top-level schema object.
Example:
const FlowRunStartArgsShape = {
featureId: z.string().optional(),
};This plugin uses two validation layers:
- SDK-facing tool
argsstay as raw shapes for OpenCode compatibility - stricter runtime validation happens later through schemas such as
WorkerResultSchema
Runtime transition failures can also carry structured recovery metadata so agents can tell the difference between:
- a missing prerequisite
- a missing artifact
- a valid user-facing next command
- an immediately executable runtime action
The test suite currently covers:
- command and agent injection
- tool argument shape compatibility
- session creation, save, and load
- markdown doc rendering
- plan application, selection, and approval
- feature execution and reviewer gating
- blocked and replan-required outcomes
- final-review completion rules
- reset behavior
- prerequisite-aware recovery metadata and autonomous recovery behavior
Run tests with:
bun testThis project is licensed under the MIT License. See LICENSE for the full text.