# Class OpenCodeCliAdapter

OpenCode CLI adapter using subprocess transport. Executes: opencode run --format json ""

Probes available models on first use and omits --model flag when the requested model isn't available (#1402).

#### Hierarchy (View Summary)

- SubprocessCliAdapter
  - OpenCodeCliAdapter

- Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:139

##### Index

### Constructors

constructor

### Properties

name
parser
transientRetry
logger
capacityTracker
initialized
lastHealthCheck?
cachedVersion?
transport

### Accessors

capabilities

### Methods

getModelInfo
initialize
getCommand
listModels
initCapacityTracker
execute
healthCheck
getVersion
getCapacity
recordUsage
parseVersion
checkVersionCompatibility
getVersionMessage
createError
normalizeResponse
delay
executeTask
dispose

## Constructors

### constructor

- new OpenCodeCliAdapter(options?: BaseAdapterOptions): OpenCodeCliAdapter

  #### Parameters

  - `Optional` options: BaseAdapterOptions

  #### Returns OpenCodeCliAdapter

  Overrides SubprocessCliAdapter.constructor

  - Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:149

## Properties

### `Readonly` name

name: "claude" | "gemini" | "codex" | "opencode" = 'opencode'

CLI name

Overrides SubprocessCliAdapter.name

- Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:140

### `Protected` `Readonly` parser

parser: ICliResponseParser = ...

Overrides SubprocessCliAdapter.parser

- Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:141

### `Protected` `Readonly` transientRetry

transientRetry: TransientRetryConfig = ...

