# Class LittleGhost::Harnesses::OpenCode

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Harnesses/OpenCode.html

Runs OpenCode with `opencode run --format json --agent build`.

In `:isolated` mode every tool permission is granted without
prompting and the provider's API key is the placeholder. In
`:native_guards` mode OpenCode may read and edit files in the
working directory, every other permission, including shell commands, web
access, and directories outside the working directory, is denied, and OpenCode
authenticates from the inherited environment. Project configuration in the
working directory is ignored, automatic updates and sharing are disabled, the
harness adds only the request's `mcp_servers`, and OpenCode's XDG directories
live under `home`. OpenCode merges this configuration over its global
configuration, so MCP servers or other settings in a persistent home still
apply.

`defaults` accepts:

`:provider`
:   OpenCode provider identifier, such as `"openrouter"`. Requests
    name models as `provider/model`.

`:base_url`
:   Base URL for that provider, for example a Network::Facade address.

`:api_key`
:   Placeholder API key for that provider in `:isolated` mode. A
    gateway replaces it.

`:model`
:   Model used when the request does not name one.

`:config`
:   Additional OpenCode configuration merged into the generated configuration.

OpenCode has no reasoning effort option, so it ignores a request's `effort`.

OpenCode reports cost and token usage after each step, so #run stops it when
cost exceeds `budget_usd`. Each finished step counts toward `max_turns`.

## Inheritance

`LittleGhost::Harnesses::OpenCode < LittleGhost::Harnesses::Base`

## Instance methods

<a id="method-i-command"></a>
### `#command`

```ruby
#command(request)
```

Returns the OpenCode command line for `request`.

<a id="method-i-environment"></a>
### `#environment`

```ruby
#environment(request)
```

Returns OpenCode's permission, configuration, and directory settings.

<a id="method-i-parse_line"></a>
### `#parse_line`

```ruby
#parse_line(line, state)
```

Parses one `run --format json` event.
