# OpenCode

> Import OpenCode CLI, desktop, and web sessions from OpenCode's local history, without copying credentials or share secrets.

The OpenCode CLI, desktop app, and local web app all save to the same local
history. Hansard imports all of it with one source, `opencode`.

## Source IDs

| Source     | Use it for                                                                       |
| ---------- | -------------------------------------------------------------------------------- |
| `opencode` | All sessions in OpenCode's data folder, or in a folder you set with an override. |

The older names `opencode-cli`, `opencode-desktop`, and `opencode-web` still
work and mean the same as `opencode`. They cannot limit an import to one app,
because all three apps share one history.

## How the import works

Hansard finds OpenCode's history in its data folder, normally
`$XDG_DATA_HOME/opencode` (`~/.local/share/opencode`), or in the folder or
database you set with `HANSARD_OPENCODE_DATA_DIR` or `HANSARD_OPENCODE_DB`. It
does not look for extra history in the desktop app's settings. OpenCode has
saved history as JSON files and, in later versions, as a SQLite database.
Hansard recognizes the four JSON layouts and five SQLite layouts OpenCode has
used, and checks each one before importing it.

Current databases can hold both transcript formats. Hansard chooses the
populated format for each session, so an empty newer table cannot hide an
older transcript. If both formats contain records for the same session,
the import reports a conflict instead of discarding either history.

For JSON history, Hansard imports each session's messages, parts, todos, and
file diff lists together, and summarizes the todo and diff lists. Share links
and their secrets are never copied into the archive; Hansard removes share
secrets from older JSON sessions before it saves anything. For SQLite history,
Hansard first takes a consistent copy of the database, including changes still
in its write-ahead log. It then makes a history-only copy without credential,
account, and share-secret tables, and that copy is what Hansard reads and
archives.

Model-switch notices preserve the selected model, provider, and variant as
settings history. A selection alone never adds a model or effort level to
historical response attribution.

Text, reasoning, tool calls and results, attachments, model routes, usage,
workspace details, current todos, and linked child agent sessions all come from
the history Hansard read. Rebuilding a conversation later uses the archived
copy and never reopens your live OpenCode database.
Snapshot replay retains the same native conversation and parent identities
as live import.

## Import and keep current

**Import now**

```sh
hansard import --source opencode --since all
hansard index rebuild
```

**Keep current**

With **Automatic** source selection, the watcher already includes
`opencode`. With a **Custom** list, enable it. The watcher picks it up within 30 seconds:

```sh
hansard config sources enable opencode
```

## Review the import in the app

1. When the import finishes, open **Conversations** and select **Filter & sort**.
2. Set **Source** to **OpenCode** and set **Time** to the window you imported. Use **Folder** to narrow the list when you use this harness in several projects.
3. Select a conversation to check its messages, tool calls, files, commits, model, and token usage.

To keep archiving new sessions from a local harness, open **Settings → Imports**. **Automatic** follows every supported harness installed on this computer. **Custom** lets you turn individual harnesses on or off. Cloud sources and account exports never run from here; each needs its own import command. If a conversation you expect is missing after you reset the filters, run the import command on this page again with `--explain-skips` where the source supports it.

## What Hansard preserves

- Sessions, messages, parts, tool calls and results, model routes, usage,
  workspace details, summaries of current todos and file diffs, and linked
  agent sessions.
- The JSON files or history-only SQLite copy used for the import, without
  credentials or share secrets.
- The exact route for each model, including OpenCode Zen, OpenRouter, and
  custom routes.

## Known limitations

- After rebuilding a SQLite snapshot from raw, ordinary live imports cannot
  overwrite that snapshot. Returning to live imports currently requires a full
  archive refresh. Preview `hansard update --dry-run` before choosing its scope.
- Pricing for a specific route applies only when OpenCode recorded the exact
  route. OpenRouter and custom routes do not use OpenCode Zen prices.
- A history with an unknown or damaged record is not imported, rather than
  imported partly or read as a different format.
- The older `opencode-cli`, `opencode-desktop`, and `opencode-web` names cannot
  select one app's history, because all three apps share it.

> **MiMo Code is a separate source:** MiMo Code has its own database, data folder, and `mimo-code` source. See
> [MiMo Code](https://www.hansard.dev/imports/mimo-code/).

## Refresh an existing archive

```sh
hansard import --source opencode --since all
hansard index rebuild
```

After an update, the watcher refreshes most archived conversations on its own,
but it leaves sessions kept as a SQLite snapshot as they are. The import above
reads them again from OpenCode's history. If that history is gone, rebuild the
snapshots from Hansard's preserved copy:

```sh
hansard rebuild --from-raw --provider opencode --since all
```