Enable transient-error retry for OpenCode (#1456).

Overrides SubprocessCliAdapter.transientRetry

- Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:144

### `Protected` `Readonly` logger

logger: ILogger

Inherited from SubprocessCliAdapter.logger

- Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:75

### `Protected` capacityTracker

capacityTracker: CapacityTracker | null = null

Inherited from SubprocessCliAdapter.capacityTracker

- Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:76

### `Protected` initialized

initialized: boolean = false

Inherited from SubprocessCliAdapter.initialized

- Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:77

### `Protected` `Optional` lastHealthCheck

lastHealthCheck?: HealthStatus

Inherited from SubprocessCliAdapter.lastHealthCheck

- Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:78

### `Protected` `Optional` cachedVersion

cachedVersion?: string

Inherited from SubprocessCliAdapter.cachedVersion

- Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:79

### `Readonly` transport

transport: CliTransport = 'subprocess'

Transport type

Inherited from SubprocessCliAdapter.transport

- Defined in packages/nexus-agents/src/cli-adapters/subprocess-adapter.ts:236

## Accessors

### capabilities

- get capabilities(): CliCapabilityProfile

  Gets the capability profile for this CLI.

  #### Returns CliCapabilityProfile

  Inherited from SubprocessCliAdapter.capabilities

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:96

## Methods

### getModelInfo

- getModelInfo(): CliModelInfo

  Gets OpenCode model information from canonical registry.

  #### Returns CliModelInfo

  Overrides SubprocessCliAdapter.getModelInfo

  - Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:157

### initialize

- initialize(): Promise<void>

  Initializes the adapter — probes available models. Warns if Anthropic provider is configured (#1429 — API key boundaries).

  #### Returns Promise<void>

  Overrides SubprocessCliAdapter.initialize

  - Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:175

### `Protected` getCommand

- getCommand(task: CliTask): CommandConfig

  Gets CLI command and arguments for execution. Uses `opencode run` with JSON format for stable parsing. Omits --model when the requested model isn't available (#1402).

  #### Parameters

  - task: CliTask

  #### Returns CommandConfig

  Overrides SubprocessCliAdapter.getCommand

  - Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:222

### listModels

- listModels(): Promise<readonly CliModelInfo[]>

  (#2540) Lists models the local OpenCode installation can route to. Wraps the existing `probeAvailableModels()` (cached for the process lifetime — see `cachedModels` at the top of this file) and reshapes the result into the CliModelInfo schema. Splits `provider/model` ids when present.

  #### Returns Promise<readonly CliModelInfo[]>

  - Defined in packages/nexus-agents/src/cli-adapters/adapters/opencode-adapter.ts:247

### `Protected` initCapacityTracker

- initCapacityTracker(): void

  Initializes the capacity tracker. Called by subclasses after name is set.

  #### Returns void

  Inherited from SubprocessCliAdapter.initCapacityTracker

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:89

### execute

- execute(
  task: CliTask,
  options?: CliExecutionOptions,
  ): Promise<Result<CliResponse, CliError>>

  Executes a task with error handling and retries.

  Timeout priority (highest to lowest):

  1. options.timeoutMs - explicit execution option
  2. task.timeoutMs - task-level setting
  3. getTimeoutForTaskAuto() - computed from task complexity and CLI

  #### Parameters

  - task: CliTask
  - `Optional` options: CliExecutionOptions

  #### Returns Promise<Result<CliResponse, CliError>>

  Inherited from SubprocessCliAdapter.execute

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:135

### healthCheck

- healthCheck(): Promise<HealthStatus>

  Performs a health check.

  #### Returns Promise<HealthStatus>

  Inherited from SubprocessCliAdapter.healthCheck

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:200

### getVersion

- getVersion(): Promise<string>

  Gets CLI version.

  #### Returns Promise<string>

  Inherited from SubprocessCliAdapter.getVersion

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:230

### getCapacity

- getCapacity(): Promise<CapacityStatus>

  Gets current capacity status based on tracked usage. Uses usage-based tracking since CLI subprocess execution doesn't expose HTTP rate limit headers.

  #### Returns Promise<CapacityStatus>

  #### See

  Issue #456 - Real API rate limit tracking

  Inherited from SubprocessCliAdapter.getCapacity

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:256

### `Protected` recordUsage

- recordUsage(response: CliResponse): void

  Records usage from a response for capacity tracking.

  #### Parameters

  - response: CliResponse

  #### Returns void

  Inherited from SubprocessCliAdapter.recordUsage

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:281

### `Protected` parseVersion

- parseVersion(output: string): string

  Parses version from CLI output.

  #### Parameters

  - output: string

  #### Returns string

  Inherited from SubprocessCliAdapter.parseVersion

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:290

### `Protected` checkVersionCompatibility

- checkVersionCompatibility(version: string): VersionStatus

  Checks version compatibility.

  #### Parameters

  - version: string

  #### Returns VersionStatus

  Inherited from SubprocessCliAdapter.checkVersionCompatibility

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:302

### `Protected` getVersionMessage

- getVersionMessage(status: VersionStatus, version: string): string | undefined

  Gets version status message.

  #### Parameters

  - status: VersionStatus
  - version: string

  #### Returns string | undefined

  Inherited from SubprocessCliAdapter.getVersionMessage

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:331

### `Protected` createError

- createError(code: CliErrorCode, message: string, cause?: Error): CliError

  Creates a CLI error.

  #### Parameters

  - code: CliErrorCode
  - message: string
  - `Optional` cause: Error

  #### Returns CliError

  Inherited from SubprocessCliAdapter.createError

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:349

### `Protected` normalizeResponse

- normalizeResponse(
  text: string,
  usage?: CliTokenUsage,
  extra?: Partial<CliResponse>,
  ): CliResponse

  Normalizes CLI response to common format.

  #### Parameters

  - text: string
  - `Optional` usage: CliTokenUsage
  - `Optional` extra: Partial<CliResponse>

  #### Returns CliResponse

  Inherited from SubprocessCliAdapter.normalizeResponse

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:364

### `Protected` delay

- delay(ms: number): Promise<void>

  Delays for the specified milliseconds.

  #### Parameters

  - ms: number

  #### Returns Promise<void>

  Inherited from SubprocessCliAdapter.delay

  - Defined in packages/nexus-agents/src/cli-adapters/base-adapter.ts:379

### executeTask

- executeTask(
  task: CliTask,
  options: Required<CliExecutionOptions>,
  ): Promise<Result<CliResponse, CliError>>

  Executes a task via subprocess, with optional transient-error retry. When `transientRetry.enabled` is true, transient errors (timeout, rate_limit, connection, parse) are retried with exponential backoff (500ms, 1000ms). Parse errors get max 1 retry (#1533); others get 2.

  #### Parameters

  - task: CliTask
  - options: Required<CliExecutionOptions>

  #### Returns Promise<Result<CliResponse, CliError>>

  Inherited from SubprocessCliAdapter.executeTask

  - Defined in packages/nexus-agents/src/cli-adapters/subprocess-adapter.ts:255

### dispose

- dispose(): Promise<void>

  Disposes the adapter (no-op for subprocess).

  #### Returns Promise<void>

  Inherited from SubprocessCliAdapter.dispose

  - Defined in packages/nexus-agents/src/cli-adapters/subprocess-adapter.ts:608