> ## Documentation Index
> Fetch the complete documentation index at: https://arize-ax.mintlify.site/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCode

> Trace OpenCode terminal coding sessions, model calls, and tool usage in Arize AX using the Arize Coding Harness Tracing.

> Trace OpenCode terminal coding sessions, model calls, and tool usage with Arize AX for full observability.

[OpenCode](https://opencode.ai/) is an open-source AI coding agent built for the terminal. The [Arize Coding Harness Tracing](https://github.com/Arize-ai/coding-harness-tracing) instruments OpenCode sessions with an in-process plugin and exports [OpenInference](https://github.com/Arize-ai/openinference) spans to Arize AX. Each turn is captured as a trace, with nested spans for the model call and every tool invocation.

## Launch Arize AX

To get started, sign up for a free [Arize AX account](https://app.arize.com/auth/join) and get your Space ID and API Key:

1. Log in at [app.arize.com](https://app.arize.com)
2. Click **Settings** and copy the **Space ID**
3. Open the **API Keys** tab and create or copy an API key

## Install

### Curl installer

**macOS / Linux:**

```bash theme={null}
curl -sSL https://raw.githubusercontent.com/Arize-ai/coding-harness-tracing/main/install.sh | bash -s -- opencode
```

**Windows (PowerShell):**

```powershell theme={null}
iwr -useb https://raw.githubusercontent.com/Arize-ai/coding-harness-tracing/main/install.bat -OutFile $env:TEMP\install.bat
& $env:TEMP\install.bat opencode
```

### Local clone

```bash theme={null}
git clone https://github.com/Arize-ai/coding-harness-tracing.git
cd coding-harness-tracing
./install.sh opencode      # macOS / Linux
install.bat opencode       # Windows
```

The installer prompts for your Arize AX credentials and project name, writes them to `~/.arize/harness/config.json`, and copies the tracing plugin to `~/.config/opencode/plugin/arize-tracing.ts`. OpenCode auto-discovers plugins from both the `plugin/` and `plugins/` directories under `~/.config/opencode/`, so no `opencode.json` edit is required.

## Configuration

Credentials live in `~/.arize/harness/config.json`. Environment variables override values in `config.json` and can be set in your shell profile so they apply to every OpenCode session.

```bash theme={null}
export ARIZE_API_KEY="<your-api-key>"
export ARIZE_SPACE_ID="<your-space-id>"
export ARIZE_PROJECT_NAME="opencode"
export ARIZE_TRACE_ENABLED="true"
```

<Callout type="warning">
  If `ARIZE_TRACE_ENABLED=false` is set in your shell environment — for example, inherited from another harness's configuration — tracing is silently disabled. Set `ARIZE_TRACE_ENABLED=true` before launching OpenCode, or unset the variable to fall back to the default of `true`.
</Callout>

### Redaction controls

Each `ARIZE_LOG_*` flag accepts `"true"` or `"false"` and defaults to `"true"`. Set to `"false"` to opt out per category:

```bash theme={null}
export ARIZE_LOG_PROMPTS="false"
export ARIZE_LOG_TOOL_DETAILS="false"
export ARIZE_LOG_TOOL_CONTENT="false"
```

| Flag                     | Redacts                                 |
| :----------------------- | :-------------------------------------- |
| `ARIZE_LOG_PROMPTS`      | User prompt and assistant response text |
| `ARIZE_LOG_TOOL_DETAILS` | Tool names and arguments                |
| `ARIZE_LOG_TOOL_CONTENT` | Tool call output content                |

## Observe

Once tracing is enabled, OpenCode activity is streamed to Arize AX. Each turn (one user prompt to the assistant's response) is captured as a trace.

### Spans Captured

Each turn produces a three-level span tree:

| Span           | Span Kind | Description                                                                                                                                                                |
| :------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Turn`         | CHAIN     | Root span for the turn. Input is the user prompt; output is the assistant's final text.                                                                                    |
| `LLM: {model}` | LLM       | Model call with `llm.model_name`, `llm.provider`, prompt/completion/reasoning token counts, cache read/write tokens, and `llm.cost`. One per assistant message.            |
| `{tool}`       | TOOL      | One per completed tool call, with `tool.name`, redacted input/output, and tool-specific attributes such as `tool.command`, `tool.file_path`, `tool.query`, and `tool.url`. |

Timestamps come from OpenCode's own millisecond clocks rather than wall-clock time on the tracing process. The default project name is `opencode` unless you set `ARIZE_PROJECT_NAME`.

## How Tracing Works

OpenCode is architecturally different from the other coding agents in this repo. Extensions load as [plugins](https://opencode.ai/docs/plugins/) inside OpenCode's Bun runtime — there is no per-event subprocess. The integration has two pieces:

1. A **TypeScript plugin shim** at `~/.config/opencode/plugin/arize-tracing.ts` that listens for `message.updated` and `session.idle` events, pulls the authoritative session snapshot via the OpenCode SDK, and pipes it to the reconciler.
2. A **Python reconciler** (`arize-hook-opencode`) that walks the snapshot and emits any new `Turn`, `LLM`, and `TOOL` spans, deduplicated by message ID and tool call ID. Spans are sent directly to Arize AX — no separate buffer or collector service is required.

## Limitations

Sub-agent and `task` sessions trace independently. OpenCode's built-in `task` tool spawns sub-agents that each get their own `sessionID`. In v1, each sub-agent session produces its own independent trace; they are not linked back to the parent session's trace.

## Reference

For the full list of environment variables, default file paths, and troubleshooting steps, see the [OpenCode tracing README](https://github.com/Arize-ai/coding-harness-tracing/blob/main/tracing/opencode/README.md).

## Uninstall

```bash theme={null}
curl -sSL https://raw.githubusercontent.com/Arize-ai/coding-harness-tracing/main/install.sh | bash -s -- uninstall opencode
```

## Resources

<CardGroup>
  <Card icon="github" href="https://github.com/Arize-ai/coding-harness-tracing" title="Arize Coding Harness Tracing" horizontal />

  <Card icon="github" href="https://github.com/Arize-ai/openinference" title="OpenInference" horizontal />

  <Card icon="book-open" href="https://opencode.ai/" title="OpenCode" horizontal />
</CardGroup>
