Skip to main content

OpenCode

Execute prompts via the OpenCode SDK. Supports OpenCode Zen models and 75+ LLM providers including Big Pickle (free stealth), GPT-5.2, Claude Sonnet 4.5, Gemini 3 Pro, and more.
import { OpenCode } from "smithers-orchestrator"
<OpenCode model="opencode/big-pickle">
  Analyze this codebase and suggest improvements
</OpenCode>

Basic Usage

// Use Big Pickle (free stealth model)
<OpenCode model="opencode/big-pickle">
  Analyze this codebase and suggest improvements
</OpenCode>

// Use GPT-5.2 via OpenCode Zen
<OpenCode model="opencode/gpt-5.2-codex" agent="coder">
  Implement the feature described in the task
</OpenCode>

// Use Claude directly
<OpenCode model="anthropic/claude-sonnet-4-5">
  Review this pull request
</OpenCode>

Props

Model Configuration

model
OpenCodeModel
default:"opencode default"
OpenCode model to use in format “provider/model”.
<OpenCode model="opencode/big-pickle">Free stealth model</OpenCode>
<OpenCode model="opencode/gpt-5.2-codex">GPT-5.2 via Zen</OpenCode>
<OpenCode model="anthropic/claude-sonnet-4-5">Claude direct</OpenCode>
agent
'default' | 'planner' | 'coder' | string
Agent to use for this session. Corresponds to .opencode/agents/{name}.md.
<OpenCode agent="coder">Implementation task</OpenCode>
<OpenCode agent="planner">Planning task</OpenCode>
maxTurns
number
Maximum number of agentic turns (tool use cycles).
<OpenCode maxTurns={10}>Limited iteration task</OpenCode>
maxTokens
number
Maximum tokens for the response.
<OpenCode maxTokens={4096}>Task with token limit</OpenCode>
timeout
number
Timeout in milliseconds.
<OpenCode timeout={60000}>Task with 1 minute timeout</OpenCode>

System Prompt

systemPrompt
string
Custom system prompt override.
<OpenCode systemPrompt="You are a security expert. Focus on vulnerabilities.">
  Review this code.
</OpenCode>

Permission & Tool Configuration

permissionMode
'auto' | 'ask' | 'deny'
default:"ask"
Permission handling for tool calls.
  • auto: auto-approve based on opencode.json permissions
  • ask: prompt for permission (default)
  • deny: deny all permission requests
<OpenCode permissionMode="auto">Auto-approve tools</OpenCode>
toolConfig
Record<string, boolean>
Tool configuration overrides. Map of tool name to enabled/disabled.
<OpenCode toolConfig={{ bash: true, write: false }}>
  Allow bash, disable write
</OpenCode>

Execution Configuration

cwd
string
Working directory for the session.
<OpenCode cwd="/path/to/project">
  Run in specific directory.
</OpenCode>
resumeSession
string
Continue from an existing session ID.
<OpenCode resumeSession="session-abc123">Continue this session.</OpenCode>
middleware
SmithersMiddleware[]
Middleware applied to this OpenCode execution. Provider middleware are prepended automatically.
<OpenCode middleware={[loggingMiddleware, rateLimitMiddleware]}>
  Task with middleware.
</OpenCode>
tailLogCount
number
default:"10"
Number of tail log entries to display during execution.
tailLogLines
number
default:"10"
Number of lines to show per tail log entry.

Server Configuration

hostname
string
default:"127.0.0.1"
OpenCode server hostname.
port
number
default:"4096"
OpenCode server port.
serverTimeout
number
default:"10000"
Server startup timeout in milliseconds.

Structured Output

schema
ZodSchema
Zod schema for structured output validation.
const ResultSchema = z.object({
  summary: z.string(),
  issues: z.array(z.string()),
});

<OpenCode schema={ResultSchema}>
  Return structured analysis.
</OpenCode>
schemaRetries
number
default:"2"
Maximum retries for schema validation failures.
validate
(result: AgentResult) => boolean | Promise<boolean>
Custom validation function.
<OpenCode validate={(result) => result.output.includes("DONE")}>
  Must include completion marker.
</OpenCode>
retryOnValidationFailure
boolean
default:"false"
Retry if validation fails.
maxRetries
number
Maximum retry attempts.

Callbacks

onFinished
(result: AgentResult) => void
Called when agent finishes successfully.
<OpenCode onFinished={(r) => console.log(r.output)}>Task</OpenCode>
onError
(error: Error) => void
Called when agent encounters an error.
onToolCall
(tool: string, input: any) => void
Called when agent makes a tool call.
onProgress
(message: string) => void
Called for progress updates.

Reporting

reportingEnabled
boolean
default:"true"
Enable database reporting for this agent.
recordStreamEvents
boolean
default:"true"
Record stream events to the database when reporting is enabled.

Models

OpenCode supports 75+ LLM providers. Common models:
ModelDescription
opencode/big-pickleFree stealth model
opencode/gpt-5.2GPT-5.2 via OpenCode Zen
opencode/gpt-5.2-codexGPT-5.2 Codex variant
opencode/gpt-5.1-codexGPT-5.1 Codex
opencode/claude-sonnet-4-5Claude Sonnet 4.5 via Zen
opencode/claude-opus-4-5Claude Opus 4.5 via Zen
opencode/gemini-3-proGemini 3 Pro via Zen
opencode/grok-codeGrok Code
opencode/kimi-k2Kimi K2
opencode/qwen3-coderQwen3 Coder
anthropic/claude-sonnet-4-20250514Claude direct via Anthropic
anthropic/claude-opus-4-20250514Claude Opus direct
openai/gpt-5.2GPT-5.2 direct via OpenAI
google/gemini-3-proGemini 3 Pro direct

AgentResult Type

interface AgentResult<T = any> {
  output: string;              // Raw text output
  structured?: T;              // Validated structured output
  tokensUsed: {
    input: number;
    output: number;
  };
  turnsUsed: number;
  stopReason: 'completed' | 'stop_condition' | 'error' | 'cancelled';
  durationMs: number;
  exitCode?: number;
  sessionId?: string;
}

Structured Output with Zod

import { z } from 'zod';

const AnalysisSchema = z.object({
  summary: z.string(),
  issues: z.array(z.object({
    severity: z.enum(['low', 'medium', 'high', 'critical']),
    file: z.string(),
    description: z.string(),
  })),
});

<OpenCode
  model="opencode/gpt-5.2-codex"
  schema={AnalysisSchema}
  onFinished={(result) => {
    for (const issue of result.structured.issues) {
      console.log(`[${issue.severity}] ${issue.file}: ${issue.description}`);
    }
  }}
>
  Analyze this codebase for security issues.
</OpenCode>

Agent Types

Use different agents for specialized tasks:
// Default agent
<OpenCode model="opencode/big-pickle">
  General task
</OpenCode>

// Coder agent - optimized for implementation
<OpenCode model="opencode/gpt-5.2-codex" agent="coder">
  Implement the feature
</OpenCode>

// Planner agent - optimized for planning
<OpenCode model="opencode/big-pickle" agent="planner">
  Create a plan for the migration
</OpenCode>

Error Handling

<OpenCode
  model="opencode/big-pickle"
  maxRetries={3}
  retryOnValidationFailure
  onError={(err) => console.error("Failed:", err.message)}
  onFinished={(r) => console.log("Success:", r.output)}
>
  Complete the task.
</OpenCode>