-
Notifications
You must be signed in to change notification settings - Fork 5
Practical Workflow Examples
Step-by-step walkthroughs for common OpenCode tasks inside VS Code. These examples show where to click, what appears in each surface, and how sessions hand off between the Agent sidebar, integrated terminal, and tree views.
- Surfaces at a glance
- Example 1: Multi-step plan → build handoff
- Example 2: Agent harness chat with editor context
- Example 3: Resume a session from the Sessions tree
- Example 4: Run on project files (batch refactor)
- Example 5: Interactive TUI for long-running work
- Example 6: Custom agent + subagent handoff
| Surface | Where | Best for |
|---|---|---|
Agent sidebar (opencode-walkthrough.agent) |
OpenCode activity bar → Agent | In-editor chat, harness context, session resume |
| MCP Servers panel → Sessions tab | Bottom panel | Browse past sessions, click to resume |
| Agents / Models trees | OpenCode activity bar | Pick agents, inspect models |
Integrated terminal (OpenCode or OpenCode Server) |
Terminal panel | TUI, opencode run, opencode serve
|
| OpenCode Agent output channel | Output panel | Harness debug log (spawn args, stream events) |
| Status bar | Bottom |
OpenCode quick actions · Agents list |
flowchart LR
subgraph sidebar [Activity Bar]
A[Agent webview]
T[Agents tree]
M[Models tree]
end
subgraph panel [Bottom Panel]
S[Sessions tree]
MCP[MCP Servers]
end
subgraph term [Terminal]
CLI[opencode TUI / run]
SRV[opencode serve]
end
A -->|spawn opencode run| CLI
A -->|auto-start| SRV
S -->|Resume Session| A
T -->|agent list| CLI
Goal: Ask OpenCode to plan a feature first, review the plan in the editor, then execute implementation — without leaving VS Code.
- OpenCode CLI installed (
opencode --versionworks in a terminal). - Auth configured (
opencode auth login). - A trusted workspace folder open.
Plan mode is an OpenCode CLI experimental feature. Map it through VS Code settings so every terminal command from the extension inherits it:
{
"opencode.experimental.planMode": true
}This sets OPENCODE_EXPERIMENTAL_PLAN_MODE=true before each sendToTerminal dispatch (see Troubleshooting if env vars do not apply).
-
Open the OpenCode activity bar.
-
Select Agent.
-
Confirm the header shows health, e.g.
OpenCode 0.x.x — ready. -
Type a planning prompt:
Plan a handoff flow: add a
UserProfilecomponent with avatar, display name, and email. List files to create, props, and test strategy. Do not edit files yet. -
Press Send (or run OpenCode: Start Agent Session from the Command Palette).
| Phase | UI |
|---|---|
| After Send | Your message appears in a user bubble; status → running
|
| While CLI works | Assistant bubble streams text; tool rows may appear as Tool: read, Tool: grep, etc. |
| On completion | Status shows Session abc12345 (first 8 chars of session id) |
| On error | Red error bubble; status → error
|
Behind the scenes the harness:
- Assembles a
<harness-context>block (workspace path, active file, selection, diagnostics, git branch). - Spawns
opencode run --format json [--attach http://127.0.0.1:4096]. - Streams JSON lines into the webview.
Open View → Output → OpenCode Agent to watch spawn args and stream parsing.
-
Read the plan in the Agent chat.
-
Send a follow-up in the same sidebar (session id is preserved):
Implement step 1 only: create
UserProfile.tsxwith the props from your plan. Keep the diff small. -
When hybrid tools run (file writes, terminal commands), VS Code may show a confirmation dialog depending on
opencode.harness.toolConfirmation(smartby default).
- New or changed files appear in the Explorer.
- Problems panel shows any new diagnostics (included in the next harness message if
opencode.harness.context.includeDiagnosticsis true).
- OpenCode: Start Interactive Session → plan in the full TUI.
- Note the session id from Sessions tree (bottom panel).
- Click the session → enter a follow-up → harness resumes with
--session <id>.
Goal: Fix the error on the line your cursor is on, using diagnostics the harness attaches automatically.
-
Open a file with a TypeScript or ESLint error.
-
Place the cursor on the offending line (optional: select the symbol).
-
Open Agent sidebar.
-
Prompt:
Explain the diagnostic at my cursor and suggest a minimal fix.
-
Press Send.
The harness appends JSON inside <harness-context> (file path, language, selection, diagnostics). File contents are off by default (opencode.harness.context.includeFileContents: false). Enable only when you need the model to see full buffer text.
If the header shows OpenCode CLI is not installed or no providers configured, fix install/auth before sending — see Troubleshooting.
Goal: Continue yesterday's agent session from the bottom panel without re-pasting context.
- Open MCP Servers panel → Sessions tab.
- Click a session row (or run OpenCode: List Sessions to refresh).
- VS Code prompts for a follow-up message.
- The harness calls
opencode run --session <id> --format jsonwith your new text + fresh harness context.
| Location | Behavior |
|---|---|
| Input box | Pre-filled or empty follow-up prompt |
| Agent sidebar | Opens if needed; new user + assistant messages append |
| Sessions tree | Same session id; title may update after CLI sync |
Empty Sessions tree? Run any prompt first (Run Inline Prompt or Start Agent Session), then click Refresh on the Sessions toolbar.
Goal: Refactor several files in one shot via the terminal (not the Agent webview).
-
OpenCode: Run on Project Files (
Ctrl+Alt+P/Cmd+Alt+P). -
Multi-select files in the quick pick.
-
Enter prompt:
Refactor these files to use async/await consistently. -
Confirm — the extension opens the integrated terminal and runs:
opencode run --file path/a.ts --file path/b.ts "Refactor these files..."(Exact flags depend on CLI version; env prefixes are injected per your
opencode.*settings.)
| Use Run on Project Files | Use Agent sidebar |
|---|---|
| Explicit file list | Active editor + workspace context |
| One-shot terminal output | Streaming chat + session resume |
| No webview needed | Tool confirmations in VS Code |
Goal: Multi-hour exploratory work with OpenCode's full TUI (MCP, agents, compaction).
- OpenCode: Start Interactive Session (or welcome link Start Interactive Session).
- Terminal opens (reuses active terminal if named
OpenCode). - Full TUI runs — use
/help, switch agents, attach MCP servers.
From the Agent sidebar, click Open TUI anytime to jump to the same terminal command.
With opencode.harness.autoStartServer: true (default), the first Agent message may also open an OpenCode Server terminal running opencode serve --hostname 127.0.0.1 --port 4096. The harness passes --attach so opencode run shares server-side session state.
Goal: Create a reviewer agent, list it in the sidebar, then invoke it from a harness prompt.
-
OpenCode: Create Agent → complete CLI wizard in terminal.
-
Open Agents tree → confirm
code-reviewer(or your name) appears. -
In Agent sidebar, prompt:
Use the code-reviewer agent to review
src/api.tsfor error handling gaps.(If your CLI supports
--agent, the harness can pass it when resuming from the Agents tree; otherwise name the agent in the prompt.) -
For background subagents (experimental):
{ "opencode.experimental.backgroundSubagents": true } -
Watch the Agent panel for tool rows and the terminal for parallel subagent output.
| Command | ID |
|---|---|
| Start Agent Session | opencode-walkthrough.startAgent |
| Open Agent Panel | opencode-walkthrough.openAgentPanel |
| Cancel Agent | opencode-walkthrough.cancelAgent |
| Resume Session | opencode-walkthrough.resumeSession |
| Run Inline Prompt | opencode-walkthrough.runInline |
| Run on Project Files | opencode-walkthrough.runOnProject |
| Start Interactive Session | opencode-walkthrough.runInteractive |
| Start Server | opencode-walkthrough.serve |
Full command catalog: Repository README.
- Building the OpenCode Agent Harness — architecture and design
- Troubleshooting — PATH, env vars, terminal shells
- OpenCode CLI docs