---
title: OpenCode
description: How Hindsight installs its plugin into OpenCode and what the plugin reports.
sidebar:
  order: 6
---

OpenCode gets a small plugin. Hindsight copies it into OpenCode's plugins folder, and you don't have to do anything.

## What gets installed

Hindsight looks for OpenCode's config folder: `$XDG_CONFIG_HOME/opencode` if that's set, otherwise `~/.config/opencode`.
OpenCode uses that path on every system, Windows included, so on Windows it's `C:\Users\you\.config\opencode`. If the
folder doesn't exist, OpenCode counts as not installed.

The plugin goes in `plugins/hindsight` inside it:

- opencode/
  - plugins/
    - hindsight/
      - package.json
      - daemon-path
      - src/
        - index.ts
        - emit.ts
        - payload.ts
        - opencode.ts

`daemon-path` holds the full path of the daemon, so the plugin finds it without `PATH`. Hindsight only writes files that
are missing or different, and replaces each in one step. OpenCode runs the TypeScript itself.

Hindsight leaves the folder alone if `plugins/hindsight` is a link you made yourself, or if it holds some other
plugin (it recognises its own by the package name `opencode-hindsight`). The connect line then says `skipped`, with
why.

## What Hindsight sees

The plugin listens to OpenCode's session events and tool hooks and runs `hindsight-daemon emit --source opencode` for
each, one at a time and in order. It never fails a tool call or prints into OpenCode.

- **Your prompts.** A prompt counts from when OpenCode hands it to the agent, not when you send it. A prompt sent
  mid-run waits for its turn. One run can take several prompts. The text goes to the daemon on your computer, which
  keeps only its length and a keyed hash.
- **Runs nobody prompted.** A finished background task or a queued message starts a run, but it isn't a prompt.
- **Tool calls.** The tool, how long it took, and whether it failed (never why). Shell commands, file reads and tool
  output are never sent. File contents are sent only for the three tools that write files (`edit`, `write` and `patch`),
  so lines can be counted and the path hashed.
- **Tokens and model.** Added up over a run from each step, with reasoning tokens counted as output, and attached when
  the run ends. OpenCode keeps no transcript file, so the plugin counts them itself.
- **Which window.** OpenCode starts one plugin per location and every one sees every location's events. The plugin
  keeps only its own location's, so a prompt isn't counted once per window.

## Things to know

- **The daemon it uses.** In order: the `command` option for the plugin, the `HINDSIGHT_DAEMON_BIN` environment
  variable, the path in `daemon-path`, `~/.cargo/bin/hindsight-daemon`, then plain `hindsight-daemon` on `PATH`.
- **Commits.** A commit made from OpenCode's shell is recorded as the agent's (Hindsight checks
  `OPENCODE_SESSION_ID`). See [Commits](/docs/tools#commits).
- **Only global plugins are seen.** Hindsight checks the global config folder for the connection status. A plugin
  added to a single project isn't looked for.

## Check that it's working

Send OpenCode a prompt and look at the timeline on your [Today page](/docs/dashboard/today). If nothing arrives, check that
`plugins/hindsight/package.json` is there, then [reconnect](/docs/tools#reconnect).

## Disconnect

```powershell
hindsight-daemon disconnect
```

This deletes `plugins/hindsight`, but only if its `package.json` is the Hindsight plugin's. A link or another plugin
with that folder name is left alone. It comes back at Hindsight's next start unless you uninstall Hindsight.
