## OpenCode Integration

OpenCode is an AI-powered terminal coding agent. Entire integrates with OpenCode via its plugin system, automatically capturing sessions and checkpoints. The OpenCode integration is in preview and may contain bugs.

## Prerequisites

- [Entire CLI installed](https://docs.entire.io/installation)
- [OpenCode](https://github.com/anomalyco/opencode) installed
- A Git repository with Entire enabled

## Enable

```
entire agent add opencode
opencode
```

`entire agent add opencode` installs a TypeScript plugin that hooks into OpenCode’s event system.

### How it works

The plugin communicates with Entire via hooks:

1. **Session Detection** — the plugin fires on `session.created` events.
2. **Turn Tracking** — each user prompt triggers `turn-start`; when the agent goes idle, `turn-end` fires.
3. **Transcript Export** — on `turn-end`, Entire calls `opencode export` to capture the full transcript.
4. **Checkpoint Creation** — checkpoints are created based on your strategy.
5. **Session Storage** — data saved to the `entire/checkpoints/v1` branch.

### What gets captured

| Data            | Description                                            |
|-----------------|-------------------------------------------------------|
| Conversation     | Full transcript of prompts and responses               |
| File changes     | Files modified via edit, write, and patch tools      |
| Tool calls       | Tool invocations with inputs and outputs              |
| Token usage      | Input, output, reasoning, and cache tokens            |
| Timestamps       | Session, message, and checkpoint timing               |

### Features

**Rewind during sessions.** Use `entire checkpoint rewind` to restore to a previous checkpoint during or after an OpenCode session. When you rewind, Entire reimports the checkpoint-state transcript into OpenCode’s database so you can continue seamlessly. See the [`checkpoint rewind` command reference](https://docs.entire.io/cli-reference/checkpoint#checkpoint-rewind) for full flag documentation.

**Resume previous sessions.** Switch to a session’s branch with `entire session resume BRANCH`. The CLI restores the session log if needed and prints `opencode -s SESSION_ID`. See the [`session resume` command reference](https://docs.entire.io/cli-reference/sessions#session-resume) for full flag documentation.

**Explain commits.** Inspect any commit or checkpoint with `entire checkpoint explain`. See the [`checkpoint explain` command reference](https://docs.entire.io/cli-reference/checkpoint#checkpoint-explain) for full flag documentation.

**Mid-turn commits.** When OpenCode commits during a turn (before the turn ends), Entire captures a checkpoint for that commit. The transcript is fetched on-demand via `opencode export` so the checkpoint includes the latest agent activity.

### Caveats and limitations

- The integration is in preview and may have rough edges.
- Plugin requires Bun runtime (used by OpenCode’s plugin system).
- Session detection relies on OpenCode’s event system.
- Works best with the manual-commit strategy.

### Best practices

**Use the manual-commit strategy.** For terminal AI tools like OpenCode:

```
entire agent add opencode
```

**Commit when you’ve made meaningful progress:**

```
git add .
git commit -m "Implement feature with OpenCode"
```

### Example workflow

```
# 1. Enable Entire with OpenCode
cd my-project
entire agent add opencode

# 2. Start OpenCode
opencode

# 3. Work with OpenCode
# Ask it to write code, make changes, etc.

# 4. Rewind if needed
entire checkpoint rewind

# 5. Commit when ready
git add .
git commit -m "Add feature with OpenCode"

# 6. Push to see on entire.io
git push
```

Your session is now visible on [entire.io](/content/site-root.html) with full context for code review.

## Troubleshooting

### Session not detected

1. Ensure you’re in an Entire-enabled repo: `entire status`
2. Verify OpenCode is running from within the repository
3. Check that the plugin is installed: look for the Entire plugin in your OpenCode config
4. Check Git hooks are installed: `ls .git/hooks`

### No checkpoints created

1. Checkpoints require file changes — ensure OpenCode is modifying files
2. Check your strategy settings in `.entire/settings.json`
3. Verify `opencode export` works: `opencode export <session-id>`

### Transcript not captured

1. The plugin calls `opencode export` to fetch transcripts — ensure this command works
2. Check that the `.opencode` directory exists in your repository
3. Look for errors in the Entire hook output: run `entire hooks opencode turn-end` manually.
