Skip to main content

OpenCode Adapter

The opencode_local adapter runs OpenCode CLI on the host machine as a SLAW agent, supporting multi-provider model routing and resuming sessions across Heartbeats.

Type key: opencode_local

Prerequisites

  • OpenCode CLI installed via the official installer:
curl -fsSL https://opencode.ai/install | bash
  • API credentials for your chosen provider set in the agent's env config (for example OPENAI_API_KEY for OpenAI models, ANTHROPIC_API_KEY for Anthropic models)

Configuration

Set adapterType: opencode_local on the agent and provide the config below.

Config fields

FieldTypeDefaultDescription
cwdstringAbsolute working directory; created if missing
instructionsFilePathstringAbsolute path to a markdown file prepended to the run prompt
modelstringrequiredModel in provider/model format (see Models)
variantstringProvider-specific reasoning variant: minimal, low, medium, high, xhigh, or max; passed as --variant
dangerouslySkipPermissionsbooleantrueInject a runtime config that allows external_directory access without interactive prompts
promptTemplatestringTemplate for the run prompt
commandstringopencodeOverride the OpenCode binary path
extraArgsstring[]Additional CLI arguments
envobjectEnvironment variables injected into the agent process
timeoutSecnumber0Run timeout in seconds
graceSecnumber15SIGTERM grace period

Models

OpenCode uses provider/model format. Common choices:

Model IDNotes
openai/gpt-5.2-codexDefault
openai/gpt-5.4Latest GPT
openai/gpt-5.2Standard GPT
openai/gpt-5.1-codex-maxMax Codex
openai/gpt-5.1-codex-miniBudget lane (cheap profile)
anthropic/claude-sonnet-4-6Claude Sonnet via OpenCode
anthropic/claude-opus-4-8Claude Opus via OpenCode

Run opencode models to list all available models for your configured providers.

Minimal example

{
"adapterType": "opencode_local",
"adapterConfig": {
"cwd": "/home/agent/workspace",
"model": "openai/gpt-5.2-codex",
"dangerouslySkipPermissions": true,
"timeoutSec": 0,
"graceSec": 15
}
}

Session behaviour

SLAW stores the session ID and cwd after each run. On the next Heartbeat, OpenCode resumes the prior session with --session when the stored cwd matches the current working directory.

Notes

  • model is required for opencode_local — there is no implicit default that survives across model updates.
  • Runs are executed as: opencode run --format json …
  • SLAW sets OPENCODE_DISABLE_PROJECT_CONFIG=true to prevent OpenCode from writing an opencode.json into the project working directory. Model selection is passed via the --model CLI flag instead.
  • When dangerouslySkipPermissions is enabled, SLAW injects a temporary runtime config with permission.external_directory=allow so headless runs do not stall on approval prompts.
  • When SLAW provisions a workspace or runtime, it injects SLAW_WORKSPACE_* and SLAW_RUNTIME_* environment variables.

Next steps