---
title: OpenCode
description: OpenCode terminal agent. Uses the OpenCode session API for resume and discovery.
---
import { Accordions, Accordion } from "fumadocs-ui/components/accordion";
Slot: agent · Name: opencode · Binary: opencode
[OpenCode](https://opencode.ai) is an open-source terminal coding agent. It has a structured session API, which means AO can discover, resume, and track its sessions reliably.
## Install
```bash
npm install -g opencode-ai
```
## Use
```yaml title="agent-orchestrator.yaml"
agent: opencode
```
No plugin-level config.
## How it works
- **Launch:** `opencode` starts in the worktree with `AO:` as the session title — this is how AO finds it back later.
- **Session discovery:** `opencode session list --format json` returns the list; AO matches on the title prefix.
- **Resume:** `opencode --session ` rehydrates the state.
- **Activity tracking:** Primary signal is the OpenCode session's `updatedAt`. AO falls back to its own activity JSONL if the session API doesn't answer.
- **PR + git tracking:** PATH wrappers for `gh` / `git`.
## Environment variables
| Variable | Set by AO | Purpose |
|---|---|---|
| `AO_SESSION_ID` | ✓ | AO session id |
| `AO_ISSUE_ID` | ✓ | Issue identifier |
| `PATH` | ✓ | Prepends `~/.ao/bin` |
| `GH_PATH` | ✓ | Absolute path to real `gh` |
## Troubleshooting
`ao session remap ` re-discovers and persists the OpenCode session mapping. Use `--force` to override a stale mapping.
If the OpenCode session API doesn't respond, AO falls back to the activity JSONL, which uses age-based decay. If even that returns `idle` forever, check that `opencode session list` works on its own.